Skip to content

PrestaShopCorp/ps_accounts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrestaShop Account module

Source Code Latest Version Software License Build Status

Context

The module ps_accounts is the interface between your module and PrestaShop's services. It manages:

  • Shop association/dissociation process;
  • Providing tokens to communicate safely with PrestaShop services;
  • Synchronize basic informations about the shops (ex: shop URLs, name, ...).

This module is a basis for other modules using PrestaShop services.

Installation

If you need to install and test the module, you can download the desired zip here.

Compatibility Matrix

We aims to follow partially the Prestashop compatibility charts

ps_accounts version Prestashop Version PHP Version
^7.0.9 >=1.6 && <= 9.x PHP 5.6 - 8
7.x >=1.6 && <9.x PHP 5.6 - 8
6.x (deprecated) >=8.0.0 PHP 7.2 - 8
5.x (deprecated) >=1.6 && <8.0.0 PHP 5.6 - 7.4

Integration along with your Prestashop module

If you are integrating a module, you should have a look on the PrestaShop Integration Framework Documentation.

A preliminary note about PrestaShop modules ecosystem :

You should keep in mind that the PrestaShop Core

  • doesn't manage dependencies between modules;
  • doesn't manage composer dependencies globally.

As a consequence you MUST

  • check by yourself that the PsAccounts module is installed;
  • ensure your vendor dependencies won't collide with existing ones.
    (loaded by other modules OR coming from the PrestaShop Core)

Display the PrestaShop Account Component in your module :

Load PsAccountsPresenter

The presenter will give basic informations to the components through contextPsAccounts object accessible on the page.

// My_module.php

// /!\ TODO: Starting here you are responsible to check that the module is installed

/** @var Ps_accounts $module */
$module = \Module::getModuleIdByName('ps_accounts');

/** @var \PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter $presenter */
$presenter = $module->getService(\PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter::class);

Media::addJsDef([
    'contextPsAccounts' => $presenter->present((string) $this->name),
]);

return $this->display(__FILE__, 'views/templates/admin/app.tpl');

Alternatively you can still use : PrestaShop Accounts Installer for more details on how to setup Installer.

Load and init the component on your page

For detailed usage you can follow the component's documentation : prestashop_accounts_vue_components

How to get up to date (legacy) JWT Tokens

About tokens provided :

All the JWT tokens exposed follow the OpenId Connect Token and Access Tokens Specs.

This module provides the following tokens:

  • ShopToken (legacy Firebase tokens)
    This token can be used to act as the shop. It should be used only for machine to machine communication without user interaction
  • OwnerToken (legacy Firebase tokens)
    This token is created for the shop owner who associate the shop.
  • ShopAccessToken (provided by Prestashop OpenId Connect Provider)
    For machine to machine calls. (also used to keep up to date legacy Shop and Owner tokens

Using PsAccountsService (recommended) :

// /!\ TODO: Starting here you are responsible to check that the module is installed

/** @var Ps_accounts $module */
$module = \Module::getModuleIdByName('ps_accounts');

/** @var \PrestaShop\Module\PsAccounts\Service\PsAccountsService $service */
$service = $module->getService(\PrestaShop\Module\PsAccounts\Service\PsAccountsService::class);

// With this one you can call your API's as the PrestaShop Account Shop
$jwtShop = $service->getOrRefreshToken();

// With this one you can call your API's as the PrestaShop Account Shop Owner
$jwtOwner = $service->getUserToken();

Calling AJAX controller in backend context :

That way you will retrieve an up to date Shop Token

const response = await fetch("https://<shop-admin-url>/index.php", {
  ajax: true,
  controller: 'AdminAjaxPsAccounts',
  action: 'getOrRefreshAccessToken',
  token: '<admin_token>',
});

With the given response :

{ 
  "token": "<access_token>"
}

Provided hooks

Here are listed custom hooks provided with this module:

hook params description
actionShopAccountLinkAfter shopId, shopUuid Triggered after link shop acknowledged
actionShopAccountUnlinkAfter shopId, shopUuid Triggered after unlink shop acknowledged
actionShopAccessTokenRefreshAfter token Triggered after OAuth access token refreshed

Building the module locally

In case you need to build a zip by yourself :

  cp config.dist.php config.php
  make

OR with multiple environments :

  cp config.dist.php config.myenv.php
  BUNDLE_ENV=myenv make