1

How do I get Netto(without tax) and Brutto(with tax) prices in magento2 inside the custom block?

I try to show the 2 prices.

1 Answer 1

2

To display/show product price including tax amount, you need to do some configuration settings.

1. Create Tax Rule

You need to create tax rules (Sales -> Tax -> Manage Tax Rules). For this, you can refer to different tutorials available over the internet on creating Tax rules.

2. Assign Tax Rule to Product

Then, you need to assign the Tax rule to the product.

– Edit product (Catalog -> Manage Products) – Go to ‘Prices’ tab – Select your Tax rule from the ‘Tax Class’ select box – Save the product

3. Configuration Settings to show Product Price including Tax

Now, go to configuration settings (System -> Configuration -> SALES -> Tax -> Price Display Settings -> Display Product Prices in Catalog).

You have three options there. To show product price:

a) Excluding Tax b) Including Tax c) Including and Excluding Tax

That’s all. Now, you should be able to see the frontend product price as per your configuration setting.

Programmatically

I believe that you are referring to Magento/Catalog/view/frontend/templates/product/list.phtml You could use something like

    $_product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount()

This gets you the price with no tax into store currency

this code should work for all product types with tax::

    $_product->getPriceInfo()->getPrice('final_price')->getAmount()->getAmount()

is the price including tax (that adds Weee FPT price as well if you use that) You can look at the format of $_product->getPriceInfo()->getPrice('final_price')->getAmount() it has all your needed information there like discounts, adjustments, tax values if more.. etc..

Update

Code Example

echo "<pre>";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_id = 15;
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
// get excluding price
$priceData = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount();
//print_r($priceData);

echo "Excluding Price : " . $priceData . "<br/>";
// get including price
$priceData = $product->getPriceInfo()->getPrice('final_price')->getAmount();
echo "Including Price : " . $priceData . "<br/>";

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.