3

I have a relatively large database and every now and again I find products that when imported were not assigned to a tax class. While I agree that this should be addressed when products are imported, it can still cause a problem if a product is overlooked for one reason or another and a visitors happens to purchase an affected product.

Since all products in my store are taxeable and of the same tax class, how can I force magento to have a default value of taxeable goods instead of "none" for all store products?

3
  • 1
    To all who have answered thank you - but I am looking for a solution that does this automatically / default. I am capable of doing this manually; there has to be a way to default all products to this setting.
    – SR_Magento
    Commented Aug 2, 2014 at 23:31
  • My answer sets the default value for the attributes, so that it should work automatically for new products.
    – Simon
    Commented Aug 12, 2014 at 7:03
  • Did you find a reasonable solution to this? I had a similar problem but I wanted them all to be "None". I ended up editing the attribute settings to make it not required and to not be visible on the front end. I know it won't help you but hopefully someone else!
    – NotJay
    Commented Oct 8, 2015 at 15:51

5 Answers 5

2

I don't know if this is an option. I've got a solution that requires a CRON to be run every so often.

gist.github.com/btray77/d37fc77bc22b397b03b8 <-- Code is also here.

It's not been tested, but I use almost the same code to update products attributes.

Observer.php

<?php
//  app/code/local/Yourname/Tax/Model/Observer.php
class YourName_Tax_Model_Observer {
        public function updateTaxRates(){

        $productCollection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('tax_class_id');

        foreach ($productCollection as $product) {

            if (($taxClassId != '1')) {  
            //You can change the logic here

                $product->setData('tax_class_id', $store_id)->getResource()->saveAttribute($product, 'tax_class_id');
                usleep(20000);//0.02 seconds to keep database from being locked
            }
        }
    }

}

Config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- html/app/code/local/Yourname/Tax/etc/config.xml -->
<config>
   <modules>
      <Yourname_Tax>
         <version>0.1.1</version>
      </Yourname_Tax>
   </modules>
   <!-- -->
   <crontab>
      <jobs>
         <Yourname_Tax>
            <schedule>
               <cron_expr>*/05 * * * *</cron_expr> <!-- Every X Minutes Update As Needed-->
            </schedule>
            <run>
               <model>Yourname_Tax/observer::updateTaxRates</model>
            </run>
         </Yourname_Tax>
      </jobs>
   </crontab>
   <!-- -->
</config>
2

Well, since you're not exactly forthcoming how exactly do you import your products (magmi, api, dataflow?), I'm shooting from the hip here. If you're using Magento's own tools, you can use observer that updates attributes.

As an alternative is to create a database trigger that updates records during INSERT / UPDATE and makes sure that tax class is always "Taxable goods".

1

Taken from this Stackoverflow answer, you can do it with a SQL query. First, check in the database in the table tax_class what the ID of the default tax class is. Then, run the following SQL query (replacing 1 with the respective tax class):

UPDATE `eav_attribute` SET `default_value` = '1' WHERE `eav_attribute`.`attribute_code`='tax_class_id';

Always be careful with the DB and backup first.

2
  • Sorry for the late reply, tried this and it did not work. V1.9
    – SR_Magento
    Commented Aug 21, 2014 at 18:39
  • And you are 100% sure that you do not import any value for the tax_class field? Then I do not know what the problem is... Cannot test it properly...
    – Simon
    Commented Aug 22, 2014 at 6:28
0

You can did through admin panel.

Goto Admin panel > Catalog > Manage Products

Then Select all product and select Update Attribute in Mass action

enter image description here

Now you can see the page with all attributes. Find Tax Class and check that change, then save

enter image description here

Cheers

1
  • 1
    Yes, thank you, I am aware of this; but how do I force it to be automatic?
    – SR_Magento
    Commented Aug 2, 2014 at 11:58
0

You might have the disable Tax Class from Attributes and recreate it but this time don't make it a dropdown, but text with the defualt text being taxable goods. I would try it on a developing site on not production.

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.