From 413aa84f166ceaadf315a7b6d9eff4506c5d7018 Mon Sep 17 00:00:00 2001 From: Thilo <40621547+ThLind@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:56:20 +0200 Subject: [PATCH] PISHPS-368: Hide cart apple pay option (#867) Co-authored-by: Thilo Lindner --- .../apple-pay-payment-method.plugin.js | 26 +++++++++++-------- .../page/account/payment/index.html.twig | 6 +++-- .../page/checkout/cart/index.html.twig | 14 ++++++++++ src/Subscriber/ApplePayDirectSubscriber.php | 3 +++ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js index ca6674e1c..5a4b6bfc7 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js @@ -24,17 +24,12 @@ export default class MollieApplePayPaymentMethod extends Plugin { this.hideApplePay('.payment-method-input.applepay'); // support for >= Shopware 6.4 - // we have to find the dynamic ID and use that - // one as a selector to hide it - const client = new HttpClient(); - client.get( - shopUrl + '/mollie/apple-pay/applepay-id', - (data) => { - me.hideApplePay('#paymentMethod' + data.id); - } - ); - + this.hideApplePay('#paymentMethod' + this.options.applePayId) + // hide cart apple pay select option + if (this.options.hideApplePayOption) { + this.hideApplePaySelect(this.options.applePayId); + } } /** @@ -50,6 +45,15 @@ export default class MollieApplePayPaymentMethod extends Plugin { } } + /** + * + * @param applePayId + */ + hideApplePaySelect(applePayId) { + const option = document.querySelector('option[value="' + applePayId + '"]'); + option.remove(); + } + /** * * @returns {*} @@ -107,4 +111,4 @@ export default class MollieApplePayPaymentMethod extends Plugin { return null; } -} \ No newline at end of file +} diff --git a/src/Resources/views/storefront/page/account/payment/index.html.twig b/src/Resources/views/storefront/page/account/payment/index.html.twig index eb67c69ef..ac28f052b 100644 --- a/src/Resources/views/storefront/page/account/payment/index.html.twig +++ b/src/Resources/views/storefront/page/account/payment/index.html.twig @@ -4,7 +4,9 @@ {% if mollie_applepay_enabled %}
{% endif %} @@ -78,4 +80,4 @@ {% endblock %} {{ parent() }} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/Resources/views/storefront/page/checkout/cart/index.html.twig b/src/Resources/views/storefront/page/checkout/cart/index.html.twig index 35883d56e..4988525fc 100644 --- a/src/Resources/views/storefront/page/checkout/cart/index.html.twig +++ b/src/Resources/views/storefront/page/checkout/cart/index.html.twig @@ -1,5 +1,19 @@ {% sw_extends '@Storefront/storefront/page/checkout/cart/index.html.twig' %} +{% block page_checkout_cart %} + {% if mollie_applepay_enabled %} +
+ {% endif %} + + {{ parent() }} +{% endblock %} + {% block page_checkout_cart_shipping_costs_form_group_payment_method %}
diff --git a/src/Subscriber/ApplePayDirectSubscriber.php b/src/Subscriber/ApplePayDirectSubscriber.php index ea78eadc8..03a9dace9 100644 --- a/src/Subscriber/ApplePayDirectSubscriber.php +++ b/src/Subscriber/ApplePayDirectSubscriber.php @@ -53,9 +53,12 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void $shoPhoneNumberField = $settings->isPhoneNumberFieldRequired() || $settings->isPhoneNumberFieldShown(); + $applePayPaymentMethodId = $this->applePay->getActiveApplePayID($event->getSalesChannelContext()); + $event->setParameter('mollie_applepaydirect_phonenumber_required', (int)$shoPhoneNumberField); $event->setParameter('mollie_applepaydirect_enabled', $applePayDirectEnabled); $event->setParameter('mollie_applepaydirect_restrictions', $settings->getRestrictApplePayDirect()); $event->setParameter('mollie_express_required_data_protection', $settings->isRequireDataProtectionCheckbox() && $event->getSalesChannelContext()->getCustomer() == null); + $event->setParameter('apple_pay_payment_method_id', $applePayPaymentMethodId); } }