Reset ‘Use Default Value’ for Store View on All Products – Magento Guide

store-view

Somehow a number of my products had the "Use Default Value" deselected.

My store has 2 languages, English and French. French uses the Default Store value, so now when I update products it doesn't appear on the front end unless I manually go onto the product on the French store view and select "Use Default Value",

There doesn't appear to be an attribute for a mass action, I've come across some scripts and MySQL queries however it is not clear if those solutions reset all store views to use the default value.

The desired result is to set "Use Default Value" on a specific store view (French) on all products.

How do I reset a large number of products (or all products) to "Use Default Value" on a specific store view?

Best Answer

Unfortunately, none of the efficient ways to update a product attribute work in this case. $product->getResource()->saveAttribute() updates the attribute for all store views even if you set the store ID on the $product object. Mage::getSingleton('catalog/product_action')->updateAttributes() only updates the value in a specific store, but it cannot set the attribute to use the default value (see also this Stack Overflow question for a reference). Hence, we have to use the slow, memory intensive way via $product->save().

I assume that you know which attributes you would like to update. For the following example, I set the visibility attribute to use the default value. The following script should then do the trick (make sure you change it according to your needs):

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

require_once 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
set_time_limit(0);

function useDefaultValueCallback($args)
{
    // change to the ID of your french store view
    $specificStoreViewId = 7;
    $product = Mage::getModel('catalog/product');
    $product->setData($args['row']);
    $product->setStoreId($specificStoreViewId);
    // change according to your needs
    $product->setData('visibility', false);
    $product->save();
}

$products = Mage::getModel('catalog/product')->getCollection();
Mage::getSingleton('core/resource_iterator')->walk($products->getSelect(), array('useDefaultValueCallback'));
Related Topic