Question

Hi Currently I am getting tax class name as follows

$_product = $item->getProduct()
$taxClassId = $_product->getTaxClassId();
$taxClass = Mage::getModel('tax/class')->load($taxClassId);

Which is fine if it is not called in for loop. But my problem is that I am doing that in a for loop. Which is very expensive. I have a invoice collection and calling the above code block for each invoice.

What I want to be able to do is have a query that will fetch all the SKUS and its corresponding tax class names. Which I will load before the for loop and when I need it I will call it from array.

**SKU      Tax_Class_Name**
SKU_001  Taxable Goods
SKU_002  Taxable Goods
SKU_SHIP SHIPPING

I am not able to establish the correct tables so I can fire the query. catalog_product_entity and tax_class table will be needed but cannot find connection between the two.

Was it helpful?

Solution

I found answer to my question. It is not exactly what I wanted to but my way would have been wrong anyways. Since Tax class is assigned based on combination of Product and Website. Hence the following query.

SELECT pe.sku, pi.website_id, t.class_name 
FROM magento1ee.catalog_product_entity as pe 
LEFT JOIN  magento1ee.catalog_product_index_price as pi on pe.entity_id = pi.entity_id
LEFT JOIN magento1ee.tax_class as t on pi.tax_class_id = t.class_id
group by pi.entity_id, pi.website_id, pi.tax_class_id;
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top