1

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.

0

1 Answer 1

2

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.