From 89dd84e47379d9bb7148de4233db67b1a12da83a Mon Sep 17 00:00:00 2001 From: Aleksej Wert <55035661+GuentherHade@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:32:17 +0100 Subject: [PATCH] NTR: show mollie payment js if needed (#712) * NTR: show mollie payment js if needed * NTR: added comments * NTR: Fixes --- src/Resources/views/storefront/base.html.twig | 34 ++++++++++++++++++- src/Subscriber/ApplePaySubscriber.php | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Resources/views/storefront/base.html.twig b/src/Resources/views/storefront/base.html.twig index 073e5f54b..7b2ce1a1d 100644 --- a/src/Resources/views/storefront/base.html.twig +++ b/src/Resources/views/storefront/base.html.twig @@ -1,11 +1,43 @@ {% sw_extends '@Storefront/storefront/base.html.twig' %} {% block base_main %} + + + {# pages where apple pay requires js with their mollie_applepaydirect_restrictions names as values #} + {% set onlyShowHere = { + 'frontend.checkout.confirm.page' : '', + 'frontend.checkout.cart.page' : 'cart', + 'frontend.navigation.page' : 'plp', + 'frontend.account.edit-order.page' : '', + 'frontend.detail.page' : 'pdp' + } %} + + + {% set currentRoute = app.request.attributes.get('_route') %} + {% set implementJS = false %} + + {# js always required on this pages #} + {% if currentRoute == 'frontend.checkout.cart.page' or currentRoute == 'frontend.checkout.confirm.page' %} + {% set implementJS = true %} + {% endif %} + + {# requirement check for apple pay direct #} + {% if mollie_applepaydirect_enabled == true or mollie_applepay_enabled == true %} + {% if currentRoute in onlyShowHere|keys and onlyShowHere[currentRoute] not in mollie_applepaydirect_restrictions %} + {% set implementJS = true %} + {% endif %} + {% if 'offcanvas' not in mollie_applepaydirect_restrictions %} + {% set implementJS = true %} + {% endif %} + {% endif %} + - {% if mollie_javascript_use_shopware != '1' %} + + {% if mollie_javascript_use_shopware != '1' and implementJS == true %} {% endif %} + {{ parent() }} {% endblock %} \ No newline at end of file diff --git a/src/Subscriber/ApplePaySubscriber.php b/src/Subscriber/ApplePaySubscriber.php index b08efd746..12fa5441a 100644 --- a/src/Subscriber/ApplePaySubscriber.php +++ b/src/Subscriber/ApplePaySubscriber.php @@ -40,7 +40,7 @@ public static function getSubscribedEvents() public function onStorefrontRender(StorefrontRenderEvent $event): void { try { - $applePayEnabled = $this->applePay->getActiveApplePayID($event->getSalesChannelContext()); + $applePayEnabled = (bool) $this->applePay->getActiveApplePayID($event->getSalesChannelContext()); } catch (\Exception $ex) { $applePayEnabled = false; }