【发布时间】:2017-05-24 15:35:03
【问题描述】:
我想在 magento 中导入产品。这是脚本:
<?php
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
$product = Mage::getModel('catalog/product');
$product->setSku("ABC123");
$product->setName("Name");
$product->setDescription("Desc.");
$product->setShortDescription("Desc2.");
$product->setPrice(70.50);
$product->setTypeId('simple');
$product->setAttributeSetId(9);
$product->setCategoryIds("20,24");
$product->setWeight(1.0);
$product->setTaxClassId(2);
$product->setVisibility(4);
$product->setStatus(1);
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
$product->save();
?>
问题是结果:
致命错误:未捕获的异常 带有消息“SQLSTATE [23000]”的“PDOException”:完整性约束 违规:1452 无法添加或更新子行:外键 约束失败(
magento.catalog_product_entity, CONSTRAINTFK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID外键 (attribute_set_id) 参考资料eav_attribute_set(attribute_set_i)' in /home/zelewe3k/public_html/lib/Zend/Db/Statement/Pdo.php:228 Stack trace: #0 /home/zelewe3k/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array) #1 /home/zelewe3k/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array) #2 /home/zelewe3k/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array) #3 /home/zelewe3k/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array) #4 /home/zelewe3k/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTOca...',数组)#5 /home/zelewe3k/pu 输入 /home/zelewe3k/public_html/lib/Zend/Db/Statement/Pdo.php 在第 234 行
我能做什么? 怎么解决!?
【问题讨论】:
-
如果这是一个新产品,属性集
9真的存在吗?如果它是现有产品,您应该能够更改属性集 - 在DELETE或UPDATE上设置为CASCADE但我害怕想到会留下的那种混乱在数据库中。使用 System -> Import/Export -> Dataflow Profiles 可能会更好。