I am trying to convert below code in magento2. I'm unable to find equivalent class of Mage::getModel('tax/calculation') in Magento2.

$taxCalculation = Mage::getModel('tax/calculation');
$request = $taxCalculation->getRateRequest(null, null, null, $store);
$taxClassId = $_product->getTaxClassId();
$percent = $taxCalculation->getRate($request->setProductClassId($taxClassId));

Help appreciated.


in your block file

protected  $calculation;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Tax\Model\Calculation $calculation,
) {
 $this->calculation = $calculation;

public function yourmethod()
  $taxCalculation = $this->calculation;
  $request        = $taxCalculation->getRateRequest(null, null, null, $store);
  $taxClassId     = $_product->getTaxClassId();
  $percent        = $taxCalculation->getRate($request->setProductClassId($taxClassId));

Magento 2 has a separate module for tax calculations module-tax. There you can find the equivalent of the Mage_Tax_Model_Calculation class.


namespace Magento\Tax\Model;

class Calculation extends \Magento\Framework\Model\AbstractModel

This class also contains the methods getRateRequest() and getRate().


If you are using an block you can create a protected variable:


protected $_taxCalculation;


And declaret model on construct:

public function __construct( ...
    \Magento\Tax\Model\TaxCalculation $taxCalculation
   $this->_taxCalculation = $taxCalculation;


Now you can use functions of TaxCalculation model from: /vendor/magento/module-tax/Model/TaxCalculation.php

For example:

public function myFunction(){
   return $this->_taxCalculation->getRate(1);
$taxCalculation = Mage::getModel('tax/calculation');

equivalent class in Magento 2 Please inject Magento\Tax\Model\TaxCalculation $taxCalculation

getRateRequest,getRate his method is in (Magento\Tax\Model\TaxCalculation) model

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.