【发布时间】:2019-06-11 07:14:45
【问题描述】:
我尝试以编程方式添加产品。我使用下面的代码
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
$paramater = array(
'product' => $product->getId(),
'related_product' => null,
'qty' => 1,
'form_key' => Mage::getSingleton('core/session')->getFormKey()
);
$request = new Varien_Object();
$request->setData($paramater);
$cart->addProduct($product, $request);
$cart->save();
此代码在登录后工作正常。但在登录之前我收到以下错误。
a:5:{i:0;s:640:"SQLSTATE[23000]: 完整性约束违规:1452 无法添加或更新子行:外键约束失败 (
db_magento_nua.sales_flat_quote_item, CONSTRAINTFK_SALES_FLAT_QUOTE_ITEM_QUOTE_ID_SALES_FLAT_QUOTE_ENTITY_IDFOREIGN KEY (quote_id) REFERENCESsales_flat_quote(entity_id) ON DELE),查询是:INSERT INTOsales_flat_quote_item(created_at,updated_at, @9876543323@, @98765333 @、sku、name、is_qty_decimal、weight、qty、custom_price、product_type、original_custom_price、base_cost) 值 ('2019-06-11: 58', '2019-06-11 12:17:58', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";i:1;s:2586: "#0 /var/www/html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
谁能帮我解决这个问题。提前致谢。
【问题讨论】:
标签: php mysql magento magento-1.9