gpt4 book ai didi

php - 违反完整性约束 : 1062 Duplicate entry '4974-134' for key 'UNQ_CATALOG_PRODUCT_SUPER_ATTRIBUTE_PRODUCT_ID_ATTRIBUTE_ID'

转载 作者:行者123 更新时间:2023-11-29 08:25:24 25 4
gpt4 key购买 nike

添加可配置产品时(创建简单产品之前),我在 Magento 中收到上述错误

这已经有效,但由于某种原因现在失败了。

表中甚至不存在键值 4974-134: enter image description here

我尝试重新创建表格。我已经清除缓存/日志表/重新索引,但似乎没有任何效果 - 每次 4974 (product/entity_id) 递增 1 时,意味着它正在 Catalog_product_entity 表中创建,但事实并非如此:

enter image description here

最佳答案

最终解决此问题的唯一方法是在新模块中扩展/覆盖 Product 模型 _afterSave 函数(确保新类扩展了 Mage_Catalog_Model_Product)。

像这样:

/**
* Saving product type related data and init index
*
* @return Mage_Catalog_Model_Product
*/
protected function _afterSave()
{
$this->getLinkInstance()->saveProductRelations($this);

if($this->getTypeId() !== 'configurable')
{
$this->getTypeInstance(true)->save($this);
}


/**
* Product Options
*/
$this->getOptionInstance()->setProduct($this)
->saveOptions();

$result = parent::_afterSave();

Mage::getSingleton('index/indexer')->processEntityAction(
$this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
);
return $result;
}

关键点是:

if($this->getTypeId() !== 'configurable')
{
$this->getTypeInstance(true)->save($this);
}

}

看起来由于某种原因,在创建可配置产品时,它试图保存可能已经存在于资源适配器中的对象 - 对此的一些想法将不胜感激。

关于php - 违反完整性约束 : 1062 Duplicate entry '4974-134' for key 'UNQ_CATALOG_PRODUCT_SUPER_ATTRIBUTE_PRODUCT_ID_ATTRIBUTE_ID' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18107288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com