Updating tax classes for products in specific categories in Magento (For Tax Free Weekends)

With tax free season coming around, majority of my Magento clients requested that products set to specific categories be made tax free.

Magento sets the tax_class_id attribute on the product level, which would require me doing a batch update of the products, however I can’t set a filter to specific categories which puts me back to square one.

Below is a simple SQL query that will update all products to a Tax Class of None, based on a set of category ids I define.

WARNING: Always do a complete database backup before running SQL queries against your database

UPDATE catalog_product_entity_int cpei
SET cpei.value = 0
WHERE cpei.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'tax_class_id')
AND cpei.value = 2
AND cpei.entity_id IN (
    SELECT product_id AS entity_id FROM catalog_category_product
    WHERE category_id IN (1,2,3,4,5,6,7,8,9)

Be sure to replace this section

WHERE category_id IN (1,2,3,4,5,6,7,8,9)
to include the comma separate list of category_id values you wish to apply this to.

You can also change the tax_class_id you set these products to by modifying this line:

SET cpei.value = 0
. Change the 0 to the value of the tax_class_id you wish to set it to.

After applying the SQL query, be sure to update the Product Flat Data under System > Index Management, then refresh all of your Magento caches under System > Cache Management

Trackbacks for this post

  1. How to separate different tax rules based on Category and Location with Magento and Magmi - Magento Tutorial

Leave a Reply