From c3a34c07e0c6107a19dceb9d7517ace2ae8e8044 Mon Sep 17 00:00:00 2001 From: Benjamin Wittwer Date: Tue, 16 Apr 2024 09:43:15 +0200 Subject: [PATCH] Exclude mollie script, if it already exists in the header --- src/Resources/config/services/subscriber.xml | 1 + src/Resources/views/storefront/layout/meta.html.twig | 8 ++++++++ src/Subscriber/StorefrontBuildSubscriber.php | 11 ++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Resources/config/services/subscriber.xml b/src/Resources/config/services/subscriber.xml index ba25c3490..d13a6baa1 100644 --- a/src/Resources/config/services/subscriber.xml +++ b/src/Resources/config/services/subscriber.xml @@ -42,6 +42,7 @@ + %kernel.shopware_version% diff --git a/src/Resources/views/storefront/layout/meta.html.twig b/src/Resources/views/storefront/layout/meta.html.twig index 206b3868e..41063cc5b 100644 --- a/src/Resources/views/storefront/layout/meta.html.twig +++ b/src/Resources/views/storefront/layout/meta.html.twig @@ -29,6 +29,14 @@ {% endif %} {% endif %} + {% if includeJsInHeader == true and mollie_javascript_check_duplicate == true %} + {% for script in theme_scripts() %} + {% if script == 'js/mollie-payments/mollie-payments.js' %} + {% set includeJsInHeader = false %} + {% endif %} + {% endfor %} + {% endif %} + diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index 07bbbe9fc..f8192cba6 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -2,6 +2,7 @@ namespace Kiener\MolliePayments\Subscriber; +use Kiener\MolliePayments\Compatibility\VersionCompare; use Kiener\MolliePayments\Service\SettingsService; use Shopware\Storefront\Event\StorefrontRenderEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -13,13 +14,20 @@ class StorefrontBuildSubscriber implements EventSubscriberInterface */ private $settingsService; + /** + * @var VersionCompare + */ + private $versionCompare; + /** * @param SettingsService $settingsService + * @param string $shopwareVersion */ - public function __construct(SettingsService $settingsService) + public function __construct(SettingsService $settingsService, string $shopwareVersion) { $this->settingsService = $settingsService; + $this->versionCompare = new VersionCompare($shopwareVersion); } /** @@ -43,5 +51,6 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void $useJsValue = (int)$settings->isUseShopwareJavascript(); $event->setParameter('mollie_javascript_use_shopware', $useJsValue); + $event->setParameter('mollie_javascript_check_duplicate', $this->versionCompare->gte('6.6')); } }