Skip to content

Conversation

ericclaeren
Copy link

Fixed price value, I would think, it always should be the final price, product type shouldn't matter. Final price incorporates tax/discount/special price and matches the displayed value on the product page.

In the current logic $price is always set, so the logic of simple/configurable is never called.
Thought about removing the getProductPrice method, but this could be an issue for people using this method in custom extensions.

Explanation:

$price = $product
                ->getPriceInfo()
                ->getPrice(FinalPrice::PRICE_CODE)
                ->getAmount()

Returns an AmountInterface object.

->getBaseAmount()

getBaseAmount() fetches the amount without tax calculations, for the the final price amount it seems you should call:

->getValue()

Which is equal to getFinalPrice(), so don't see much value for all the logic and just call ->getFinalPrice() on the product, and let the product decide what the correct route is for fetching the correct amount.

Tested on Magento 2.4.3 and 2.3.5-p1 with 2.7.0.

  • Checked configurable product
  • Checked simple product
  • Checked simple product with discount (catalog rule)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant