2

I am new to this magento world and stuck on a problem: I need to create a attribute rule which can add 20% in all prices by default. In fact I created a rule with name "standard VAT" in Sales->Tax->Manage Tax Rules.

However, by default Magento is using "None" as the default Tax Class in Product > Price > Tax Class. How can we make Magento use my tax class "Standard VAT" by default instead?

I know one way is by selecting all products and editing the Tax Class attribute, but that is not a viable solution for us. If we go this route we have to apply that edit too often as our listing updates every 30 minute.

We need a 1 time solution so that all our newly add products and existing products can automatically use the new Tax Class.

If you know any way we can edit any file in magento please advise us with full file path, code to add and line number.

Thank you for your help in advance.

(I did what ever they recommenced here but this inst the solution for me: magentocommerce.com/knowledge-base/entry/ce18-and-ee113-vat-gst)

2

Unfortunately Magento does not have a setting in the Admin to force every new product created to default to a specified Tax Class. Without knowing your specific product loading procedure I am going to give you the most general, reusable solution for defaulting the Tax Class of new products.

First you need the Id of you new tax class. In the admin go to "Sales -> Tax -> Product Tax Classes" and click on the row for your "standard Tax" that you created. The URL in the browser window would be something like : http://website.com/index.php/admin/tax_class_product/edit/id/12/key/025f7b6050a3fdd31960637732d3b9f9/ You want the number between edit/id/ and /key/. That is the id of your tax class.

Next steps would be writing code to make a custom Magento module that would update the Tax Class every time you create a new product.

  1. Create a file /app/etc/modules/Stackoverflow_Example.xml and put the following in it. This is a module declaration that is telling Magento you are creating a module and where to find the files for it.

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <modules>
            <Stackoverflow_Example>
                <active>true</active>
                <codePool>local</codePool>
            </Stackoverflow_Example>
        </modules>
    </config>
    
  2. Create a file /app/code/local/Stackoverflow/Example/etc/config.xml and put the following into it. You will notice that some of the fields in the previous file match up to the path of this file and some of the nodes here. This file is telling Magento where to find your new Model Stackoverflow_Example_Model and also is telling Magento whenever you are creating a new product (catalog_product_new_action) to run some custom code on that product <method>catalog_product_new_action</method> and the custom code is found in a model <class>stackoverflow_example/product_observer</class> that Magento will now know how to find because we told it how to find our custom Models higher up.

    <?xml version="1.0"?>
    <config>
        <modules>
            <Stackoverflow_Example>
                <version>1.0.0</version>
            </Stackoverflow_Example>
        </modules>
        <global>
            <models>
                <stackoverflow_example>
                     <class>Stackoverflow_Example_Model</class>
                </stackoverflow_example>
            </models> 
            <events>
                <catalog_product_new_action>
                    <observers>
                      <stackoverflow_example_product_observer>
                        <type>singleton</type>
                        <class>stackoverflow_example/product_observer</class>
                        <method>catalog_product_new_action</method>
                      </stackoverflow_example_product_observer>
                    </observers>
                </catalog_product_new_action>
            </events>
        </global>
    </config>
    
  3. Create a file /app/code/local/Stackoverflow/Example/Model/Product/Observer.php and put the following code in it. All we are doing in this file is creating a simple PHP function that will determine the new Product that is being created $product = $observer->getEvent()->getProduct(); and it is then setting the tax class of it before it is saved $product->setTaxClassId(12);. Of course I am using 12 here because it was what was between edit/id/ and /key/ in my example above. However if your "standard Tax" class was the first one created on a new store it may be 3 or 4.

    <?php
    
    class Stackoverflow_Example_Model_Product_Observer
    {
        public function catalog_product_new_action($observer) {
    
            $product = $observer->getEvent()->getProduct();
            $product->setTaxClassId(12);
        }
    }
    
| improve this answer | |
  • Hi Talesh, Thank you for your help, but there is a problem, I am using stockinthechannel as my data provider, and there plugin auto import and display products from our manufacturer using cron job. I tried your solution but it do not work with imported products, after reimporting the products it is still showing " Tax Class * --Please Select--" it is still not selecting my tax class id. any reason? I have also given the right tax class id which is 8 – shafiq Feb 15 '15 at 14:07
  • If this is the case, then your best bet is to override their module or better yet, get in touch with them and ask them to update their module with a dropdown for you to select a default tax ID which you can configure on your Magento admin. :) – Talesh Feb 15 '15 at 14:50
  • I have already spoken to them, they have given straight answer VAT need to be done in magento we cant help you with this :( – shafiq Feb 15 '15 at 15:31
  • can we right any script which run every 10 or 5 minutes and update the tax class attribute for all listing? magento is a well known ecom platform how come they never came across this problem and solved it before? I am sure there are plenty of other peoples who are using stock In channel on magento. there should be a configuration setting which can help us? – shafiq Feb 15 '15 at 15:37

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.