1

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?

Marius
  • 197,939
  • 53
  • 422
  • 830
saniya
  • 79
  • 2
  • 8

1 Answers1

6

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());
David Manners
  • 27,241
  • 9
  • 76
  • 220