Skip to content

Commit 71650c8

Browse files
authored
MCLOUD-8279: Added MDVA-40924 patch (Fixed currency displaying on product page). (#45)
1 parent e525467 commit 71650c8

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

patches.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@
260260
"Incompatible PHP Method Fix": {
261261
"2.3.7-p1": "AC-384__Fix_Incompatible_PHP_Method__2.3.7-p1_ce.patch",
262262
"2.4.3": "AC-384__Fix_Incompatible_PHP_Method__2.4.3_ce.patch"
263+
},
264+
"Fixed currency displaying on product page": {
265+
">=2.4.3 <2.4.4": "MCLOUD-8279__Fixed_currency_displaying_on_product_page__2.4.3.patch"
263266
}
264267
},
265268
"magento/module-paypal": {
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
diff -Nuar a/vendor/magento/module-directory/Model/Currency.php b/vendor/magento/module-directory/Model/Currency.php
2+
index 65b47d7535c..e1815b25619 100644
3+
--- a/vendor/magento/module-directory/Model/Currency.php
4+
+++ b/vendor/magento/module-directory/Model/Currency.php
5+
@@ -13,6 +13,7 @@ use Magento\Framework\Locale\Currency as LocaleCurrency;
6+
use Magento\Framework\Locale\ResolverInterface as LocalResolverInterface;
7+
use Magento\Framework\NumberFormatterFactory;
8+
use Magento\Framework\Serialize\Serializer\Json;
9+
+use Magento\Framework\Exception\LocalizedException;
10+
11+
/**
12+
* Currency model
13+
@@ -39,8 +40,6 @@ class Currency extends \Magento\Framework\Model\AbstractModel
14+
protected $_filter;
15+
16+
/**
17+
- * Currency Rates
18+
- *
19+
* @var array
20+
*/
21+
protected $_rates;
22+
@@ -147,11 +146,14 @@ class Currency extends \Magento\Framework\Model\AbstractModel
23+
$this->_localeCurrency = $localeCurrency;
24+
$this->currencyConfig = $currencyConfig ?: ObjectManager::getInstance()->get(CurrencyConfig::class);
25+
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(LocalResolverInterface::class);
26+
- $this->numberFormatterFactory = $numberFormatterFactory ?: ObjectManager::getInstance()->get(NumberFormatterFactory::class);
27+
+ $this->numberFormatterFactory = $numberFormatterFactory ?:
28+
+ ObjectManager::getInstance()->get(NumberFormatterFactory::class);
29+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
30+
}
31+
32+
/**
33+
+ * Initializing Currency Resource model
34+
+ *
35+
* @return void
36+
*/
37+
protected function _construct()
38+
@@ -253,10 +255,10 @@ class Currency extends \Magento\Framework\Model\AbstractModel
39+
/**
40+
* Convert price to currency format
41+
*
42+
- * @param float $price
43+
- * @param mixed $toCurrency
44+
- * @return float
45+
- * @throws \Exception
46+
+ * @param float $price
47+
+ * @param mixed $toCurrency
48+
+ * @return float
49+
+ * @throws LocalizedException
50+
*/
51+
public function convert($price, $toCurrency = null)
52+
{
53+
@@ -266,7 +268,7 @@ class Currency extends \Magento\Framework\Model\AbstractModel
54+
return (float)$price * (float)$rate;
55+
}
56+
57+
- throw new \Exception(__(
58+
+ throw new LocalizedException(__(
59+
'Undefined rate from "%1-%2".',
60+
$this->getCode(),
61+
$this->getCurrencyCodeFromToCurrency($toCurrency)
62+
@@ -274,7 +276,10 @@ class Currency extends \Magento\Framework\Model\AbstractModel
63+
}
64+
65+
/**
66+
+ * Return the currency code
67+
+ *
68+
* @param mixed $toCurrency
69+
+ *
70+
* @return string
71+
* @throws \Magento\Framework\Exception\InputException
72+
*/
73+
@@ -348,8 +353,11 @@ class Currency extends \Magento\Framework\Model\AbstractModel
74+
}
75+
76+
/**
77+
+ * Return formatted currency
78+
+ *
79+
* @param float $price
80+
* @param array $options
81+
+ *
82+
* @return string
83+
*/
84+
public function formatTxt($price, $options = [])
85+
@@ -420,7 +428,8 @@ class Currency extends \Magento\Framework\Model\AbstractModel
86+
$this->numberFormatter = $this->getNumberFormatter($options);
87+
88+
$formattedCurrency = $this->numberFormatter->formatCurrency(
89+
- $price, $this->getCode() ?? $this->numberFormatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE)
90+
+ $price,
91+
+ $this->getCode() ?? $this->numberFormatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE)
92+
);
93+
94+
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_SYMBOL, $options)) {
95+
@@ -430,7 +439,7 @@ class Currency extends \Magento\Framework\Model\AbstractModel
96+
97+
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
98+
&& $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) {
99+
- $formattedCurrency = str_replace(' ', '', $formattedCurrency);
100+
+ $formattedCurrency = preg_replace(['/[^0-9.,۰٫]+/', '/ /'], '', $formattedCurrency);
101+
}
102+
103+
return preg_replace('/^\s+|\s+$/u', '', $formattedCurrency);
104+
@@ -444,7 +453,10 @@ class Currency extends \Magento\Framework\Model\AbstractModel
105+
*/
106+
private function getNumberFormatter(array $options): \Magento\Framework\NumberFormatter
107+
{
108+
- $key = 'currency_' . md5($this->localeResolver->getLocale() . $this->serializer->serialize($options));
109+
+ $key = 'currency_' . hash(
110+
+ 'sha256',
111+
+ ($this->localeResolver->getLocale() . $this->serializer->serialize($options))
112+
+ );
113+
if (!isset($this->numberFormatterCache[$key])) {
114+
$this->numberFormatter = $this->numberFormatterFactory->create(
115+
['locale' => $this->localeResolver->getLocale(), 'style' => \NumberFormatter::CURRENCY]
116+
@@ -467,7 +479,8 @@ class Currency extends \Magento\Framework\Model\AbstractModel
117+
{
118+
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_SYMBOL, $options)) {
119+
$this->numberFormatter->setSymbol(
120+
- \NumberFormatter::CURRENCY_SYMBOL, $options[LocaleCurrency::CURRENCY_OPTION_SYMBOL]
121+
+ \NumberFormatter::CURRENCY_SYMBOL,
122+
+ $options[LocaleCurrency::CURRENCY_OPTION_SYMBOL]
123+
);
124+
}
125+
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
126+
@@ -490,6 +503,8 @@ class Currency extends \Magento\Framework\Model\AbstractModel
127+
}
128+
129+
/**
130+
+ * Return the price format to be displayed to user
131+
+ *
132+
* @return string
133+
*/
134+
public function getOutputFormat()
135+
@@ -532,6 +547,8 @@ class Currency extends \Magento\Framework\Model\AbstractModel
136+
}
137+
138+
/**
139+
+ * Retrieve base config currency data by config path.
140+
+ *
141+
* @return array
142+
*/
143+
public function getConfigBaseCurrencies()

src/Test/Functional/Acceptance/Acceptance73Cest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ protected function patchesDataProvider(): array
2929
['templateVersion' => '2.3.6', 'magentoVersion' => '2.3.6-p1'],
3030
['templateVersion' => '2.3.7', 'magentoVersion' => '2.3.7'],
3131
['templateVersion' => '2.3.7', 'magentoVersion' => '2.3.7-p1'],
32+
['templateVersion' => '2.3.7', 'magentoVersion' => '2.3.7-p2'],
3233
['templateVersion' => '2.4.0', 'magentoVersion' => '2.4.0'],
3334
];
3435
}

src/Test/Functional/Acceptance/AcceptanceCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected function patchesDataProvider(): array
5757
['templateVersion' => '2.4.2', 'magentoVersion' => '2.4.2-p1'],
5858
['templateVersion' => '2.4.2', 'magentoVersion' => '2.4.2-p2'],
5959
['templateVersion' => '2.4.3', 'magentoVersion' => '2.4.3'],
60+
['templateVersion' => '2.4.3', 'magentoVersion' => '2.4.3-p1'],
6061
['templateVersion' => 'master'],
6162
];
6263
}

0 commit comments

Comments
 (0)