magento / meta-for-magento2

33 stars 19 forks source link

Wrong logic exporting product prices with tax excluded #43

Open stephansteiner opened 7 months ago

stephansteiner commented 7 months ago

When exporting products in the feed that are set to excluding tax in the Magento admin panel, prices are exported without tax instead of with tax added. Feed builder logic in app/code/Meta/Catalog/Model/Product/Tools is wrong:

$price = $this->systemConfig->isPriceInclTax()
             ? $this->catalogHelper->getTaxPrice($product, $product->getPrice(), true)
             : $product->getPrice();

If prices in Magento are set to "Catalog Prices" = "Excluding Tax" (Store > Configuration > Sales > Tax > Calculation Settings), the function call to $this->systemConfig->isPriceInclTax() will return false and the product price is exported as is. Instead, it should return the price with taxed added.

The correct logic should be:

$price = $this->systemConfig->isPriceInclTax()
             ? $product->getPrice()
             : $this->catalogHelper->getTaxPrice($product, $product->getPrice(), true);

Found in functions getProductPrice() and getProductSalePrice().

Preconditions (*)

1. 2.

Steps to reproduce (*)

Expected result (*)

  1. [Screenshots, logs or description]

Actual result (*)

  1. [Screenshots, logs or description]
stephansteiner commented 7 months ago

Furthermore, the function $this->systemConfig->isPriceInclTax() is a checking for a custom setting with key facebook_business_extension/catalog_management/price_incl_tax that is not visible in the Magento admin panel, because showInDefaults, showInWebsite and showInStore are all set to 0.

<field id="price_incl_tax" translate="label comment" type="select" sortOrder="50" showInDefault="0" showInWebsite="0" showInStore="0">
                    <label>Price Including Tax</label>
                    .....
</field>

Setting is not visible in Magento admin panel: Bildschirmfoto 2023-11-14 um 06 53 11

Bashev commented 7 months ago

As workaround you can use: php bin/magento config:set price_incl_tax 0

A lot of settings are hidden for some reason, probably after migration of the plugin from facebook to meta.

stephansteiner commented 7 months ago

The setting is already set to 0. The function isPriceInclTax returns a false value, the order of instructions is messed up. If prices are set including taxes, then return as they are otherwise call getTaxPrice, right now it’s the other way around