12
12
use Magento \Framework \Locale \Currency as LocaleCurrency ;
13
13
use Magento \Framework \Locale \ResolverInterface as LocalResolverInterface ;
14
14
use Magento \Framework \NumberFormatterFactory ;
15
+ use Magento \Framework \Serialize \Serializer \Json ;
15
16
16
17
/**
17
18
* Currency model
@@ -94,6 +95,11 @@ class Currency extends \Magento\Framework\Model\AbstractModel
94
95
*/
95
96
private $ numberFormatterCache ;
96
97
98
+ /**
99
+ * @var Json
100
+ */
101
+ private $ serializer ;
102
+
97
103
/**
98
104
* @param \Magento\Framework\Model\Context $context
99
105
* @param \Magento\Framework\Registry $registry
@@ -108,6 +114,7 @@ class Currency extends \Magento\Framework\Model\AbstractModel
108
114
* @param CurrencyConfig|null $currencyConfig
109
115
* @param LocalResolverInterface|null $localeResolver
110
116
* @param NumberFormatterFactory|null $numberFormatterFactory
117
+ * @param Json|null $serializer
111
118
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
112
119
*/
113
120
public function __construct (
@@ -123,7 +130,8 @@ public function __construct(
123
130
array $ data = [],
124
131
CurrencyConfig $ currencyConfig = null ,
125
132
LocalResolverInterface $ localeResolver = null ,
126
- \Magento \Framework \NumberFormatterFactory $ numberFormatterFactory = null
133
+ \Magento \Framework \NumberFormatterFactory $ numberFormatterFactory = null ,
134
+ Json $ serializer = null
127
135
) {
128
136
parent ::__construct (
129
137
$ context ,
@@ -140,6 +148,7 @@ public function __construct(
140
148
$ this ->currencyConfig = $ currencyConfig ?: ObjectManager::getInstance ()->get (CurrencyConfig::class);
141
149
$ this ->localeResolver = $ localeResolver ?: ObjectManager::getInstance ()->get (LocalResolverInterface::class);
142
150
$ this ->numberFormatterFactory = $ numberFormatterFactory ?: ObjectManager::getInstance ()->get (NumberFormatterFactory::class);
151
+ $ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
143
152
}
144
153
145
154
/**
@@ -356,7 +365,7 @@ public function formatTxt($price, $options = [])
356
365
*/
357
366
$ price = sprintf ("%F " , $ price );
358
367
359
- if ($ this ->useNumberFormatter ($ options )) {
368
+ if ($ this ->canUseNumberFormatter ($ options )) {
360
369
return $ this ->formatCurrency ($ price , $ options );
361
370
}
362
371
@@ -369,7 +378,7 @@ public function formatTxt($price, $options = [])
369
378
* @param array $options
370
379
* @return bool
371
380
*/
372
- private function useNumberFormatter (array $ options ): bool
381
+ private function canUseNumberFormatter (array $ options ): bool
373
382
{
374
383
$ allowedOptions = [
375
384
'precision ' ,
@@ -435,7 +444,7 @@ private function formatCurrency(string $price, array $options): string
435
444
*/
436
445
private function getNumberFormatter (array $ options ): \Magento \Framework \NumberFormatter
437
446
{
438
- $ key = 'currency_ ' . md5 ($ this ->localeResolver ->getLocale () . serialize ($ options ));
447
+ $ key = 'currency_ ' . md5 ($ this ->localeResolver ->getLocale () . $ this -> serializer -> serialize ($ options ));
439
448
if (!isset ($ this ->numberFormatterCache [$ key ])) {
440
449
$ this ->numberFormatter = $ this ->numberFormatterFactory ->create (
441
450
['locale ' => $ this ->localeResolver ->getLocale (), 'style ' => \NumberFormatter::CURRENCY ]
0 commit comments