Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Magento中删除所有相关的产品链接?_Magento_Product - Fatal编程技术网

如何从Magento中删除所有相关的产品链接?

如何从Magento中删除所有相关的产品链接?,magento,product,Magento,Product,我创建导入脚本来管理相关产品,并使用如下代码: $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]

我创建导入脚本来管理相关产品,并使用如下代码:

$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)
 $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
 $sql = "DELETE FROM `catalog_product_link` WHERE `link_type_id`=1";
 $connection->query($sql);
我得到的错误如下:

$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)
 $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
 $sql = "DELETE FROM `catalog_product_link` WHERE `link_type_id`=1";
 $connection->query($sql);

如果要从商店中删除所有相关的产品链接,easist方法如下:

$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)
 $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
 $sql = "DELETE FROM `catalog_product_link` WHERE `link_type_id`=1";
 $connection->query($sql);

当然,首先在目录\产品\链接\类型表中检查相关产品的链接id。通常为1,但最好先检查

如何对一个产品执行此操作?只需像这样扩展sql:从
目录\u产品\u链接
中删除
链接\u类型\u id
=1和
产品\u id
=您的产品\u id