From 8145860573df1af93cdc063aa434e2f571b1b3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=BCsken?= Date: Thu, 16 Jan 2025 16:02:40 +0100 Subject: [PATCH] Fix displaying of currency symbol --- resources/js/blocks/molliePaymentMethod.js | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/resources/js/blocks/molliePaymentMethod.js b/resources/js/blocks/molliePaymentMethod.js index 3c09149f..e8f79e60 100644 --- a/resources/js/blocks/molliePaymentMethod.js +++ b/resources/js/blocks/molliePaymentMethod.js @@ -1,5 +1,10 @@ let cachedAvailableGateways = {}; +function formatPriceLikeWc(price) { + // todo add thousandSeparator + return wcSettings.currency.priceFormat.replace('%1$s', wcSettings.currency.symbol).replace('%2$s',price.toFixed(wcSettings.currency.precision).replace('.', wcSettings.currency.decimalSeparator)); +} + function loadCachedAvailableGateways() { const storedData = localStorage.getItem('cachedAvailableGateways'); if (storedData) { @@ -93,24 +98,21 @@ const MollieComponent = (props) => { const billingPhone = document.getElementById('billing-phone'); return billingPhone || shippingPhone; } - function updateTotalLabel(newTotal, currency) { - let feeText = newTotal + " " + currency - let totalSpan = "" + feeText + "" + function updateTotalLabel(newTotal) { + let totalSpan = "" + formatPriceLikeWc(newTotal) + "" let total = jQuery('.wc-block-components-totals-footer-item .wc-block-formatted-money-amount:first') total.replaceWith(totalSpan) } - function updateTaxesLabel(newTotal, currency) { - let feeText = newTotal + " " + currency - - let totalSpan = "" + feeText + "" + function updateTaxesLabel(newTotal) { + let totalSpan = "" + formatPriceLikeWc(newTotal) + "" let total = jQuery('div.wp-block-woocommerce-checkout-order-summary-taxes-block.wc-block-components-totals-wrapper > div > span.wc-block-formatted-money-amount.wc-block-components-formatted-money-amount.wc-block-components-totals-item__value:first') total.replaceWith(totalSpan) } function hideFee(fee, response) { fee?.hide() - updateTotalLabel(response.data.newTotal.toFixed(2).replace('.', ','), response.data.currency); - updateTaxesLabel(response.data.totalTax.toFixed(2).replace('.', ','), response.data.currency); + updateTotalLabel(response.data.newTotal); + updateTaxesLabel(response.data.totalTax); } function feeMarkup(response) { @@ -119,7 +121,7 @@ const MollieComponent = (props) => { + response.data.name + "" + "" - + response.data.amount.toFixed(2).replace('.', ',') + " " + response.data.currency + + formatPriceLikeWc(response.data.amount) + "" + "
" + "
" + @@ -128,15 +130,15 @@ const MollieComponent = (props) => { function replaceFee(fee, newFee, response) { fee.replaceWith(newFee) - updateTotalLabel(response.data.newTotal.toFixed(2).replace('.', ','), response.data.currency); - updateTaxesLabel(response.data.totalTax.toFixed(2).replace('.', ','), response.data.currency); + updateTotalLabel(response.data.newTotal); + updateTaxesLabel(response.data.totalTax); } function insertNewFee(newFee, response) { const subtotal = jQuery('.wc-block-components-totals-item:first') subtotal.after(newFee) - updateTotalLabel(response.data.newTotal.toFixed(2).replace('.', ','), response.data.currency); - updateTaxesLabel(response.data.totalTax.toFixed(2).replace('.', ','), response.data.currency); + updateTotalLabel(response.data.newTotal); + updateTaxesLabel(response.data.totalTax); } function handleFees(response) {