Update products programmatically in Magento

后端 未结 5 823
礼貌的吻别
礼貌的吻别 2020-12-13 15:53

I\'m working on a script that will create or update products in my catalog.
The script works fine when the product needs to be created, but it fails when the product alr

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 16:13

    Adding Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); before saving product solves the error. The sample code below updates product's cost.

    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    $productId = 160;
    $newCost = 80;
    $product = Mage::getModel('catalog/product')->load($productId);
    $product->setCost($newCost)->save();
    

提交回复
热议问题