1

I have this simple code, which tries to update the product's name & description like this:

$productID = Mage::getModel('catalog/product')
    ->getIdBySku($product->Sku);

if ($productID)
{
    $p = Mage::getModel('catalog/product'); 
    $p->load($productID);
    $p->setName($product->Name);
    $p->setDescription($product->Description);
    $p->save();
    $p = null;
}

This causes the following error to occur:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3596-0-1-0' for key 'CC12C83765B562314470A24F2BDD0F36', query was: INSERT INTO catalog_product_entity_group_price (entity_id, all_groups, customer_group_id, value, website_id) VALUES (?, ?, ?, ?, ?)

I've noticed this error only occurs IF the product has group_price set on it (even though I am not updating this).

Any ideas? I am on magento 1.9.x

1

Okay, I have solved it like this: hope this helps someone else with similar issue...

// Update Existing Product
$productAction = Mage::getSingleton('catalog/product_action')
    ->getResource();
$productAction->updateAttributes(array($productID), array(
    'name' => $product->Name,
    'description' => $product->Description
), 0); // 0 = store id (default scope)
$productAction = null;

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.