Skip to content

Commit

Permalink
Final fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akf-bw committed Apr 24, 2024
1 parent 3fc47ae commit 2140d70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
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 type="service" id="Shopware\Storefront\Theme\StorefrontPluginRegistry"/>
<argument>%kernel.shopware_version%</argument>
<tag name="kernel.event_subscriber"/>
</service>
Expand Down
11 changes: 1 addition & 10 deletions src/Resources/views/mollie/head.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'frontend.detail.page' : 'pdp'
} %}


{% set currentRoute = app.request.attributes.get('_route') %}
{% set includeJsInHeader = false %}

Expand All @@ -28,19 +27,11 @@
{% endif %}
{% endif %}

{% if includeJsInHeader == true and mollie_javascript_use_head == 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>

{% if mollie_javascript_use_shopware != '1' and includeJsInHeader == true %}
{% if mollie_javascript_already_exists == false and mollie_javascript_use_shopware != '1' and includeJsInHeader == true %}
<script type="text/javascript" src="{{ asset('bundles/molliepayments/mollie-payments.js', 'asset') }}" defer></script>
{% endif %}

Expand Down
17 changes: 15 additions & 2 deletions src/Subscriber/StorefrontBuildSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Kiener\MolliePayments\Compatibility\VersionCompare;
use Kiener\MolliePayments\Service\SettingsService;
use Shopware\Storefront\Event\StorefrontRenderEvent;
use Shopware\Storefront\Theme\StorefrontPluginRegistryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class StorefrontBuildSubscriber implements EventSubscriberInterface
Expand All @@ -14,6 +15,11 @@ class StorefrontBuildSubscriber implements EventSubscriberInterface
*/
private $settingsService;

/**
* @var StorefrontPluginRegistryInterface
*/
private $pluginRegistry;

/**
* @var VersionCompare
*/
Expand All @@ -24,9 +30,10 @@ class StorefrontBuildSubscriber implements EventSubscriberInterface
* @param SettingsService $settingsService
* @param string $shopwareVersion
*/
public function __construct(SettingsService $settingsService, string $shopwareVersion)
public function __construct(SettingsService $settingsService, StorefrontPluginRegistryInterface $pluginRegistry, string $shopwareVersion)
{
$this->settingsService = $settingsService;
$this->pluginRegistry = $pluginRegistry;
$this->versionCompare = new VersionCompare($shopwareVersion);
}

Expand All @@ -51,6 +58,12 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void

$useJsValue = (int)$settings->isUseShopwareJavascript();
$event->setParameter('mollie_javascript_use_shopware', $useJsValue);
$event->setParameter('mollie_javascript_use_head', $this->versionCompare->gte('6.6'));

$mollieJavascriptAlreadyExists = false;
if($this->versionCompare->gte('6.6')) {
$molliePayments = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments');
$mollieJavascriptAlreadyExists = $molliePayments?->getScriptFiles()->count() ?? 0 > 0;

Check failure on line 65 in src/Subscriber/StorefrontBuildSubscriber.php

View workflow job for this annotation

GitHub Actions / PHPStan

Syntax error, unexpected T_OBJECT_OPERATOR on line 65
}
$event->setParameter('mollie_javascript_already_exists', $mollieJavascriptAlreadyExists);
}
}

0 comments on commit 2140d70

Please sign in to comment.