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.

4 Answers 4


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));
  • hi,@Muruza, i need to set custom tax price for product, how that can be achieved in magneto2? May 14, 2019 at 10:33
  • @jafarpinjar what do you mean by customTaxPrice can you please explain May 16, 2019 at 2:55
  • I need to set fixed tax amount for the quote item, how that can be achieved? Here is my complete question, magento.stackexchange.com/questions/274520/… May 16, 2019 at 3:47
  • hi @Murtuza, are you cleared now? May 16, 2019 at 6:01

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 and acknowledge you have read our privacy policy.

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