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?

Was it helpful?

Solution

The following code will:

  1. Load a customer address and get the country id e.g. "US" or "DE"
  2. 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
scroll top