4

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.

3 Answers 3

13

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.

1
  • 3
    Wow, there is no way I would know to use setURLKey(false).
    – dnelson
    Jun 13, 2014 at 1:38
4

(Possible Assumption) Adding the setStoreId appears to be required now in 1.13.1.0

3
  • I think you are wrong. You have to set the store_id if you want to save or load storeview specific content. If you want to get website scoped content or default, then you don't need this. Mar 11, 2014 at 22:37
  • magento.stackexchange.com/questions/12500/… This problem, leads me to believe my assumption.
    – Aepod
    Mar 11, 2014 at 23:59
  • Interesting magento bug - I think. Thanks for the link. The problem is, magento tries to save everything in store view scope (because you are in frontend?) but the url_key already exists and magento doesn't realize it is the same product? whatever. If it solves the problem I'll be quiet. Mar 12, 2014 at 7:18
0

There is official magento patch to fix that. This is a bug.

2
  • 1
    Can you provide more details about this?
    – Marius
    Mar 13, 2014 at 8:29
  • Sounds like a EE bugfix, which you are not allowed to publish. But if this fix is part of CE 1.8.1 one could extract it and post it here... Mar 13, 2014 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.