Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currency Symbol Positioning Issue #984

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 = "<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 @@ -119,7 +121,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 @@ -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) {
Expand Down
Loading