【问题标题】:Can't import product in Magento with script无法使用脚本在 Magento 中导入产品
【发布时间】: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, CONSTRAINT FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID 外键 (attribute_set_id) 参考资料eav_attribute_setattribute_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真的存在吗?如果它是现有产品,您应该能够更改属性集 - 在 DELETEUPDATE 上设置为 CASCADE 但我害怕想到会留下的那种混乱在数据库中。使用 System -> Import/Export -> Dataflow Profiles 可能会更好。

标签: php magento


【解决方案1】:

看起来属性集 id 9 不存在。请检查您的属性集 id 是否存在于 Magento 中或尝试

$product->setAttributeSetId(4);

【讨论】:

    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多