Skip to content

Commit

Permalink
NTR: show mollie payment js if needed (#712)
Browse files Browse the repository at this point in the history
* NTR: show mollie payment js if needed

* NTR: added comments

* NTR: Fixes
  • Loading branch information
GuentherHade authored Feb 29, 2024
1 parent b2eff45 commit 89dd84e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/Resources/views/storefront/base.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}

<script>
window.mollie_javascript_use_shopware = '{{ mollie_javascript_use_shopware }}'
</script>
{% if mollie_javascript_use_shopware != '1' %}

{% if mollie_javascript_use_shopware != '1' and implementJS == true %}

This comment has been minimized.

Copy link
@boxblinkracer

boxblinkracer Feb 29, 2024

Collaborator

maybe rename implementJS to addJsToPage? or something like this?

This comment has been minimized.

Copy link
@boxblinkracer

boxblinkracer Feb 29, 2024

Collaborator

also, i think that works good, but only in mode with custom webpack
we also support shopware-standard storefront building with js

however that would not work in the same way and it would still be on every page
the main.js (or register custom file in our case) needs to be enhanced with twig-bound div layers, so that its only added to these pages

however...again...this would all destroy the option to have an agency add an apple pay button to another page than these?

<script src="{{ asset('bundles/molliepayments/mollie-payments.js', 'asset') }}"></script>
{% endif %}

{{ parent() }}
{% endblock %}
2 changes: 1 addition & 1 deletion src/Subscriber/ApplePaySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

This comment has been minimized.

Copy link
@boxblinkracer

boxblinkracer Feb 29, 2024

Collaborator

ID is not BOOL? could it be that the wrong function is used?
or that the variable is just wrong and its actually $applePayID which would be fine to use string?

This comment has been minimized.

Copy link
@boxblinkracer

boxblinkracer Feb 29, 2024

Collaborator

yeah just double checked, bool is wrong
it returns a string, so this accidentally works

this would be more correct

$applePayID = $this->....get....
$applePayEnabled = true;

so if it does not crash, its true....thats all that is necessary

still there are other ways, but this one is not really correct

} catch (\Exception $ex) {
$applePayEnabled = false;
}
Expand Down

0 comments on commit 89dd84e

Please sign in to comment.