Magento 产品保存时出现“catalog_product_entity_tier_price”错误中的重复条目
Magento Duplicate entry in `catalog_product_entity_tier_price` error on product save
我有一个启用了 Tier Price
的产品。当我加载该产品并尝试更新时,Magento 抛出异常。
这是我的代码。
$_product = Mage::getModel('catalog/product')->load(779);
try {
$_product->setData('backorder_limit', '10');
$_product->save();
} catch (Exception $e) {
echo $e->getMessage();
}
以上代码打印出以下异常
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
'779-1-0-5.0000-0' for key 'E8AB433B9ACB00343ABB312AD2FAB087', query
was: INSERT INTO catalog_product_entity_tier_price
(entity_id
,
all_groups
, customer_group_id
, qty
, value
, website_id
)
VALUES (?, ?, ?, ?, ?, ?)
当我删除分级价格时,上面的代码工作正常。我尝试重建索引并清除缓存但没有成功。
我对这个错误一无所知,所以我在这里问问你们是否有人知道问题是什么以及如何解决?
非常感谢!
有时 $product->save()
会抛出此错误。
为防止这种情况,请尝试使用 $product->getResource()->save($product)
。
希望对你有用。
编辑: 这假设您在脚本之上设置。
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
我有一个启用了 Tier Price
的产品。当我加载该产品并尝试更新时,Magento 抛出异常。
这是我的代码。
$_product = Mage::getModel('catalog/product')->load(779);
try {
$_product->setData('backorder_limit', '10');
$_product->save();
} catch (Exception $e) {
echo $e->getMessage();
}
以上代码打印出以下异常
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '779-1-0-5.0000-0' for key 'E8AB433B9ACB00343ABB312AD2FAB087', query was: INSERT INTO
catalog_product_entity_tier_price
(entity_id
,all_groups
,customer_group_id
,qty
,value
,website_id
) VALUES (?, ?, ?, ?, ?, ?)
当我删除分级价格时,上面的代码工作正常。我尝试重建索引并清除缓存但没有成功。
我对这个错误一无所知,所以我在这里问问你们是否有人知道问题是什么以及如何解决?
非常感谢!
有时 $product->save()
会抛出此错误。
为防止这种情况,请尝试使用 $product->getResource()->save($product)
。
希望对你有用。
编辑: 这假设您在脚本之上设置。
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);