Skip to content

Commit eca0128

Browse files
committed
AC-13171: Fixed Product Tax (FPT) is not displaying separately with configurable products
Removed unwanted assignments and calculations and refactored code
1 parent 6a76019 commit eca0128

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

app/code/Magento/Weee/Plugin/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/code/Magento/Weee/view/frontend/web/js/price-box-mixin.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,18 @@ define([
128128
*/
129129
_getWeeeData: function(productId) {
130130
var swatchWidget = this._getSwatchWidget(),
131-
configurableWidget,
131+
configurableWidget = this._getConfigurableWidget(),
132+
jsonConfig = (swatchWidget && swatchWidget.options.jsonConfig) ||
133+
(configurableWidget && configurableWidget.options.spConfig),
132134
optionPrices;
133135

134-
if (swatchWidget && swatchWidget.options.jsonConfig) {
135-
optionPrices = swatchWidget.options.jsonConfig.optionPrices;
136-
if (optionPrices && optionPrices[productId] && optionPrices[productId].finalPrice) {
137-
return optionPrices[productId].finalPrice;
138-
}
136+
if (!jsonConfig) {
137+
return null;
139138
}
140139

141-
configurableWidget = this._getConfigurableWidget();
142-
if (configurableWidget && configurableWidget.options.spConfig) {
143-
optionPrices = configurableWidget.options.spConfig.optionPrices;
144-
if (optionPrices && optionPrices[productId] && optionPrices[productId].finalPrice) {
145-
return optionPrices[productId].finalPrice;
146-
}
140+
optionPrices = jsonConfig.optionPrices;
141+
if (optionPrices && optionPrices[productId] && optionPrices[productId].finalPrice) {
142+
return optionPrices[productId].finalPrice;
147143
}
148144

149145
return null;

0 commit comments

Comments
 (0)