From 3ad2148dc8a7a47ed414acd604047b829c87c48f Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 16 Oct 2023 10:16:22 +0200 Subject: [PATCH] Bugfix: Handle prices formatted in difference currencies --- view/frontend/web/js/view/product/apple-pay-button.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/view/frontend/web/js/view/product/apple-pay-button.js b/view/frontend/web/js/view/product/apple-pay-button.js index 8381a23006e..f965801e7e1 100644 --- a/view/frontend/web/js/view/product/apple-pay-button.js +++ b/view/frontend/web/js/view/product/apple-pay-button.js @@ -48,10 +48,13 @@ define([ }, getProductPrice: function () { - return $('[data-role=priceBox][data-product-id] [data-price-type="finalPrice"] .price') + var price = $('[data-role=priceBox][data-product-id] [data-price-type="finalPrice"] .price') .html() - .replace(/[^\d,.-]/g, '') - .replace(',', '.'); + .replace(/[^\d,.-]/g, ''); + + // We get the price formatted as in the currency, eg 1.000,00 or 1,000.00. So remove all dots and + // commas and divide by 100 to get the price in cents. + return (price.replace(',', '').replace('.', '') / 100).toFixed(2); }, createApplePaySession: function () {