I have the problem with UPDATING table catalog/product in Magento. I want to update value in column 'custom_product_option' which I added as EAV attribute :
for ($i=0;$i<=sizeof($my_data); $i++){
$id = $my_data[$i];
$db_data = array('custom_product_option'=>3);
$model = Mage::getModel('catalog/product')->load($id)->addData($db_data);
try {
$model->setId($id)->save();
echo "Data updated successfully.";
} catch (Exception $e){
echo $e->getMessage();
}
}
When I try to UPDATE my new custom value in catalog/product table I get this error:
Integrity constraint violation 1062 duplicate entry '44-1-0-2.0000-0' for key '...'
I am confused, because I am updating the table, and it behaves like I am inserting new value with same ID. I appreciate if somebody could help.
I assume that $my_data
is an array of product ids that need to be updated.
If so, try this. It is much faster:
$db_data = array('custom_product_option'=>3);
Mage::getSingleton('catalog/product_action')->updateAttributes(
$my_data, //array with ids to be updated,
$db_data, //array with attributes to be updated,
0 //store id for the update : 0 = default values
);