我创建导入脚本来管理相关产品,我使用这样的代码:
$product = Mage::getModel('catalog/product')->load($product_id);
$related_data = array();
related_data[$linked_product_id]['position']=1;
$product->setRelatedLinkData($related_data);
$product->save();
我得到这样的错误:
SQLSTATE[23000]: Integrity constraint violation: 1452
Cannot add or update a child row: a foreign key constraint fails
(`netztech`.`catalog_product_link`, CONSTRAINT
`FK_CAT_PRD_LNK_LNKED_PRD_ID_CAT_PRD_ENTT_ENTT_ID`
FOREIGN KEY (`linked_product_id`)
REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE C)
答案 0 :(得分:1)
如果您想从商店中删除所有相关产品链接,那么简单方法就是这样:
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "DELETE FROM `catalog_product_link` WHERE `link_type_id`=1";
$connection->query($sql);
当然先在您的catalog_product_link_type表中查看相关产品的链接ID。通常它是1,但最好先检查一下!