@@ -32,24 +32,6 @@ public function __construct(
3232 ) {
3333 }
3434
35- /**
36- * Format price using the store's price format
37- *
38- * @param float $amount
39- * @param array $priceFormat
40- * @return string
41- */
42- private function formatPrice (float $ amount , array $ priceFormat ): string
43- {
44- $ pattern = $ priceFormat ['pattern ' ] ?? '%s ' ;
45- $ precision = $ priceFormat ['precision ' ] ?? 2 ;
46- $ decimalSymbol = $ priceFormat ['decimalSymbol ' ] ?? '. ' ;
47- $ groupSymbol = $ priceFormat ['groupSymbol ' ] ?? ', ' ;
48-
49- $ formatted = number_format ($ amount , $ precision , $ decimalSymbol , $ groupSymbol );
50- return str_replace ('%s ' , $ formatted , $ pattern );
51- }
52-
5335 /**
5436 * Add FPT data to option prices
5537 *
@@ -104,7 +86,6 @@ private function shouldProcessWeee(?array $config): bool
10486 private function addWeeeDataToProduct (array &$ config , string $ productId , $ product ): void
10587 {
10688 $ weeeAttributes = $ this ->weeeHelper ->getProductWeeeAttributesForDisplay ($ product );
107- $ config ['optionPrices ' ][$ productId ]['weeeAttributes ' ] = [];
10889
10990 if (empty ($ weeeAttributes )) {
11091 return ;
@@ -156,8 +137,8 @@ private function processWeeeAttributes(array $weeeAttributes): array
156137 */
157138 private function addFormattedWeeeData (array &$ config , string $ productId , array $ weeeData ): void
158139 {
159- $ config ['optionPrices ' ][$ productId ]['weeeAttributes ' ] = $ weeeData [ ' attributes ' ];
160- $ basePriceAmount = $ config [ ' optionPrices ' ][ $ productId ][ ' finalPrice ' ][ ' amount ' ] - $ weeeData ['total ' ];
140+ $ finalPriceAmount = $ config ['optionPrices ' ][$ productId ]['finalPrice ' ][ ' amount ' ];
141+ $ basePriceAmount = $ finalPriceAmount - $ weeeData ['total ' ];
161142
162143 $ formattedWeeeAttributes = [];
163144 foreach ($ weeeData ['attributes ' ] as $ weeeAttr ) {
@@ -174,9 +155,24 @@ private function addFormattedWeeeData(array &$config, string $productId, array $
174155 $ config ['optionPrices ' ][$ productId ]['finalPrice ' ]['formattedWithoutWeee ' ] =
175156 $ this ->formatPrice ($ basePriceAmount , $ config ['priceFormat ' ]);
176157 $ config ['optionPrices ' ][$ productId ]['finalPrice ' ]['formattedWithWeee ' ] =
177- $ this ->formatPrice (
178- $ config ['optionPrices ' ][$ productId ]['finalPrice ' ]['amount ' ],
179- $ config ['priceFormat ' ]
180- );
158+ $ this ->formatPrice ($ finalPriceAmount , $ config ['priceFormat ' ]);
159+ }
160+
161+ /**
162+ * Format price using the store's price format
163+ *
164+ * @param float $amount
165+ * @param array $priceFormat
166+ * @return string
167+ */
168+ private function formatPrice (float $ amount , array $ priceFormat ): string
169+ {
170+ $ pattern = $ priceFormat ['pattern ' ] ?? '%s ' ;
171+ $ precision = $ priceFormat ['precision ' ] ?? 2 ;
172+ $ decimalSymbol = $ priceFormat ['decimalSymbol ' ] ?? '. ' ;
173+ $ groupSymbol = $ priceFormat ['groupSymbol ' ] ?? ', ' ;
174+
175+ $ formatted = number_format ($ amount , $ precision , $ decimalSymbol , $ groupSymbol );
176+ return str_replace ('%s ' , $ formatted , $ pattern );
181177 }
182178}
0 commit comments