Skip to content

Commit

Permalink
Exclude mollie script, if it already exists in the header
Browse files Browse the repository at this point in the history
  • Loading branch information
akf-bw committed Apr 16, 2024
1 parent 4072493 commit c3a34c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Resources/config/services/subscriber.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

<service id="Kiener\MolliePayments\Subscriber\StorefrontBuildSubscriber">
<argument type="service" id="Kiener\MolliePayments\Service\SettingsService"/>
<argument>%kernel.shopware_version%</argument>
<tag name="kernel.event_subscriber"/>
</service>

Expand Down
8 changes: 8 additions & 0 deletions src/Resources/views/storefront/layout/meta.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<script>
window.mollie_javascript_use_shopware = '{{ mollie_javascript_use_shopware }}'
</script>
Expand Down
11 changes: 10 additions & 1 deletion src/Subscriber/StorefrontBuildSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand All @@ -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'));
}
}

0 comments on commit c3a34c0

Please sign in to comment.