Skip to content

Commit

Permalink
Merge pull request #984 from mollie/PIWOO-576-currency-symbol-positio…
Browse files Browse the repository at this point in the history
…ning-issue

Currency Symbol Positioning Issue
  • Loading branch information
danielhuesken authored Jan 31, 2025
2 parents 238ed00 + 8145860 commit 3fefff3
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions resources/js/blocks/molliePaymentMethod.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -95,24 +100,21 @@ const MollieComponent = (props) => {
const billingPhone = document.getElementById('billing-phone');
return billingPhone || shippingPhone;
}
function updateTotalLabel(newTotal, currency) {
let feeText = newTotal + " " + currency
let totalSpan = "<span class='wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-totals-item__value'>" + feeText + "</span>"
function updateTotalLabel(newTotal) {
let totalSpan = "<span class='wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-totals-item__value'>" + formatPriceLikeWc(newTotal) + "</span>"
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 = "<span class='wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-totals-item__value'>" + feeText + "</span>"
function updateTaxesLabel(newTotal) {
let totalSpan = "<span class='wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-totals-item__value'>" + formatPriceLikeWc(newTotal) + "</span>"
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) {
Expand All @@ -121,7 +123,7 @@ const MollieComponent = (props) => {
+ response.data.name
+ "</span>" +
"<span class='wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-totals-item__value'>"
+ response.data.amount.toFixed(2).replace('.', ',') + " " + response.data.currency
+ formatPriceLikeWc(response.data.amount)
+ "</span>" +
"<div class='wc-block-components-totals-item__description'>" +
"</div>" +
Expand All @@ -130,15 +132,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) {
Expand Down

0 comments on commit 3fefff3

Please sign in to comment.