I want to restore the "Use Default Value" option for the Tax Class field for all products where the price has store-view scope.

I am testing with the code in the first part of this question, however using setData($attr, false) doesn't work (nothing happens when I run the code). However, if I change false to eg 5 this works and the tax class is updated. I want to restore the "Use default value" option instead of updating the tax class itself.

Here is the code I am currently using:

$attrArray=array('tax_class_id'); // define array of attributes to set to 'use default value'
$products = array(3253); // ID 3253 = SKU 38356
$stores = array(6);

require_once "../app/Mage.php";

foreach ($stores as $store_id) {
    foreach ($products as $product_id) {
        foreach ($attrArray as $attr) {
            echo "Restoring '$attr' for product ID#$product_id in store #$store_id...<br />";
            $product = Mage::getModel('catalog/product')
            ->setData($attr, false)

I have tried using null in place of false as well.

Can anyone tell me what I need to do to get this to work properly?

I don't want to manipulate the database directly via MySQL for safety reasons.


You need to set the value to null with:

->setData($attr, null)

to remove the value on store level and use the default value.

| improve this answer | |
  • 1
    Unfortunately changing it to null doesn't work - same as using false, nothing changes. – Chris Nov 10 '14 at 19:02

You have to remove lines from DB, as suggested here.

Basically when you save an attribute value for a website or a store view in a product, Magento adds a line to EAV tables that overrides the default value. So the only way to restore "Use default", is to remove that additional line from DB.

It is a safe procedure, if you know what you are doing. Don't forget to perform a reindex after that.

| improve this answer | |

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.