From 240f6b1707c44ee1883fb627e9b4a33d7a175843 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 09:57:33 +0200 Subject: [PATCH 01/10] Added cloudsync --- composer.json | 8 ++- config/services.yml | 14 +++++ .../admin/AdminMollieSettingsController.php | 59 +++++++++++++++++++ module_dependencies.json | 10 ++++ views/js/admin/cloudsync.js | 15 +++++ views/templates/admin/cloudsync.tpl | 35 +++++++++++ views/templates/admin/dependency_builder.tpl | 17 ++++++ 7 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 module_dependencies.json create mode 100644 views/js/admin/cloudsync.js create mode 100644 views/templates/admin/cloudsync.tpl create mode 100644 views/templates/admin/dependency_builder.tpl diff --git a/composer.json b/composer.json index dcfdcb4d3..d86cafc06 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,9 @@ "webmozart/assert": "^1.11", "symfony/http-client": "^4.4", "http-interop/http-factory-guzzle": "^1.1", - "php-http/message-factory": "^1.1" + "php-http/message-factory": "^1.1", + "prestashop/prestashop-accounts-installer": "^1.0.4", + "prestashop/module-lib-mbo-installer": "^2.0" }, "require-dev": { "roave/security-advisories": "dev-latest", @@ -41,11 +43,11 @@ }, "config": { "platform": { - "php": "7.2" + "php": "7.2.5" }, "prepend-autoloader": false, "allow-plugins": { - "php-http/discovery": true + "php-http/discovery": false } }, "type": "prestashop-module", diff --git a/config/services.yml b/config/services.yml index 76634b961..b815319b3 100644 --- a/config/services.yml +++ b/config/services.yml @@ -8,6 +8,20 @@ services: arguments: - 'mollie' + ##################### + # PS Account + Mollie.PsAccountsInstaller: + class: 'PrestaShop\PsAccountsInstaller\Installer\Installer' + public: true + arguments: + - "5.0" + + Mollie.PsAccountsFacade: + class: 'PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts' + public: true + arguments: + - "@Mollie.PsAccountsInstaller" + Mollie\Subscription\Grid\SubscriptionGridQueryBuilder: class: Mollie\Subscription\Grid\SubscriptionGridQueryBuilder parent: 'prestashop.core.grid.abstract_query_builder' diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index b9cf243af..5bea8d9e8 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -12,6 +12,10 @@ declare(strict_types=1); +use Prestashop\ModuleLibMboInstaller\DependencyBuilder; +use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder; +use PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException; + if (!defined('_PS_VERSION_')) { exit; } @@ -27,8 +31,63 @@ public function __construct() $this->bootstrap = true; } + private function initCloudSyncAndPsAccounts(): void + { + $mboInstaller = new DependencyBuilder($this->module); + + if( !$mboInstaller->areDependenciesMet() ) { + $dependencies = $mboInstaller->handleDependencies(); + $this->context->smarty->assign('dependencies', $dependencies); + + $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/dependency_builder.tpl'); + } + + $this->context->smarty->assign('module_dir', $this->module->getPathUri()); + $moduleManager = ModuleManagerBuilder::getInstance()->build(); + + try { + $accountsFacade = $this->module->getService('Mollie.PsAccountsFacade'); + $accountsService = $accountsFacade->getPsAccountsService(); + } catch (InstallerException $e) { + $accountsInstaller = $this->module->getService('Mollie.PsAccountsInstaller'); + $accountsInstaller->install(); + $accountsFacade = $this->module->getService('Mollie.PsAccountsFacade'); + $accountsService = $accountsFacade->getPsAccountsService(); + } + + try { + Media::addJsDef([ + 'contextPsAccounts' => $accountsFacade->getPsAccountsPresenter() + ->present($this->module->name), + ]); + + // Retrieve Account CDN + $this->context->smarty->assign('urlAccountsCdn', $accountsService->getAccountsCdn()); + + } catch (Exception $e) { + $this->context->controller->errors[] = $e->getMessage(); + } + + if ($moduleManager->isInstalled("ps_eventbus")) { + $eventbusModule = \Module::getInstanceByName("ps_eventbus"); + if (version_compare($eventbusModule->version, '1.9.0', '>=')) { + + $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); + + $this->context->smarty->assign('urlCloudsync', "https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js"); + $this->addJs($this->module->getPathUri() . '/views/js/admin/cloudsync.js'); + Media::addJsDef([ + 'contextPsEventbus' => $eventbusPresenterService->expose($this->module, ['info', 'modules', 'themes']) + ]); + } + } + + $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() .'views/templates/admin/cloudsync.tpl'); + } + public function postProcess() { + $this->initCloudSyncAndPsAccounts(); /** @var \Mollie\Repository\ModuleRepository $moduleRepository */ $moduleRepository = $this->module->getService(\Mollie\Repository\ModuleRepository::class); $moduleDatabaseVersion = $moduleRepository->getModuleDatabaseVersion($this->module->name); diff --git a/module_dependencies.json b/module_dependencies.json new file mode 100644 index 000000000..d8b1e5b1f --- /dev/null +++ b/module_dependencies.json @@ -0,0 +1,10 @@ +{ + "dependencies": [ + { + "name" : "ps_accounts" + }, + { + "name" : "ps_eventbus" + } + ] +} \ No newline at end of file diff --git a/views/js/admin/cloudsync.js b/views/js/admin/cloudsync.js new file mode 100644 index 000000000..38aee98c0 --- /dev/null +++ b/views/js/admin/cloudsync.js @@ -0,0 +1,15 @@ +$(document).ready(function () { + window?.psaccountsVue?.init(); + + // Cloud Sync + const cdc = window.cloudSyncSharingConsent; + + cdc.init('#prestashop-cloudsync'); + cdc.on('OnboardingCompleted', (isCompleted) => { + console.log('OnboardingCompleted', isCompleted); + + }); + cdc.isOnboardingCompleted((isCompleted) => { + console.log('Onboarding is already Completed', isCompleted); + }); +}); diff --git a/views/templates/admin/cloudsync.tpl b/views/templates/admin/cloudsync.tpl new file mode 100644 index 000000000..adb8e6b83 --- /dev/null +++ b/views/templates/admin/cloudsync.tpl @@ -0,0 +1,35 @@ +{* +* 2007-2023 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2023 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + +
+
+ +
+ +
+ + + diff --git a/views/templates/admin/dependency_builder.tpl b/views/templates/admin/dependency_builder.tpl new file mode 100644 index 000000000..10ff76f74 --- /dev/null +++ b/views/templates/admin/dependency_builder.tpl @@ -0,0 +1,17 @@ + + + + +
+ + \ No newline at end of file From c6a35463e025b17e8bf453b9faa8d308d05d218a Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:02:19 +0200 Subject: [PATCH 02/10] Cs fixer fix --- controllers/admin/AdminMollieSettingsController.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index 5bea8d9e8..f71d74a33 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -35,7 +35,7 @@ private function initCloudSyncAndPsAccounts(): void { $mboInstaller = new DependencyBuilder($this->module); - if( !$mboInstaller->areDependenciesMet() ) { + if(!$mboInstaller->areDependenciesMet()) { $dependencies = $mboInstaller->handleDependencies(); $this->context->smarty->assign('dependencies', $dependencies); @@ -63,26 +63,23 @@ private function initCloudSyncAndPsAccounts(): void // Retrieve Account CDN $this->context->smarty->assign('urlAccountsCdn', $accountsService->getAccountsCdn()); - } catch (Exception $e) { $this->context->controller->errors[] = $e->getMessage(); } - if ($moduleManager->isInstalled("ps_eventbus")) { + if ($moduleManager->isInstalled('ps_eventbus')) { $eventbusModule = \Module::getInstanceByName("ps_eventbus"); if (version_compare($eventbusModule->version, '1.9.0', '>=')) { - $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); - $this->context->smarty->assign('urlCloudsync', "https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js"); - $this->addJs($this->module->getPathUri() . '/views/js/admin/cloudsync.js'); + $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); $this->addJs($this->module->getPathUri() . '/views/js/admin/cloudsync.js'); Media::addJsDef([ 'contextPsEventbus' => $eventbusPresenterService->expose($this->module, ['info', 'modules', 'themes']) ]); } } - $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() .'views/templates/admin/cloudsync.tpl'); + $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/cloudsync.tpl'); } public function postProcess() From 05ceab7788651d8d626a6a4f96a7fb390122ce19 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:04:16 +0200 Subject: [PATCH 03/10] PHp stan fixes --- .../admin/AdminMollieSettingsController.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index f71d74a33..2a69351a4 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -12,10 +12,6 @@ declare(strict_types=1); -use Prestashop\ModuleLibMboInstaller\DependencyBuilder; -use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder; -use PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException; - if (!defined('_PS_VERSION_')) { exit; } @@ -33,7 +29,7 @@ public function __construct() private function initCloudSyncAndPsAccounts(): void { - $mboInstaller = new DependencyBuilder($this->module); + $mboInstaller = new Prestashop\ModuleLibMboInstaller\DependencyBuilder($this->module); if(!$mboInstaller->areDependenciesMet()) { $dependencies = $mboInstaller->handleDependencies(); @@ -43,12 +39,12 @@ private function initCloudSyncAndPsAccounts(): void } $this->context->smarty->assign('module_dir', $this->module->getPathUri()); - $moduleManager = ModuleManagerBuilder::getInstance()->build(); + $moduleManager = PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder::getInstance()->build(); try { $accountsFacade = $this->module->getService('Mollie.PsAccountsFacade'); $accountsService = $accountsFacade->getPsAccountsService(); - } catch (InstallerException $e) { + } catch (PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException $e) { $accountsInstaller = $this->module->getService('Mollie.PsAccountsInstaller'); $accountsInstaller->install(); $accountsFacade = $this->module->getService('Mollie.PsAccountsFacade'); @@ -68,8 +64,8 @@ private function initCloudSyncAndPsAccounts(): void } if ($moduleManager->isInstalled('ps_eventbus')) { - $eventbusModule = \Module::getInstanceByName("ps_eventbus"); - if (version_compare($eventbusModule->version, '1.9.0', '>=')) { + $eventbusModule = \Module::getInstanceByName('ps_eventbus'); + if (version_compare($eventbusModule->version, '1.9.0', '>=') && $eventbusModule) { $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); $this->addJs($this->module->getPathUri() . '/views/js/admin/cloudsync.js'); From d66c84173eba6d45ec9afc48df67f768d3a920a8 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:11:34 +0200 Subject: [PATCH 04/10] CS fixer fixes --- controllers/admin/AdminMollieSettingsController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index 2a69351a4..680b92793 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -31,7 +31,7 @@ private function initCloudSyncAndPsAccounts(): void { $mboInstaller = new Prestashop\ModuleLibMboInstaller\DependencyBuilder($this->module); - if(!$mboInstaller->areDependenciesMet()) { + if (!$mboInstaller->areDependenciesMet()) { $dependencies = $mboInstaller->handleDependencies(); $this->context->smarty->assign('dependencies', $dependencies); @@ -68,9 +68,10 @@ private function initCloudSyncAndPsAccounts(): void if (version_compare($eventbusModule->version, '1.9.0', '>=') && $eventbusModule) { $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); - $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); $this->addJs($this->module->getPathUri() . '/views/js/admin/cloudsync.js'); + $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); + $this->addJs($this->module->getPathUri() . '/views/js/admin/cloudsync.js'); Media::addJsDef([ - 'contextPsEventbus' => $eventbusPresenterService->expose($this->module, ['info', 'modules', 'themes']) + 'contextPsEventbus' => $eventbusPresenterService->expose($this->module, ['info', 'modules', 'themes']), ]); } } From 65c3ca76556a6e3319736ddf985eaf398ac893b5 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:12:38 +0200 Subject: [PATCH 05/10] PHP stan fix --- controllers/admin/AdminMollieSettingsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index 680b92793..713eaa89b 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -64,6 +64,7 @@ private function initCloudSyncAndPsAccounts(): void } if ($moduleManager->isInstalled('ps_eventbus')) { + /** @var Module $eventbusModule */ $eventbusModule = \Module::getInstanceByName('ps_eventbus'); if (version_compare($eventbusModule->version, '1.9.0', '>=') && $eventbusModule) { $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); From bd156d644bef21adbb0729a7b4fb1a3df2d0373a Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:15:47 +0200 Subject: [PATCH 06/10] Fixing phpstan --- controllers/admin/AdminMollieSettingsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index 713eaa89b..d4f508d77 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -64,9 +64,9 @@ private function initCloudSyncAndPsAccounts(): void } if ($moduleManager->isInstalled('ps_eventbus')) { - /** @var Module $eventbusModule */ + /** @var Ps_eventbus|false $eventbusModule */ $eventbusModule = \Module::getInstanceByName('ps_eventbus'); - if (version_compare($eventbusModule->version, '1.9.0', '>=') && $eventbusModule) { + if ($eventbusModule && version_compare($eventbusModule->version, '1.9.0', '>=')) { $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); From 3f97c9c788edd15a4e4d84f94aadeb29382a1cef Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:23:42 +0200 Subject: [PATCH 07/10] Fixing phpstan --- controllers/admin/AdminMollieSettingsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index d4f508d77..9e6504e69 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -64,9 +64,9 @@ private function initCloudSyncAndPsAccounts(): void } if ($moduleManager->isInstalled('ps_eventbus')) { - /** @var Ps_eventbus|false $eventbusModule */ $eventbusModule = \Module::getInstanceByName('ps_eventbus'); if ($eventbusModule && version_compare($eventbusModule->version, '1.9.0', '>=')) { + /** @phpstan-ignore-line PHPStan does not recognize the event bus odule, so it doesn't know it has getService function */ $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); From 5cbb5b1d4aa670f316b25658402fba8cd769d630 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:28:22 +0200 Subject: [PATCH 08/10] Fixing phpstan --- controllers/admin/AdminMollieSettingsController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index 9e6504e69..b4bb82a26 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -66,7 +66,8 @@ private function initCloudSyncAndPsAccounts(): void if ($moduleManager->isInstalled('ps_eventbus')) { $eventbusModule = \Module::getInstanceByName('ps_eventbus'); if ($eventbusModule && version_compare($eventbusModule->version, '1.9.0', '>=')) { - /** @phpstan-ignore-line PHPStan does not recognize the event bus odule, so it doesn't know it has getService function */ + /** PHPStan does not recognize the event bus module, so it doesn't know it has getService function */ + /** @phpstan-ignore-line */ $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); From ce6f7f80867c3675a0f997130fd18c7825b723d7 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:32:35 +0200 Subject: [PATCH 09/10] Fixing phpstan --- controllers/admin/AdminMollieSettingsController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/controllers/admin/AdminMollieSettingsController.php b/controllers/admin/AdminMollieSettingsController.php index b4bb82a26..420f9f43d 100644 --- a/controllers/admin/AdminMollieSettingsController.php +++ b/controllers/admin/AdminMollieSettingsController.php @@ -66,8 +66,7 @@ private function initCloudSyncAndPsAccounts(): void if ($moduleManager->isInstalled('ps_eventbus')) { $eventbusModule = \Module::getInstanceByName('ps_eventbus'); if ($eventbusModule && version_compare($eventbusModule->version, '1.9.0', '>=')) { - /** PHPStan does not recognize the event bus module, so it doesn't know it has getService function */ - /** @phpstan-ignore-line */ + /** @phpstan-ignore-next-line PHPStan does not recognize the event bus module, so it doesn't know it has getService function */ $eventbusPresenterService = $eventbusModule->getService('PrestaShop\Module\PsEventbus\Service\PresenterService'); $this->context->smarty->assign('urlCloudsync', 'https://assets.prestashop3.com/ext/cloudsync-merchant-sync-consent/latest/cloudsync-cdc.js'); From b4a80d6f91907e42fe2a463a5d82a7454a5be952 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 5 Mar 2024 10:45:41 +0200 Subject: [PATCH 10/10] Updating change log --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 2f558f73b..f5ba38210 100644 --- a/changelog.md +++ b/changelog.md @@ -3,7 +3,8 @@ # Changelog # ## Changes in release 6.1.0 ## -+ New payment methods: Twint, Blik. ++ New payment methods: Twint, Blik and Klarna ++ Added PrestaShop CloudSync support ## Changes in release 6.0.5 ## + Recurring order options are now in "Subscriptions" tab