From 934aaa50a01c8d0b852ae6a22d803ec70b31f6dd Mon Sep 17 00:00:00 2001 From: Jonathan Renard <1273438+fox-john@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:35:59 +0100 Subject: [PATCH] fix: account integration (#405) --- config.xml | 2 +- src/Service/PsAccountsAdapterService.php | 40 ++++++++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/config.xml b/config.xml index 9d65e736..830d98b2 100644 --- a/config.xml +++ b/config.xml @@ -9,4 +9,4 @@ 0 0 - \ No newline at end of file + diff --git a/src/Service/PsAccountsAdapterService.php b/src/Service/PsAccountsAdapterService.php index d877993d..327506e6 100644 --- a/src/Service/PsAccountsAdapterService.php +++ b/src/Service/PsAccountsAdapterService.php @@ -54,8 +54,6 @@ public function __construct(ModuleHelper $moduleHelper) * Get psAccounts module main class, or null if module is'nt ready * * @return false|\ModuleCore - * - * @throws \PrestaShopException */ public function getModule() { @@ -70,8 +68,6 @@ public function getModule() * Get psAccounts service, or null if module is'nt ready * * @return mixed - * - * @throws \PrestaShopException */ public function getService() { @@ -79,54 +75,64 @@ public function getService() return false; } - return $this->psAccountModule->getService('PrestaShop\Module\PsAccounts\Service\PsAccountsService'); + try { + return $this->psAccountModule->getService('PrestaShop\Module\PsAccounts\Service\PsAccountsService'); + } catch (\Exception $e) { + return false; + } } /** * Get presenter from psAccounts, or null if module is'nt ready * * @return mixed - * - * @throws \PrestaShopException */ public function getPresenter() { - if (!$this->moduleHelper->isInstalledAndActive('ps_accounts')) { + if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) { return false; } - return $this->psAccountModule->getService('PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter'); + try { + return $this->psAccountModule->getService('PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter'); + } catch (\Exception $e) { + return false; + } } /** * Get shopUuid from psAccounts, or null if module is'nt ready * * @return string - * - * @throws \PrestaShopException */ public function getShopUuid() { - if (!$this->moduleHelper->isInstalledAndActive('ps_accounts')) { + if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) { return ''; } - return $this->getService()->getShopUuid(); + try { + return $this->getService()->getShopUuid(); + } catch (\Exception $e) { + return ''; + } } /** * Get refreshToken from psAccounts, or null if module is'nt ready * * @return string - * - * @throws \PrestaShopException */ public function getOrRefreshToken() { - if (!$this->moduleHelper->isInstalledAndActive('ps_accounts')) { + if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) { return ''; } - return $this->getService()->getOrRefreshToken(); + try { + return $this->getService()->getOrRefreshToken(); + } catch (\Exception $e) { + return ''; + } } }