Skip to content

Commit

Permalink
Merge pull request #589 from alma/hotfix/ecom-2162-zepelucheclubcom-5…
Browse files Browse the repository at this point in the history
…00-internal-sever-error

fix: Impossible configure Alma if PS Account version is lower  5.0
  • Loading branch information
Benjamin-Freoua-Alma authored Oct 30, 2024
2 parents 5a9c640 + 6c6cfce commit e6c3b39
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 39 deletions.
57 changes: 40 additions & 17 deletions alma/alma.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
class Alma extends PaymentModule
{
const VERSION = '4.4.0';
const PS_ACCOUNTS_VERSION_REQUIRED = '5.3.0';

public $_path;
public $local_path;
Expand Down Expand Up @@ -128,24 +129,45 @@ public function __construct()
/**
* @return void
*
* @throws \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException
* @throws \Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException
*/
public function checkCompatibilityPSModule()
public function checkPsAccountsPresence()
{
if (_PS_MODE_DEV_ === true) {
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException('[Alma] Debug mode is activated');
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException('[Alma] Debug mode is activated');
}

if (
!class_exists(\Symfony\Component\Config\ConfigCache::class)
|| !class_exists(\PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer::class)
) {
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException('[Alma] Classes don\'t exist for PS Account');
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException('[Alma] Classes don\'t exist for PS Account');
}
if (
$this->toolsHelper->psVersionCompare('1.6', '<')
) {
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException('[Alma] Prestashop version lower than 1.6');
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException('[Alma] Prestashop version lower than 1.6');
}
}

/**
* Check if PS Account is installed and up to date, minimal version required 5.0.
*
* @return void
*
* @throws \PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException
* @throws \Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException
*/
public function checkPsAccountsCompatibility()
{
$this->checkPsAccountsPresence();
$psAccountsModule = \Module::getInstanceByName('ps_accounts');
if (!$psAccountsModule) {
throw new \PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException('[Alma] PS Account is not installed');
}

if ($psAccountsModule->version < self::PS_ACCOUNTS_VERSION_REQUIRED) {
throw new \PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException('[Alma] PS Account is not up to date, minimal version required ' . self::PS_ACCOUNTS_VERSION_REQUIRED);
}
}

Expand Down Expand Up @@ -222,10 +244,10 @@ private function checkCoreInstall($coreInstall)
public function install()
{
try {
$this->checkCompatibilityPSModule();
$this->checkPsAccountsPresence();
$this->setContainer();
$this->getService('alma.ps_accounts_installer')->install();
} catch (\Alma\PrestaShop\Exceptions\CompatibilityPsAccountException $e) {
} catch (\Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException $e) {
\Alma\PrestaShop\Logger::instance()->info($e->getMessage());
}

Expand Down Expand Up @@ -586,28 +608,29 @@ public function viewAccess()
*/
public function getContent()
{
$suggestPSAccount = false;
$suggestPSAccounts = false;

try {
$hasPSAccount = $this->renderPSAccount();
} catch (\Alma\PrestaShop\Exceptions\CompatibilityPsAccountException $e) {
$hasPSAccount = false;
$hasPSAccounts = $this->renderPSAccounts();
} catch (\Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException $e) {
$hasPSAccounts = false;
} catch (\PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException $e) {
$hasPSAccount = false;
$suggestPSAccount = true;
$hasPSAccounts = false;
$suggestPSAccounts = true;
}

return $this->runHookController('getContent', ['hasPSAccount' => $hasPSAccount, 'suggestPSAccount' => $suggestPSAccount]);
return $this->runHookController('getContent', ['hasPSAccounts' => $hasPSAccounts, 'suggestPSAccounts' => $suggestPSAccounts]);
}

/**
* @return bool
*
* @throws \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException
* @throws \Alma\PrestaShop\Exceptions\CompatibilityPsAccountsException
* @throws \PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException
*/
public function renderPSAccount()
public function renderPSAccounts()
{
$this->checkCompatibilityPSModule();
$this->checkPsAccountsCompatibility();
$this->setContainer();

try {
Expand Down
12 changes: 6 additions & 6 deletions alma/controllers/hook/GetContentHookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function processConfiguration()
if ((empty($liveKey) && ALMA_MODE_LIVE == $apiMode) || (empty($testKey) && ALMA_MODE_TEST == $apiMode)) {
$this->context->smarty->assign('validation_error', "missing_key_for_{$apiMode}_mode");
$this->context->smarty->assign([
'suggestPSAccount' => false,
'suggestPSAccounts' => false,
]);

$this->hasKey = false;
Expand Down Expand Up @@ -540,8 +540,8 @@ public function renderForm()

$this->assignSmartyAlertClasses();
$this->context->smarty->assign('tip', 'fill_api_keys');
$this->context->smarty->assign('suggestPSAccount', false);
$this->context->smarty->assign('hasPSAccount', false);
$this->context->smarty->assign('suggestPSAccounts', false);
$this->context->smarty->assign('hasPSAccounts', false);

$extraMessage = $this->module->display($this->module->file, 'getContent.tpl');
}
Expand Down Expand Up @@ -829,9 +829,9 @@ public function needsAPIKey()
public function run($params)
{
$this->context->smarty->assign([
'hasPSAccount' => $params['hasPSAccount'],
'hasPSAccounts' => $params['hasPSAccounts'],
'updated' => true,
'suggestPSAccount' => $params['suggestPSAccount'],
'suggestPSAccounts' => $params['suggestPSAccounts'],
]);

$this->assignSmartyAlertClasses();
Expand Down Expand Up @@ -863,7 +863,7 @@ public function run($params)
$messages = '';
}

if ($params['hasPSAccount'] || $params['suggestPSAccount']) {
if ($params['hasPSAccounts'] || $params['suggestPSAccounts']) {
$messages = $this->module->display($this->module->file, 'getContent.tpl');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
exit;
}

class CompatibilityPsAccountException extends AlmaException
class CompatibilityPsAccountsException extends AlmaException
{
}
2 changes: 1 addition & 1 deletion alma/translations/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
$_MODULE['<{alma}prestashop>notificationconfiguration_cf5ec9fb9f7214a3db82a5a39fec5b48'] = 'Enter your API key';
$_MODULE['<{alma}prestashop>notificationconfiguration_055f421849c2a1c32b885c95540f827c'] = 'Find your API live key on your %1$s Alma dashboard%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_53b458e8453e3694811e61c96527d638'] = 'Um den Testmodus zu verwenden, rufen Sie Ihren Test-API-Schlüssel von Ihrem %1$ssandbox dashboard%2$s ab.';
$_MODULE['<{alma}prestashop>notificationconfiguration_41d0063d3bb7d3067f46734fac8b27c4'] = 'Wir bieten das PrestaShop Account Modul zum Download an';
$_MODULE['<{alma}prestashop>notificationconfiguration_42deb316427c319fae8ef1e9a2ebfacb'] = 'Wir bieten das PrestaShop Account Modul zum Download an';
$_MODULE['<{alma}prestashop>notificationconfiguration_6997dde298b14fbf6a7c95bd39fe8dc4'] = 'Das Modul %1$sfinden Sie hier%2$s';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_a6b0ef107f0d278df612764187bbdece'] = ' Steigern Sie Ihre Leistung und erhalten Sie Einblicke!';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_5b64cb0849dd12ea528c04f2fe66ae4d'] = 'Indem Sie diese Option akzeptieren, ermöglichen Sie es Alma, die Nutzung Ihrer Zahlungsmittel zu analysieren, [1]mehr Informationen zu erhalten, um[/1] durchzuführen und diese Daten mit Ihnen zu teilen. Sie können [2]jederzeit abbestellen und Ihre Daten[/2] löschen.';
Expand Down
3 changes: 2 additions & 1 deletion alma/translations/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@
$_MODULE['<{alma}prestashop>notificationconfiguration_cf5ec9fb9f7214a3db82a5a39fec5b48'] = 'Enter your API key';
$_MODULE['<{alma}prestashop>notificationconfiguration_055f421849c2a1c32b885c95540f827c'] = 'Find your API live key on your %1$s Alma dashboard%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_53b458e8453e3694811e61c96527d638'] = 'To use Test mode, retrieve your Test API key from your %1$ssandbox dashboard%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_41d0063d3bb7d3067f46734fac8b27c4'] = 'We offer to download the PrestaShop Account module';
$_MODULE['<{alma}prestashop>notificationconfiguration_b040aba3ff898146cd8c1fb8cfd04daf'] = 'We offer to download or update the PrestaShop Account module (minimum required version %1$s)';
$_MODULE['<{alma}prestashop>notificationconfiguration_9700e091d54b8ff1fafcd27518c75b23'] = 'Link your store to your PrestaShop account to take full advantage of the modules offered by the PrestaShop Marketplace and optimize your experience.';
$_MODULE['<{alma}prestashop>notificationconfiguration_6997dde298b14fbf6a7c95bd39fe8dc4'] = 'You can find the module %1$shere%2$s';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_a6b0ef107f0d278df612764187bbdece'] = ' Increase your performance & get insights !';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_5b64cb0849dd12ea528c04f2fe66ae4d'] = 'By accepting this option, you enable Alma to analyse the usage of your payment methods, [1]get more information to perform[/1] and share this data with you. You can [2]unsubscribe and erase your data[/2] at any moment.';
Expand Down
2 changes: 1 addition & 1 deletion alma/translations/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
$_MODULE['<{alma}prestashop>notificationconfiguration_cf5ec9fb9f7214a3db82a5a39fec5b48'] = 'Introduce tu clave API';
$_MODULE['<{alma}prestashop>notificationconfiguration_055f421849c2a1c32b885c95540f827c'] = 'Encuentra tu API live key en tu %1$s Alma dashboard%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_53b458e8453e3694811e61c96527d638'] = 'Para utilizar el modo de prueba, obtenga su clave de API de prueba en el panel de control de su sandbox %1$s%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_41d0063d3bb7d3067f46734fac8b27c4'] = 'Te proponemos descargar el módulo Cuenta PrestaShop';
$_MODULE['<{alma}prestashop>notificationconfiguration_42deb316427c319fae8ef1e9a2ebfacb'] = 'Te proponemos descargar el módulo Cuenta PrestaShop';
$_MODULE['<{alma}prestashop>notificationconfiguration_6997dde298b14fbf6a7c95bd39fe8dc4'] = 'Encontrará el módulo %1$saquí%2$s';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_a6b0ef107f0d278df612764187bbdece'] = ' Aumenta tu rendimiento y obtén información';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_5b64cb0849dd12ea528c04f2fe66ae4d'] = 'Al aceptar esta opción, permites a Alma analizar el uso de tus métodos de pago, [1]obtener más información para realizar[/1] y compartir estos datos contigo. Puedes [2]darte de baja y borrar tus datos[/2] en cualquier momento.';
Expand Down
6 changes: 4 additions & 2 deletions alma/translations/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
$_MODULE['<{alma}prestashop>admininsurancehelper_7442e29d7d53e549b78d93c46b8cdcfc'] = 'Commandes';
$_MODULE['<{alma}prestashop>insuranceservice_d87aee5118a62a7ff6c21e4ac31006c5'] = 'Par la présente, je reconnais accepter de souscrire à l\'assurance proposée par Alma. Ce faisant, je confirme avoir préalablement pris connaissance de la [notice d\'information valant conditions générales], du [document d\'information sur le produit d\'assurance], et de la [fiche d\'information et de conseil précontractuelle]. J\'y adhère sans réserve et accepte de signer électroniquement les différents documents formant mon contrat, le cas échéant. Je consens expressément à la collecte et à l\'utilisation de mes données personnelles aux fins de la souscription et de la gestion de mon (mes) contrat(s) d\'assurance.';
$_MODULE['<{alma}prestashop>adminalmainsuranceconfiguration_b824200e9b8aca1fbb762d6566ff0cd7'] = 'Votre configuration a été sauvegardée';
$_MODULE['<{alma}prestashop>adminalmainsuranceconfiguration_4a39c6a33c3441762924914168d2a387'] = 'Erreur lors de la création de la configuration Assurance Alma : %1$s';
$_MODULE['<{alma}prestashop>adminalmainsuranceconfiguration_a6bf06f186e2fccecad054fd831c2144'] = '[Alma] Erreur sur le produit d\'assurance pendant le changement de configuration : %1$s';
$_MODULE['<{alma}prestashop>adminalmainsuranceconfiguration_b42688965893bdb7a37cf1197e506e25'] = '[Alma] Erreur de création de configuration sur l\'assurance Alma : %1$s';
$_MODULE['<{alma}prestashop>adminalmainsuranceorders_a66f446516cd125af12bd25073f88b78'] = 'Commandes avec assurance';
$_MODULE['<{alma}prestashop>adminalmainsuranceorders_49414cda71621b3ee718ae5ff40804c5'] = 'Ordonnance Id';
$_MODULE['<{alma}prestashop>adminalmainsuranceorders_63d5049791d9d79d86e9a108b0a999ca'] = 'Référence';
Expand Down Expand Up @@ -260,7 +261,8 @@
$_MODULE['<{alma}prestashop>notificationconfiguration_cf5ec9fb9f7214a3db82a5a39fec5b48'] = 'Entrez votre clé API';
$_MODULE['<{alma}prestashop>notificationconfiguration_055f421849c2a1c32b885c95540f827c'] = 'Trouvez votre clé API sur votre tableau de bord %1$s Alma%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_53b458e8453e3694811e61c96527d638'] = 'Pour utiliser le mode test, récupérez votre clé API de test dans le tableau de bord de votre sandbox %1$s%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_41d0063d3bb7d3067f46734fac8b27c4'] = 'Nous vous proposons de télécharger le module PrestaShop Account';
$_MODULE['<{alma}prestashop>notificationconfiguration_b040aba3ff898146cd8c1fb8cfd04daf'] = 'Nous vous proposons de télécharger ou de mettre à jour le module PrestaShop Account (version minimale requise %1$s)';
$_MODULE['<{alma}prestashop>notificationconfiguration_9700e091d54b8ff1fafcd27518c75b23'] = 'Liez votre boutique à votre compte PrestaShop pour profiter pleinement des modules proposés par PrestaShop Marketplace et optimiser votre expérience.';
$_MODULE['<{alma}prestashop>notificationconfiguration_6997dde298b14fbf6a7c95bd39fe8dc4'] = 'Vous pouvez trouver le module %1$sici%2$s';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_a6b0ef107f0d278df612764187bbdece'] = ' Augmentez vos performances et obtenez des informations !';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_5b64cb0849dd12ea528c04f2fe66ae4d'] = 'En acceptant cette option, vous permettez à Alma d\'analyser l\'utilisation de vos moyens de paiement, [1]d\'obtenir plus d\'informations pour effectuer[/1] et de partager ces données avec vous. Vous pouvez à tout moment vous désinscrire [2]et effacer vos données[/2] .';
Expand Down
2 changes: 1 addition & 1 deletion alma/translations/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
$_MODULE['<{alma}prestashop>notificationconfiguration_cf5ec9fb9f7214a3db82a5a39fec5b48'] = 'Inserire la chiave API';
$_MODULE['<{alma}prestashop>notificationconfiguration_055f421849c2a1c32b885c95540f827c'] = 'Trovate la vostra chiave API live sul vostro cruscotto %1$s Alma%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_53b458e8453e3694811e61c96527d638'] = 'Per utilizzare la modalità Test, recuperare la chiave API Test dalla dashboard di %1$ssandbox%2$s.';
$_MODULE['<{alma}prestashop>notificationconfiguration_41d0063d3bb7d3067f46734fac8b27c4'] = 'Vi proponiamo di scaricare il modulo Account di PrestaShop';
$_MODULE['<{alma}prestashop>notificationconfiguration_42deb316427c319fae8ef1e9a2ebfacb'] = 'Vi proponiamo di scaricare il modulo Account di PrestaShop';
$_MODULE['<{alma}prestashop>notificationconfiguration_6997dde298b14fbf6a7c95bd39fe8dc4'] = 'È possibile trovare il modulo %1$squi%2$s';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_a6b0ef107f0d278df612764187bbdece'] = 'Aumenta le tue prestazioni e ricevi approfondimenti sulle tue vendite!';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_5b64cb0849dd12ea528c04f2fe66ae4d'] = 'Attivando questa opzione, permetti ad Alma di analizzare l\'utilizzo dei tuoi metodi di pagamento [1]al fine[/1] di migliorare il servizio e condividerti un approfondimento sui dati analizzati. Puoi [2]annullare l\'iscrizione e cancellare i tuoi dati[/2] in qualsiasi momento.';
Expand Down
2 changes: 1 addition & 1 deletion alma/translations/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
$_MODULE['<{alma}prestashop>notificationconfiguration_cf5ec9fb9f7214a3db82a5a39fec5b48'] = 'Voer je API-sleutel in';
$_MODULE['<{alma}prestashop>notificationconfiguration_055f421849c2a1c32b885c95540f827c'] = 'Vind je API live key op je %1$s Alma dashboard%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_53b458e8453e3694811e61c96527d638'] = 'Om de Testmodus te gebruiken, haalt je je Test API-sleutel op van jouw %1$ssandbox dashboard%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_41d0063d3bb7d3067f46734fac8b27c4'] = 'Wij bieden aan om de PrestaShop Account module te downloaden';
$_MODULE['<{alma}prestashop>notificationconfiguration_42deb316427c319fae8ef1e9a2ebfacb'] = 'Wij bieden aan om de PrestaShop Account module te downloaden';
$_MODULE['<{alma}prestashop>notificationconfiguration_6997dde298b14fbf6a7c95bd39fe8dc4'] = 'Je kunt de module %1$shier vinden%2$s';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_a6b0ef107f0d278df612764187bbdece'] = ' Verhoog je prestaties & krijg inzichten!';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_5b64cb0849dd12ea528c04f2fe66ae4d'] = 'Door deze optie te aanvaarden, stel je Alma in staat het gebruik van je betaalmethoden te analyseren, [1]meer informatie te verkrijgen om beter te presteren[/1] en deze gegevens met jou te delen. Je kunt [2]je op elk moment uitschrijven en je data wissen[/2].';
Expand Down
2 changes: 1 addition & 1 deletion alma/translations/pt.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
$_MODULE['<{alma}prestashop>notificationconfiguration_cf5ec9fb9f7214a3db82a5a39fec5b48'] = 'Introduza a sua chave API';
$_MODULE['<{alma}prestashop>notificationconfiguration_055f421849c2a1c32b885c95540f827c'] = 'Encontre a sua chave de acesso à API no seu painel de controlo %1$s Alma%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_53b458e8453e3694811e61c96527d638'] = 'Para utilizar o modo de teste, recupere a sua chave de API de teste a partir do seu painel de controlo da caixa de areia %1$s%2$s';
$_MODULE['<{alma}prestashop>notificationconfiguration_41d0063d3bb7d3067f46734fac8b27c4'] = 'Oferecemos a possibilidade de descarregar o módulo Conta PrestaShop';
$_MODULE['<{alma}prestashop>notificationconfiguration_42deb316427c319fae8ef1e9a2ebfacb'] = 'Oferecemos a possibilidade de descarregar o módulo Conta PrestaShop';
$_MODULE['<{alma}prestashop>notificationconfiguration_6997dde298b14fbf6a7c95bd39fe8dc4'] = 'Pode encontrar o módulo %1$saqui%2$s';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_a6b0ef107f0d278df612764187bbdece'] = ' Aumente o seu desempenho e obtenha conhecimentos!';
$_MODULE['<{alma}prestashop>notificationshareofcheckout_5b64cb0849dd12ea528c04f2fe66ae4d'] = 'Ao aceitar esta opção, permite à Alma analisar a utilização dos seus métodos de pagamento, [1]obter mais informações para realizar[/1] e partilhar estes dados consigo. Pode [2]cancelar e apagar os seus dados[/2] a qualquer momento.';
Expand Down
2 changes: 1 addition & 1 deletion alma/views/templates/hook/getContent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
{$validation_error|escape:'htmlall':'UTF-8'}
{/if}
</div>
{elseif isset($tip) && (!isset($hasPSAccount) && !$hasPSAccount) || _PS_MODE_DEV_}
{elseif isset($tip) && (!isset($hasPSAccounts) && !$hasPSAccounts) || _PS_MODE_DEV_}
{include file="./_partials/notificationFirstInstallation.tpl"}
{/if}
{if isset($updated) && $updated}
Expand Down
Loading

0 comments on commit e6c3b39

Please sign in to comment.