Вопрос

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

Это было полезно?

Решение

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.

Другие советы

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

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top