0

I've about 6000 products with empty TAX-CLASS, what is the best approach to correct it to a proper TAX-CLASS. All the products will get the same tax-class insteed of an empty one

3 Answers 3

3

Go to Catalog->Manage Products.

Select All Products and select action is "Update attributes" then submit

In attributes tab you see "Tax Class", select tax class then save it.

2
  • In my Update Attribute Tax class missing inside attribute tab, how to make visible? @Prashant Valanda
    – zus
    Aug 31, 2019 at 6:47
  • If you are not seeing the "Tax Class" option in the list try to filter your selection by Attribute set. There is a good chance that some products don't have the tax class attribute assigned.
    – Michiel
    Oct 11, 2021 at 7:24
3

This is my approach:

  1. Get the entire collection of products

  2. In a foreach loop load the instance of product and set the tax class.

You can take a look in tax_class table to see the corresponding id for each tax class.

   <?php
require_once ( "app/Mage.php" );
Mage::app();

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach($products as $product) {
    //$product = Mage::getModel('catalog/product')->load($prod->getId());
    try{
        if($product->getTaxClassId() == 0){
            $product->setTaxClassId(2); //tax class (0 - none, 1 - default, 2 - taxable, 4 - shipping)
            $product->save();
        }
    }
    catch(Exception $e){
        Mage::log($e->getMessage());
    }
}

Save this script under your root instalation of magento, in a php file and run it

1
  • For your information, loading a product in a loop of a product collection is a bad practice. Your product is already loaded in the collection so you can use directly the $product var from your foreach ;) Feb 21, 2016 at 18:44
0

The script from Alex will ruin every product when it already has a tax class or is declared as shipping. Don't run it this way! Use some filters while grabbing your collection or use an if statement in the loop.

2
  • Ok.. I have added a validation in loop, to see if the product has "none" tax class. Thanks for the observation Feb 21, 2016 at 18:25
  • I think this is a good answer now, gave you an up for this one.
    – Michael
    Feb 22, 2016 at 8:35

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.