|
| 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() |
0 commit comments