get all tax rates in Magento 2 store
-
14-04-2021 - |
質問
I'm trying to get all tax rates I set up in my store my custom plugin, I'm using Magento 2.
I found that in db all tax rates are stored in tax_calculation_rate, but I didn't find a method to get all data from this.
Thank you for any help
解決
By using the \Magento\Tax\Model\Calculation\Rate
you can get a list of all the Tax Rates.
$getAllTaxRates = $this->taxRatesModel->getCollection()->getData();
foreach ($getAllTaxRates as $tax) {
$taxid = $tax['tax_calculation_rate_id'];
$taxCode = $tax["code"];
$taxRate = $tax["rate"];
}
where taxRatesModel
is an object of Magento\Tax\Model\Calculation\Rate class.
I hope this helps!
所属していません magento.stackexchange