Skip to content

Commit

Permalink
Merge pull request #888 from mollie/PIPRES-342-addcloudsync
Browse files Browse the repository at this point in the history
Added cloudsync
  • Loading branch information
JevgenijVisockij authored Mar 5, 2024
2 parents a88f0bf + b4a80d6 commit 23a8872
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 4 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
54 changes: 54 additions & 0 deletions controllers/admin/AdminMollieSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,62 @@ public function __construct()
$this->bootstrap = true;
}

private function initCloudSyncAndPsAccounts(): void
{
$mboInstaller = new Prestashop\ModuleLibMboInstaller\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 = PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder::getInstance()->build();

try {
$accountsFacade = $this->module->getService('Mollie.PsAccountsFacade');
$accountsService = $accountsFacade->getPsAccountsService();
} catch (PrestaShop\PsAccountsInstaller\Installer\Exception\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 ($eventbusModule && version_compare($eventbusModule->version, '1.9.0', '>=')) {
/** @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');
$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);
Expand Down
10 changes: 10 additions & 0 deletions module_dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dependencies": [
{
"name" : "ps_accounts"
},
{
"name" : "ps_eventbus"
}
]
}
15 changes: 15 additions & 0 deletions views/js/admin/cloudsync.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
35 changes: 35 additions & 0 deletions views/templates/admin/cloudsync.tpl
Original file line number Diff line number Diff line change
@@ -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 [email protected] 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 <[email protected]>
* @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
*}

<prestashop-accounts></prestashop-accounts>
<br>
<div id="prestashop-cloudsync"></div>

<div id="ps-modal"></div>

<br>

<script src="{$urlAccountsCdn|escape:'htmlall':'UTF-8'}" rel=preload></script>
<script src="{$urlCloudsync|escape:'htmlall':'UTF-8'}"></script>
17 changes: 17 additions & 0 deletions views/templates/admin/dependency_builder.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Load cdc library -->
<script src="https://assets.prestashop3.com/dst/mbo/v1/mbo-cdc-dependencies-resolver.umd.js"></script>

<!-- cdc container -->
<div id="cdc-container"></div>

<script defer>
const renderMboCdcDependencyResolver = window.mboCdcDependencyResolver.render
const context = {
...{$dependencies|json_encode},
onDependenciesResolved: () => location.reload(),
onDependencyResolved: (dependencyData) => console.log('Dependency installed', dependencyData), // name, displayName, version
onDependencyFailed: (dependencyData) => console.log('Failed to install dependency', dependencyData),
onDependenciesFailed: () => console.log('There are some errors'),
}
renderMboCdcDependencyResolver(context, '#cdc-container')
</script>

0 comments on commit 23a8872

Please sign in to comment.