I want to get tax rate (percentage) on product-view page. Following code only shows text of tax:
$currentProduct->getAttributeText('tax_class_id')
Thanks for help! martn
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI achieved getting tax rates by using \Magento\Tax\Api\TaxCalculationInterface:
$rate = $this->taxCalculation
->getCalculatedRate($productTaxClassId, $customerId, $storeId);
You can get tax rate by:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$taxCalculation = $objectManager->create( 'Magento\Tax\Model\Calculation\Rate' )->load( <tax_rate_id> , 'tax_calculation_rate_id' );
$rate = $taxCalculation->getRate();
where <tax_rate_id>
get from Tax Zones and Rates admin screen /tax/rate/ , or you can get it programmatically with TaxRuleModel
We can get rate object by instantiating 'Magento\Tax\Model\Calculation\Rate' class and calling loadByCode() method on the instance. The tax_code needs to be passed as a parameter of the method.