[2.4.9] Configurable products show the price excluding tax when catalog prices include tax and FPT is enabled
Preconditions and environment
- Magento 2.4.9 (regression, 2.4.8-p5 is not affected)
- Introduced by the fix for #40171 (AC-15718, commits 53071704a8 and 2789a517b4)
- Tax configuration:
- Catalog Prices: Including Tax (
tax/calculation/price_includes_tax = 1) - Display Product Prices In Catalog: Including Tax (
tax/display/type = 2) - Fixed Product Taxes enabled (
tax/weee/enable = 1) - Display Prices In Product Lists / On Product View Page: Including FPT or Including FPT and FPT description (the default,
tax/weee/display = 1)
- Catalog Prices: Including Tax (
- A tax rule for the default destination country, e.g. 20% VAT
Steps to reproduce
- Apply the tax configuration above.
- Create a configurable product with one simple child priced 120.00 (entered including 20% VAT). The child does not need an FPT attribute value; enabling FPT is enough.
- Open the category page and the product page of the configurable product, with no option selected.
Expected result
The configurable product shows 120.00, the child price including tax, as on 2.4.8-p5.
Actual result
The configurable product shows 100.00, the price excluding tax, on the category page and on the product page, while the tax label still says the price includes tax.
On our store: a child at 1,668.99 € incl. VAT is shown as 1,390.83 € on the parent. Every configurable product is affected. The price becomes correct only after a swatch or option is selected, because the child price box is used then.
Additional information
Cause: Magento\Weee\Plugin\ConfigurableProduct\Pricing\FinalPriceResolver::afterResolvePrice().
The fix for #40171 changed the FPT branch from getAmount()->getValue() to getAmount()->getValue(Adjustment::ADJUSTMENT_CODE), i.e. the child amount without the tax adjustment. The configurable parent then treats the resolved value as a catalog price and runs its own adjustments on it.
- With Catalog Prices Excluding Tax (the #40171 case), the parent adds the tax once. Correct.
- With Catalog Prices Including Tax, the parent reads the value as an incl.-tax catalog price, so no tax is added back. The excl.-tax value is displayed as the incl.-tax price.
So the plugin has to follow the Catalog Prices setting. A fix that keeps #40171 fixed and restores the 2.4.8 behaviour for incl.-tax catalogs:
public function afterResolvePrice(
ConfigurableProductFinalPriceResolver $subject,
float $result,
SaleableInterface $product
): float {
if (!$this->weeePriceDisplay()) {
return (float)$product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getValue();
}
$amount = $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getAmount();
// Catalog prices entered with tax: keep the tax (2.4.8 behaviour).
// Catalog prices entered without tax: leave the tax adjustment out (#40171).
return $this->taxHelper->priceIncludesTax($product->getStoreId())
? (float)$amount->getValue()
: (float)$amount->getValue(Adjustment::ADJUSTMENT_CODE);
}($this->taxHelper is Magento\Tax\Helper\Data, injected as an optional constructor argument.)
We run this as a local composer patch on 2.4.9. With it, 16 product pages and 180 category-page prices match 2.4.8-p5 exactly, including configurables with an FPT value.
The unit test added in 2789a517b4 (FinalPriceResolverTest) does not cover priceIncludesTax = true, which is why this was not caught.
Release note
Configurable products show the price including tax again when catalog prices are entered including tax and Fixed Product Tax is enabled.
Triage and priority
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
Source: magento/magento2