Magento – How to load and save product in EE 1.13

ee-1.13magento-enterpriseproduct

In previous versions of Magento, I was able to use this code:

$product = Mage::getModel('catalog/product')->load(147);
$product->setDescription('test description');
$product->save();

However, in EE 1.13.1, I am getting a fatal error:

Fatal error: Uncaught exception
'Mage_Eav_Model_Entity_Attribute_Exception' with message 'Product with
the 'louis-vuitton-handbag' url_key attribute already exists.' in
/Applications/XAMPP/xamppfiles/htdocs/magentoee113/app/code/core/Mage/Core/Model/Config.php:1348
….

If I set the store ID when loading the product, then it works:

$product = Mage::getModel('catalog/product')->setStoreId(0)->load(147);
$product->setDescription('test description');
$product->save();

What is the proper way to do this?

Thanks.

Best Answer

To save prices per website/store and to avoid getting the 'url_key' error do the following:

foreach ($storeIds as $storeId) {
    //load the product with store id
    $product = Mage::getModel('catalog/product')
        ->setStoreId($storeId)
        ->load($productId);

    //Set the store price
    $product->setPrice($price);

    //To stop Magento regenerating url-key for store, set following,
    $product->setUrlKey(false);

    //Save the product
    $product->save();
}

This has been tested and it works.

Related Topic