我创建导入脚本来管理相关产品,并且使用如下代码:
$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)
如果要从商店中删除所有相关的产品链接,则easist方法是这样的:
$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,但是最好先进行检查!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句