0

I have an observer for cataloginventory_stock_item_save_after. From here I change delivery_time:

$stockItem = $observer->getEvent()->getItem();
$productId = $stockItem->getData('product_id');
$product = Mage::getModel('catalog/product')->load($productId);
$product->setData('delivery_time', $rot)->getResource()
  ->saveAttribute($product, 'delivery_time');

This works fine if I work in the backend. But if I order this product delivery_time is changed for the current store view not global.

How can I change the attribute's global value?

1 Answer 1

2

Version 1

Faster, without load:

$stockItem = $observer->getEvent()->getItem();
$productId = $stockItem->getData('product_id');
Mage::getSingleton('catalog/product_action')->updateAttributes(
   array($productId), //product ids
   array('delivery_time' => $rot), //what to update
   Mage_Core_Model_App::ADMIN_STORE_ID //store id to update
);

Version 2

With load

Replace this:

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

with this:

$product = Mage::getModel('catalog/product')->setStoreId(0)->load($productId);  
1
  • I only had a solution with Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); and thought there must be a better way. This is perfect! Nov 28, 2014 at 12:41

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.