PHP code example of websystems / ws-prestashop-update-package

1. Go to this page and download the library: Download websystems/ws-prestashop-update-package library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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();
    }
}

use Websystems\PrestashopUpdatePackage\Translations;

$msg = Translations::trans('License activated successfully.', 'pl');
// → "Licencja aktywowana pomyślnie."

src/
  Update/
    UpdatePulseClient.php     ← klient HTTP do serwera UpdatePulse
  License/
    LicenseTabRenderer.php    ← generator HTML zakładki "Licencja i aktualizacje"
  Traits/
    WsLicenseTrait.php        ← trait do wklejenia w AdminController (zakładka licencji)
  Translations.php            ← tłumaczenia PL/EN (tablice statyczne)