From 4c12360d9cf84f6c5a29ff5935287a7ddfdc292d Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 4 Dec 2024 15:53:06 +0800 Subject: [PATCH] include locale value normalization Fixes $3789 --- CHANGELOG.md | 4 ++++ src/controllers/OrdersController.php | 4 ++++ .../_components/gateways/_modalWrapper.twig | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 089c31dd94..b6d67c23cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft Commerce +## Unreleased + +- Fixed a bug where the price was not formatted correctly according to the locale in the payment model on the Order Edit screens. ([#3789](https://github.com/craftcms/commerce/issues/3789)) + ## 5.2.7 - 2024-11 - Fixed an error that occurred on the Orders index page when running Craft CMS 5.5.4 or later. ([#3793](https://github.com/craftcms/commerce/issues/3793)) diff --git a/src/controllers/OrdersController.php b/src/controllers/OrdersController.php index 87f871c06a..9b4d07f076 100644 --- a/src/controllers/OrdersController.php +++ b/src/controllers/OrdersController.php @@ -1236,11 +1236,15 @@ public function actionPaymentAmountData(): Response $paymentCurrencies = Plugin::getInstance()->getPaymentCurrencies(); $paymentCurrency = $this->request->getRequiredParam('paymentCurrency'); $paymentAmount = $this->request->getRequiredParam('paymentAmount'); + $locale = $this->request->getRequiredParam('locale'); $orderId = $this->request->getRequiredParam('orderId'); /** @var Order $order */ $order = Order::find()->id($orderId)->one(); $baseCurrency = $order->currency; + $paymentAmount = MoneyHelper::toMoney(['value' => $paymentAmount, 'currency' => $baseCurrency, 'locale' => $locale]); + $paymentAmount = MoneyHelper::toDecimal($paymentAmount); + $baseCurrencyPaymentAmount = $paymentCurrencies->convertCurrency($paymentAmount, $paymentCurrency, $baseCurrency); $baseCurrencyPaymentAmountAsCurrency = Craft::t('commerce', 'Pay {amount} of {currency} on the order.', ['amount' => Currency::formatAsCurrency($baseCurrencyPaymentAmount, $baseCurrency), 'currency' => $baseCurrency]); diff --git a/src/templates/_components/gateways/_modalWrapper.twig b/src/templates/_components/gateways/_modalWrapper.twig index 06ab826d5a..948ff011b4 100644 --- a/src/templates/_components/gateways/_modalWrapper.twig +++ b/src/templates/_components/gateways/_modalWrapper.twig @@ -20,9 +20,15 @@ {{ formHtml|raw }}
- Payment Amount + {{ "Payment Amount"|t('commerce') }}
- + + {% set currencies = craft.commerce.paymentCurrencies.getAllPaymentCurrencies() %} {% set primaryCurrency = craft.commerce.paymentCurrencies.getPrimaryPaymentCurrency() %} @@ -77,7 +83,8 @@ function updatePrice(form) { - var price = form.find("input.paymentAmount").val(); + var price = form.find("input[name='paymentAmount[value]']").val(); + var locale = form.find("input[name='paymentAmount[locale]']").val(); $.ajax({ type: "POST", @@ -89,6 +96,7 @@ data: { 'action' : 'commerce/orders/payment-amount-data', 'paymentAmount': price, + 'locale': locale, 'paymentCurrency': form.find(".paymentCurrency").val(), 'orderId' : orderId },