88namespace Magento \Checkout \Model \Cart ;
99
1010use Magento \Framework \Locale \ResolverInterface ;
11+ use NumberFormatter ;
1112
1213/**
1314 * Cart request quantity processor
@@ -37,13 +38,11 @@ public function __construct(
3738 */
3839 public function process (array $ cartData ): array
3940 {
40- $ filter = new \Laminas \I18n \Filter \NumberParse ($ this ->localeResolver ->getLocale ());
41-
4241 foreach ($ cartData as $ index => $ data ) {
4342 if (isset ($ data ['qty ' ])) {
4443 $ data ['qty ' ] = $ this ->prepareQuantity ($ data ['qty ' ]);
4544 $ data ['qty ' ] = is_string ($ data ['qty ' ]) ? trim ($ data ['qty ' ]) : $ data ['qty ' ];
46- $ cartData [$ index ]['qty ' ] = $ filter ->filter ($ data ['qty ' ]);
45+ $ cartData [$ index ]['qty ' ] = $ this ->filter ($ data ['qty ' ]);
4746 }
4847 }
4948
@@ -55,12 +54,11 @@ public function process(array $cartData): array
5554 *
5655 * @param int|float|string|array $quantity
5756 * @return int|float|string|array
58- * @throws \Zend_Locale_Exception
5957 */
6058 public function prepareQuantity ($ quantity )
6159 {
62- $ formatter = new \ NumberFormatter ($ this ->localeResolver ->getLocale (), \ NumberFormatter::CURRENCY );
63- $ decimalSymbol = $ formatter ->getSymbol (\ NumberFormatter::DECIMAL_SEPARATOR_SYMBOL );
60+ $ formatter = new NumberFormatter ($ this ->localeResolver ->getLocale (), NumberFormatter::CURRENCY );
61+ $ decimalSymbol = $ formatter ->getSymbol (NumberFormatter::DECIMAL_SEPARATOR_SYMBOL );
6462
6563 if (is_array ($ quantity )) {
6664 foreach ($ quantity as $ key => $ qty ) {
@@ -70,8 +68,47 @@ public function prepareQuantity($quantity)
7068 }
7169 } else {
7270 if (strpos ((string )$ quantity , '. ' ) !== false && $ decimalSymbol !== '. ' ) {
73- $ quantity = str_replace ('. ' , $ decimalSymbol , (string )$ quantity );
71+ $ quantity = str_replace ('. ' , $ decimalSymbol , (string ) $ quantity );
72+ }
73+ }
74+
75+ return $ quantity ;
76+ }
77+
78+ /**
79+ * Filter quantity value and parse it by region if needed.
80+ *
81+ * @param float|int|array|string $quantity
82+ *
83+ * @return float|int|array|string
84+ */
85+ private function filter ($ quantity )
86+ {
87+ $ formatter = new NumberFormatter ($ this ->localeResolver ->getLocale (), NumberFormatter::DEFAULT_STYLE );
88+
89+ if (is_array ($ quantity )) {
90+ foreach ($ quantity as $ key => $ qty ) {
91+ $ quantity [$ key ] = $ this ->parseFormat ($ qty , $ formatter );
7492 }
93+ } else {
94+ $ quantity = $ this ->parseFormat ($ quantity , $ formatter );
95+ }
96+
97+ return $ quantity ;
98+ }
99+
100+ /**
101+ * Phrase quantity value if needed.
102+ *
103+ * @param float|int|string $quantity
104+ * @param NumberFormatter $formatter
105+ *
106+ * @return float|int|string
107+ */
108+ private function parseFormat ($ quantity , NumberFormatter $ formatter )
109+ {
110+ if (!is_float ($ quantity ) && !is_int ($ quantity )) {
111+ return $ formatter ->parse ($ quantity );
75112 }
76113
77114 return $ quantity ;
0 commit comments