Skip to content

Commit

Permalink
PISHPS-368: Hide cart apple pay option (#867)
Browse files Browse the repository at this point in the history
Co-authored-by: Thilo Lindner <[email protected]>
  • Loading branch information
ThLind and Thilo Lindner authored Oct 22, 2024
1 parent 616c80a commit 413aa84
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand All @@ -50,6 +45,15 @@ export default class MollieApplePayPaymentMethod extends Plugin {
}
}

/**
*
* @param applePayId
*/
hideApplePaySelect(applePayId) {
const option = document.querySelector('option[value="' + applePayId + '"]');
option.remove();
}

/**
*
* @returns {*}
Expand Down Expand Up @@ -107,4 +111,4 @@ export default class MollieApplePayPaymentMethod extends Plugin {
return null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
{% if mollie_applepay_enabled %}
<div id="mollie_hide_applepay" data-mollie-template-applepay-account data-mollie-apple-pay-payment-method-options="{{ {
shopUrl: seoUrl('frontend.home.page'),
hideAlways: true
hideAlways: true,
applePayId: apple_pay_payment_method_id,
hideApplePayOption: false
}
|json_encode }}"></div>
{% endif %}
Expand Down Expand Up @@ -78,4 +80,4 @@
{% endblock %}

{{ parent() }}
{% endblock %}
{% endblock %}
14 changes: 14 additions & 0 deletions src/Resources/views/storefront/page/checkout/cart/index.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
{% sw_extends '@Storefront/storefront/page/checkout/cart/index.html.twig' %}

{% block page_checkout_cart %}
{% if mollie_applepay_enabled %}
<div id="mollie_hide_applepay" data-mollie-template-applepay-account data-mollie-apple-pay-payment-method-options="{{ {
shopUrl: seoUrl('frontend.home.page'),
hideAlways: true,
applePayId: apple_pay_payment_method_id,
hideApplePayOption: true
}
|json_encode }}"></div>
{% endif %}

{{ parent() }}
{% endblock %}

{% block page_checkout_cart_shipping_costs_form_group_payment_method %}
<div class="form-group">
<label for="paymentMethodId">{{ "checkout.paymentMethod"|trans|sw_sanitize }}</label>
Expand Down
3 changes: 3 additions & 0 deletions src/Subscriber/ApplePayDirectSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 413aa84

Please sign in to comment.