我試圖以編程方式在magento中創建產品。該腳本適用於默認安裝。但是,當我嘗試在那些已給予表前綴的magento安裝中創建產品時,它顯示下面的錯誤。你能告訴我需要做什麼改變嗎?以表格前綴編碼方式在magento中創建產品
完整性約束違規:1452不能添加或更新子行:外鍵約束失敗(
databasename_magento
catalog_category_product_index
,約束FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID
外鍵(category_id
)參考文獻catalog_category_entity
(`entity_)
$product = new Mage_Catalog_Model_Product();
$product->setSku($sku);
$product->setAttributeSetId(9);
$product->setTypeId('simple');
$product->setName('55');
$product->setCategoryIds(array(7)); # some cat id's, my is 7
$product->setWebsiteIDs(array(1)); # Website id, my is 1 (default frontend)
$product->setDescription('Gift card Full description here');
$product->setShortDescription('Gift Card Short description here');
$product->setPrice('200'); # Set some price
$product->setWeight(4.0000);
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
$product->setStatus(1);
$product->setTaxClassId(0); # My default tax class
$product->setStockData(array('is_in_stock' => 1, 'qty' => 9999));
$product->save();
你有另一個問題$ product-> setWebsiteIds(array(1)); –