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

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

  • tax class id attribute isn't available in this method – Manish Arora Apr 2 '14 at 9: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 2 '14 at 9:42
  • 1
    Is the possible apply tax by SKU wise? – user51361 Jun 22 '17 at 5:26
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.

  • to do this via code where should i put that code overide ? – Manish Arora Apr 2 '14 at 9:17
  • You can put the code in one of the upgrade scripts of any module you create, or you can put it in a simple php file and run that in the browser. See my update to the answer – Marius Apr 2 '14 at 9:29
  • Very nice :) This is a very neat way. – Milkmannetje Apr 11 '16 at 9:22
  • Which one is best frist or second ? – Saurabh Taletiya Dec 25 '17 at 7:35
  • @SaurabhJain Neither. Better use the accepted answer. But if you want to do it via code, better use first one to avoid direct queries. – Marius Dec 25 '17 at 8:10
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.

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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