Skip to content

Commit

Permalink
Integrate ps_accounts component on dashboard zone one
Browse files Browse the repository at this point in the history
  • Loading branch information
sowbiba committed Jan 5, 2024
1 parent 2ab7576 commit 6922356
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/Traits/Hooks/UseDashboardZoneOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Db;
use Exception;
use PrestaShop\Module\Mbo\Helpers\ErrorHelper;
use PrestaShop\Module\Mbo\Traits\HaveCdcComponent;

trait UseDashboardZoneOne
Expand All @@ -38,7 +39,9 @@ trait UseDashboardZoneOne
*/
public function hookDashboardZoneOne(array $params)
{
return $this->smartyDisplayTpl('dashboard-zone-one.tpl');
return $this->smartyDisplayTpl('dashboard-zone-one.tpl', [
'urlAccountsCdn' => $this->loadPsAccounts(),
]);
}

/**
Expand Down Expand Up @@ -82,4 +85,36 @@ public function useDashboardZoneOneExtraOperations()

$this->updatePosition((int) $id_hook, false);
}

protected function loadPsAccounts(): string
{
/*********************
* PrestaShop Account *
* *******************/
$urlAccountsCdn = '';
$accountsFacade = $accountsService = null;

try {
$accountsFacade = $this->get('mbo.ps_accounts.facade');
$accountsService = $accountsFacade->getPsAccountsService();
} catch (\PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException $e) {
ErrorHelper::reportError($e);
}

if (null !== $accountsFacade && null !== $accountsService) {
try {
\Media::addJsDef([
'contextPsAccounts' => $accountsFacade->getPsAccountsPresenter()
->present('ps_mbo'),
]);

// Retrieve the PrestaShop Account CDN
$urlAccountsCdn = $accountsService->getAccountsCdn();
} catch (\Exception $e) {
ErrorHelper::reportError($e);
}
}

return $urlAccountsCdn;
}
}
10 changes: 10 additions & 0 deletions views/templates/hook/dashboard-zone-one.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*}

{if isset($urlAccountsCdn)}
<script src="{$urlAccountsCdn}" rel=preload></script>
<script>
if (window?.psaccountsVue) {
window?.psaccountsVue?.init();
{assign shop_context $shop_context|@json_decode:true|array_merge:['accounts_component_loaded' => true]|@json_encode}
}
</script>
{/if}
<script>
if (typeof window.mboCdc == undefined || typeof window.mboCdc == "undefined") {
if (typeof renderCdcError === 'function') {
Expand Down

0 comments on commit 6922356

Please sign in to comment.