我试图将我创建的第一个网站的产品复制到另一个以后在多中心设置中添加的23个网站。 我有这样的代码,我认为应该做的工作:将产品复制到所有网站 - Magento多店
$arr_stores = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24);
$store_from = 1; // first store id
// get observer data and process each imported simple product - my products that need to be copied to other websites
$_event = $observer->getEvent();
$_adapter = $_event->getAdapter();
foreach($_adapter->getNewSku() as $sku => $value) {
if($value['type_id'] == 'simple'){
// load the next product - this loads product correctly
$_product = Mage::getModel('catalog/product')->setStoreId($store_from)->load($value['entity_id']);
// set the websites
$_product->setWebsiteIds($arr_stores);
$_product->save();
// clear the var
unset($_product);
}
}
但我收到此错误信息:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`workoutlife`.`catalog_product_website`, CONSTRAINT `FK_CATALOG_PRODUCT_WEBSITE_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON DELET)
谁能告诉我,为什么这种限制可能会失败? 为什么ON DELET在那里?我不想删除任何东西。 TIA
您是否找到解决问题的方法? – infinity 2014-03-03 22:54:13