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?
Asked
Active
Viewed 2,859 times
1 Answers
6
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());
David Manners
- 27,241
- 9
- 76
- 220