5

how in Magento 1.7 we can apply tax class to all products via SQL
Below is sql query which i hope that i need to run to get this done

 UPDATE `catalog_product_entity_int` SET `value` =2 WHERE `attribute_id` =81;

i am unable to find attribute id for for tax class attribute? Any help on this

or i am also open to entirely different solution

Manish Arora
  • 147
  • 1
  • 2
  • 9

4 Answers4

9

You can do it by code: Create a file called taxclass.php on the same level as index.php with the following content.

error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0); 
Mage::app();

$productIds = Mage::getResourceModel('catalog/product_collection')->getAllIds();

Mage::getSingleton('catalog/product_action')->updateAttributes(
    $productIds, 
    array('tax_class_id' => 2),
    0
);

If you still want to do it in a query you can identify the tax class attribute like this:

SELECT 
    * 
FROM 
    eav_attribute
WHERE 
    attribute_code = 'tax_class_id' AND
    entity_type_id = (SELECT entity_type_id FROM eav_entity_type where entity_type_code = 'catalog_product')

then run your update with the attribute id your find. But this won't work if you have products that don't have a class id set.

Marius
  • 197,939
  • 53
  • 422
  • 830
6

Log in to your admin panel, then select

Catalog->Manage Products

Then you can click Select All, and from the Actions drop down on the right, choose Update Attributes.

Here you can choose the tax class and update all products in one go.

enter image description here

JamesAllwood
  • 1,543
  • 1
  • 11
  • 21
  • tax class id attribute isn't available in this method – Manish Arora Apr 02 '14 at 09:18
  • I've added a screenshot to the answer. If you can't see this, then I would imagine that you're selecting a product/s that are a part of an attribute set where tax_class has been removed. In which case, you need to address that first. – JamesAllwood Apr 02 '14 at 09:42
  • 1
    Is the possible apply tax by SKU wise? –  Jun 22 '17 at 05:26
1

Open Magento admin, Go to the catalog manage products section. Then click on select all and go to mass action dropdown and selection update attribute and apply.

Then a new window will open then apply changes in text class attribute.

Abhinav Singh
  • 2,592
  • 15
  • 14
1

To find attribute ID

  1. In your database and find your eav_attribute table execute below query

    SELECT * FROM eav_attribute WHERE attribute_code LIKE 'tax_class_id'

  2. You can get attribute id by above sql query

  3. By using that you can execute this sql

    UPDATE catalog_product_entity_int SET value =2 WHERE attribute_id = your_attribute_id;

Ishak Ali
  • 119
  • 7