<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
websystems / ws-prestashop-update-package example snippets
class Ws_mymodule extends Module
{
use \Websystems\PrestashopUpdatePackage\Traits\WsLicenseTrait;
public function __construct()
{
// ...
parent::__construct();
// ...
// Inicjalizacja klienta aktualizacji
$this->wsInitUpdateManager($this, 'WS_MYMODULE');
}
public function install(): bool
{
return parent::install()
&& $this->registerHook('displayAdminAfterHeader');
// ... pozostałe hooki
}
/**
* Renderuje baner z informacją o dostępnej aktualizacji.
* Sprawdzanie serwera odbywa się max raz na 24 h (cache w Configuration).
* Sam baner pokazuje się zawsze gdy wykryto nowszą wersję — bez limitu czasowego.
*/
public function hookDisplayAdminAfterHeader(): string
{
$tabUrl = $this->context->link->getAdminLink('AdminWsMyModule') . '&ws_tab=license';
return $this->wsRenderUpdateNotification($tabUrl);
}
}
class Ws_mymodule extends Module
{
use \Websystems\PrestashopUpdatePackage\Traits\WsLicenseTrait;
public function __construct()
{
parent::__construct();
$this->wsInitUpdateManager($this, 'WS_MYMODULE');
}
public function install(): bool
{
return parent::install()
&& $this->registerHook('displayBackOfficeHeader')
&& $this->registerHook('displayAdminAfterHeader');
// ... pozostałe hooki
}
/**
* Sprawdza aktualizacje w tle — max raz na 24 h.
* Nie renderuje HTML. Odpowiednik ręcznego wzorca z Configuration::get/updateValue.
*/
public function hookDisplayBackOfficeHeader(): void
{
$this->wsCheckForUpdates();
}
/**
* Renderuje baner gdy dostępna jest nowsza wersja.
* Dane są już w cache z hookDisplayBackOfficeHeader.
*/
public function hookDisplayAdminAfterHeader(): string
{
$tabUrl = $this->context->link->getAdminLink('AdminWsMyModule') . '&ws_tab=license';
return $this->wsRenderUpdateNotification($tabUrl);
}
}
use Websystems\PrestashopUpdatePackage\Traits\WsLicenseTrait;
class AdminWsMyModuleController extends ModuleAdminController
{
use WsLicenseTrait;
public function __construct()
{
parent::__construct();
// Inicjalizacja — przekaż instancję modułu i prefiks klucza konfiguracyjnego
$this->wsInitUpdateManager($this->module, 'WS_MYMODULE');
}
public function postProcess()
{
// Obsługuje submitWsLicenseActivate, submitWsLicenseDeactivate,
// submitWsCheckUpdate, submitWsInstallUpdate
$this->wsHandleLicenseActions();
parent::postProcess();
}
public function renderView()
{
if (Tools::getValue('ws_tab') === 'license') {
$adminUrl = $this->context->link->getAdminLink('AdminWsMyModule') . '&ws_tab=license';
return $this->wsRenderLicenseTab($adminUrl);
}
return parent::renderView();
}
}