From c9f025b19af6bf5a9e7982cc0f3fcf62e919ca8f Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 22 May 2024 09:23:29 +0200 Subject: [PATCH] NTR: fix loading of script files --- .../storefront/src/mollie-payments/Plugin.js | 2 ++ .../core/creditcard-mandate.plugin.js | 3 ++- .../plugins/apple-pay-direct.plugin.js | 3 ++- .../plugins/apple-pay-payment-method.plugin.js | 3 ++- .../mollie-payments/plugins/bancomat-plugin.js | 4 +++- .../plugins/creditcard-mandate-manage.plugin.js | 3 ++- .../plugins/ideal-issuer.plugin.js | 3 ++- .../plugins/pos-terminal.plugin.js | 3 ++- src/Subscriber/StorefrontBuildSubscriber.php | 17 ++++++++++++++--- 9 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 src/Resources/app/storefront/src/mollie-payments/Plugin.js diff --git a/src/Resources/app/storefront/src/mollie-payments/Plugin.js b/src/Resources/app/storefront/src/mollie-payments/Plugin.js new file mode 100644 index 000000000..142fd8432 --- /dev/null +++ b/src/Resources/app/storefront/src/mollie-payments/Plugin.js @@ -0,0 +1,2 @@ + +export default class Plugin extends window.PluginBaseClass{} \ No newline at end of file diff --git a/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js b/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js index dfcf13966..f9942cb00 100644 --- a/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js @@ -1,9 +1,10 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; /** * This plugin manage the credit card mandate of the customer */ -export default class MollieCreditCardMandate extends window.PluginBaseClass { +export default class MollieCreditCardMandate extends Plugin { static options = { newCardMandateOption: null, mollieCreditCardFormClass: '.mollie-components-credit-card', diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js index 0b2d667e4..93c264ace 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js @@ -1,6 +1,7 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; -export default class MollieApplePayDirect extends window.PluginBaseClass { +export default class MollieApplePayDirect extends Plugin { /** * diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js index a79b06208..a2856efa8 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js @@ -1,6 +1,7 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; -export default class MollieApplePayPaymentMethod extends window.PluginBaseClass { +export default class MollieApplePayPaymentMethod extends Plugin { /** * diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js index 29cef07fe..eee0d5b46 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js @@ -1,4 +1,6 @@ -export default class MollieBancomatPlugin extends window.PluginBaseClass { +import Plugin from "../Plugin"; + +export default class MollieBancomatPlugin extends Plugin { init() { diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js index 6b8098b47..0903a86c0 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js @@ -1,9 +1,10 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; /** * This plugin manage the credit card mandate of customer */ -export default class MollieCreditCardMandateManage extends window.PluginBaseClass { +export default class MollieCreditCardMandateManage extends Plugin { static options = { shopUrl: null, customerId: null, diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js index eb0bf898f..a684e203b 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js @@ -1,7 +1,8 @@ import HttpClient from '../services/HttpClient' +import Plugin from "../Plugin"; -export default class MollieIDealIssuer extends window.PluginBaseClass { +export default class MollieIDealIssuer extends Plugin { _shopUrl = ''; _customerId = ''; diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js index a7f4fa2d1..610f1dd7c 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js @@ -1,7 +1,8 @@ import HttpClient from '../services/HttpClient' +import Plugin from "../Plugin"; -export default class MolliePosTerminalPlugin extends window.PluginBaseClass { +export default class MolliePosTerminalPlugin extends Plugin { _shopUrl = ''; _customerId = ''; diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index 563209a36..ae0cdf3a0 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -5,6 +5,7 @@ use Kiener\MolliePayments\Compatibility\VersionCompare; use Kiener\MolliePayments\Service\SettingsService; use Shopware\Storefront\Event\StorefrontRenderEvent; +use Shopware\Storefront\Theme\StorefrontPluginConfiguration\StorefrontPluginConfiguration; use Shopware\Storefront\Theme\StorefrontPluginRegistryInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -60,11 +61,21 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void $event->setParameter('mollie_javascript_use_shopware', $useJsValue); $mollieJavascriptAlreadyExists = false; + if ($this->versionCompare->gte('6.6')) { - $molliePayments = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments'); - $mollieJavascriptAlreadyExists = $molliePayments && ($molliePayments->getScriptFiles()->count() > 0); - $event->setParameter('mollie_javascript_use_shopware', true); + $plugin = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments'); + + if ($plugin instanceof StorefrontPluginConfiguration) { + $scriptFiles = $plugin->getScriptFiles(); + + if ($useJsValue === 0) { + $scriptFiles->remove(0); + } + $mollieJavascriptAlreadyExists = $scriptFiles->count() > 0; + } } + $event->setParameter('mollie_javascript_already_exists', $mollieJavascriptAlreadyExists); + $event->setParameter('mollie_javascript_already_exists', false); } }