我試圖將解析的數據添加到每個產品的描述。Magento SQL錯誤,當試圖添加描述programmaticaly
這就是我:
require 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$productMage = Mage::getModel('catalog/product');
foreach ($productDescXpath as $description) { // Find each item's description
if (!$productMage->load($dataId)->getData('description')) {
$productMage->load($dataId)->getData('description');
$productMage->setDescription($description->nodeValue);
$productMage->save();
}
}
在$數據ID我有每個產品的ID和$說明 - >的nodeValue那些描述。
如果我只想用一種產品(例如用真正的產品ID替換$ dataID,例如570),並添加一些字符串而不是$ description-> nodeValue,則它可以工作。
但如果我使用第一建築 - 這就是我得到:
PHP Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update
a child row: a foreign key constraint fails (`semenin_magento`.`
catalog_product_entity`, CONSTRAINT
`FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY
(`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id)' in
/home/s/semenin/public_html/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/s/semenin/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/s/semenin/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110):Zend_Db_Statement_Pdo->_execute(Array)
#2/home/s/semenin/public_html/lib/Zend/Db/Statement.php(300):Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/s/semenin/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/s/semenin/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#5 /home/s/semenin/publi in /home/s/semenin/public_html/lib/Zend/Db/Statement/Pdo.php on line 234
你可以給我們$ dataId和$ description變量的日誌嗎? – Jouby
@Jouby,你好。當然,這是$ dataId = 19523 19524 19522 19511 19509 19508 19496,$ in描述了每個$ dataId的一些文本,這對評論很重要,但它是存在的。 – Frunky
Hm ...帶有此Id的項目在'catalog_product_entity'表中不存在 – Frunky