How to get tax rate for particular country in magento?
-
16-10-2019 - |
Question
In my code i get the current country of the user from that current country I want to get tax rate. So that I can apply that tax rate accordingly to current company. Can anyone help please?
Solution
The following code will:
- Load a customer address and get the country id e.g. "US" or "DE"
- Load a collection of all tax rates for that given country
Note that $customer_id should be a relevant customer id and you could use the current logged in customer. Also note that getDefaultBillingAddress is not always set for a customer.
$oCustomer = Mage::getModel('customer/customer')->load($customer_id);
$oAddress = $oCustomer->getDefaultBillingAddress();
/* @var $oTaxRateCollection Mage_Tax_Model_Resource_Calculation_Rate_Collection */
$oTaxRateCollection = Mage::getResourceModel('tax/calculation_rate_collection');
$oTaxRateCollection->addFieldToFilter('tax_country_id', $oAddress->getCountryId());
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange