6

I have a problem with Magento 2, I have configured a tax class and settings for including it in catalog and entered price in admin. Still when I get priceinfo I get this price:

For a product of price 119:

$prices = $product->getPriceInfo()->getPrices();
var_dump($prices->current()->getAmount());

Outputs:

object(Magento\Framework\Pricing\Amount\Base)[2082]
   protected 'amount' => float 148.75
   protected 'baseAmount' => null
   protected 'totalAdjustmentAmount' => null
   protected 'adjustmentAmounts' => 
     array (size=1)
       'tax' => float 29.750001
   protected 'adjustments' => 
     array (size=0)
       empty

Why is magento adding the tax on top of 119 despite my settings?

I have done some further research in this, it seems magento2 has a problem counting taxes backwards?

When running \Magento\Catalog\Helper\Data function getTaxPrice I set price at 119 to include tax and to return price without tax:

https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Helper/Data.php#L515

Should not this function return 119 * 0.8 = 95.2 in this case? As my tax is 25% and backwards tax that is 20%.

I run the function as this:

$catalogHelper->getTaxPrice($product, $product->getPrice(), false, null,null,null,null,true,true)

It returns 119 to me which seems weird.

1
  • Thank you! I looked for the answer, but have found only your question and it was helpful :) Sep 15, 2016 at 10:02

2 Answers 2

5

My solution for base prices incl. vat is

$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();

For special price it will be

$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue();
2
  • This works for simples, but configurables still show me the price excl. Dec 12, 2016 at 14:15
  • Hi, can you please let me know the admin settings to display including tax product price in custom module? Because I can't get incl. tax price for simple products using your solution. It would be great to help me. Feb 22, 2019 at 10:20
1

So i had missed the setting for the store location which messed it up. facepalm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.