0

I've custom block phtml in my old store and I need to be converted to Magento 2.

Magento 1.9.x code:

$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);
$unitPrice = Mage::helper('core')->currency(round($_finalPriceInclTax / $_product->getHedNetWeight(), 2),true,false);

How can I get Final Price included Tax in Magento 2 and how can I use Mage::helper('core')->currency(round) in Magento 2?

I try to display the price like this:

$this->helper('Magento\Framework\Pricing\Helper\Data')->currency($finalprice / $HedNetWeight,true,false);

Thank you

3

In Block :-

protected $taxHelper;

public function __construct(\Magento\Catalog\Helper\Data $taxHelper,
    \Magento\Framework\Pricing\PriceCurrencyInterface 
){
    $this->taxHelper = $taxHelper;
    $this->priceCurrency = $priceCurrency;
}

public function finalPrice($product) {
    return $this->taxHelper->getTaxPrice($product, $product->getFinalPrice(), true);
}

public function currency($value, $format = true, $includeContainer = true)
{
    return $format
    ? $this->priceCurrency->convertAndFormat($value, $includeContainer)
    : $this->priceCurrency->convert($value);
}

In phtml :-

$block->currency($block->finalPrice(),true,false);
  • Hi thank you for your answer, but if you read again I need this to be just a simple code in phtml file – Robert Mar 4 at 10:38
  • check my updated answer – Rk Rathod Mar 4 at 10:51
0

A couple of extensions allows to change or delete the decimal number for the front store.

https://github.com/lillik/magento2-price-decimal

https://github.com/karliuka/m2.Price

  • Hi thank you, but I don't need a global solution, I need to remove the decimal numbers only in my code – Robert Mar 4 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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