Magento – Programmatically Update a Single Attribute in Store View Scope

product-attributeprogrammaticallysavescope

If you load a product in Store View scope, all the inherited data ("Use Default Values") comes with it… which makes perfect sense, so far so good.

$_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);

My problem is, if you then change one attribute and save, everything is saved at Store View scope.

$_product->setName($storeSpecificName)->save();

Now, if I look at the product in the admin, every "Use Default Values" checkbox is unticked 🙁

It doesn't help if I do $_product->save() or $_product->getResource()->save($_product). I even tried:

$_resource = $_product->getResource();
$_resource->isPartialSave(true);
$_resource->save($_product);

Maybe I'm misunderstanding what isPartialSave() does.

So, how do I change one (or more, but not all) attributes at Store View scope?

Best Answer

Load is pretty expensive memory wise.
You can use this for a faster update:

Mage::getSingleton('catalog/product_action')->updateAttributes(
    array($productId),
    array('name' => $storeSpecificName),
    $storeId
);