1212use Magento \Framework \Locale \Currency as LocaleCurrency ;
1313use Magento \Framework \Locale \ResolverInterface as LocalResolverInterface ;
1414use Magento \Framework \NumberFormatterFactory ;
15+ use Magento \Framework \Serialize \Serializer \Json ;
1516
1617/**
1718 * Currency model
@@ -94,6 +95,11 @@ class Currency extends \Magento\Framework\Model\AbstractModel
9495 */
9596 private $ numberFormatterCache ;
9697
98+ /**
99+ * @var Json
100+ */
101+ private $ serializer ;
102+
97103 /**
98104 * @param \Magento\Framework\Model\Context $context
99105 * @param \Magento\Framework\Registry $registry
@@ -108,6 +114,7 @@ class Currency extends \Magento\Framework\Model\AbstractModel
108114 * @param CurrencyConfig|null $currencyConfig
109115 * @param LocalResolverInterface|null $localeResolver
110116 * @param NumberFormatterFactory|null $numberFormatterFactory
117+ * @param Json|null $serializer
111118 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
112119 */
113120 public function __construct (
@@ -123,7 +130,8 @@ public function __construct(
123130 array $ data = [],
124131 CurrencyConfig $ currencyConfig = null ,
125132 LocalResolverInterface $ localeResolver = null ,
126- \Magento \Framework \NumberFormatterFactory $ numberFormatterFactory = null
133+ \Magento \Framework \NumberFormatterFactory $ numberFormatterFactory = null ,
134+ Json $ serializer = null
127135 ) {
128136 parent ::__construct (
129137 $ context ,
@@ -140,6 +148,7 @@ public function __construct(
140148 $ this ->currencyConfig = $ currencyConfig ?: ObjectManager::getInstance ()->get (CurrencyConfig::class);
141149 $ this ->localeResolver = $ localeResolver ?: ObjectManager::getInstance ()->get (LocalResolverInterface::class);
142150 $ this ->numberFormatterFactory = $ numberFormatterFactory ?: ObjectManager::getInstance ()->get (NumberFormatterFactory::class);
151+ $ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
143152 }
144153
145154 /**
@@ -356,7 +365,7 @@ public function formatTxt($price, $options = [])
356365 */
357366 $ price = sprintf ("%F " , $ price );
358367
359- if ($ this ->useNumberFormatter ($ options )) {
368+ if ($ this ->canUseNumberFormatter ($ options )) {
360369 return $ this ->formatCurrency ($ price , $ options );
361370 }
362371
@@ -369,7 +378,7 @@ public function formatTxt($price, $options = [])
369378 * @param array $options
370379 * @return bool
371380 */
372- private function useNumberFormatter (array $ options ): bool
381+ private function canUseNumberFormatter (array $ options ): bool
373382 {
374383 $ allowedOptions = [
375384 'precision ' ,
@@ -435,7 +444,7 @@ private function formatCurrency(string $price, array $options): string
435444 */
436445 private function getNumberFormatter (array $ options ): \Magento \Framework \NumberFormatter
437446 {
438- $ key = 'currency_ ' . md5 ($ this ->localeResolver ->getLocale () . serialize ($ options ));
447+ $ key = 'currency_ ' . md5 ($ this ->localeResolver ->getLocale () . $ this -> serializer -> serialize ($ options ));
439448 if (!isset ($ this ->numberFormatterCache [$ key ])) {
440449 $ this ->numberFormatter = $ this ->numberFormatterFactory ->create (
441450 ['locale ' => $ this ->localeResolver ->getLocale (), 'style ' => \NumberFormatter::CURRENCY ]
0 commit comments