I'm trying to get 'tax_calculation_rate_id' by iterating through ordered products.
The following code works ok, but the problem arises when there are multiple ids assigned to the same percentage values (e.g. "VAT exempt rate" at 0% and "EC Sales rate" at 0%)
Is there a better way to get the rate ids calculated?
Thank you for your help!
// $line_item and $address come as arguments
$store = Mage::app()->getStore();
$product_class= Mage::getModel('catalog/product')
->loadByAttribute('sku',$line_item->getSku())
->getTaxClassId();
$tax_model = Mage::getSingleton('tax/calculation');
$request = $tax_model->getRateRequest($address, null, null, $store);
$percent = $tax_model->getRate($request->setProductClassId($product_class));
$rates = Mage::getModel("tax/calculation_rate")
->getCollection()
->addFieldToFilter('rate', array('eq'=>$percent));
foreach ($rates as $rate)
{
$mage_rate_id = $rate->getTaxCalculationRateId();
// if more than 1 rate exits it obviously picks the last one
}