2013-09-27 67 views
0

似乎我必須設置一個商店視圖才能更新網站範圍上的屬性 - 是否正確?Magento需要一個storeview設置來更新網站範圍屬性

我的代碼:

Mage::app('admin'); 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

$product = Mage::getModel('catalog/product'); 
$product->load(123); 
$product->setStoreId('1'); // without this line the attribute is not updated 
$product->setSomeattribute("abc"); 
$product->save(); 

回答

1

是。這是正確的。這是前臺的性能原因。通常你不會從前端保存產品。 See a detailed explanation of why is this needed
但你不需要那樣做。我速度慢,資源消耗大。嘗試像這樣保存:

Mage::getSingleton('catalog/product_action') 
    ->updateAttributes(array(123), array('somattribute'=>'abc'), 1); 

第一個參數是數組,並且與產品id一起排列。
第二個是具有要更新的屬性代碼和值的數組。
第三個是更新完成的商店標識。

這種方法更快。

+0

好的,謝謝我會嘗試。順便說一句......有可能,這在早期版本中有所不同嗎?我的導入腳本運行良好,但未更新之前設置storeId(從1.4到1.7.0.2) – johjoh

+0

@johjoh我認爲這個限制是在1.3中添加的,但我不確定。 – Marius

+0

仍然沒有得到它。我不是說'setCurrentStore(Mage_Core_Model_App :: ADMIN_STORE_ID)',而是'setStoreId('1')'......就這樣使用它,但現在遇到了網站範圍內的圖像問題,因此沒有在那裏更新。 – johjoh