我在 config.xml 中有观察者 sales_quote_add_item,它在将商品添加到购物车时运行以下函数:
public function updatePrice( $observer ){
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = 200;
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->setTotalPrice(350);
$quote_item->save();
}
如果用户已注册,则工作正常,但如果我们是访客,则此行
$quote_item->save();
在 var/exception.log 中给出错误
2012-10-23T05:12:28+00:00 DEBUG (7): Exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`bluning_mage`.`sales_flat_quote_item`, CONSTRAINT `FK_SALES_QUOTE_ITEM_SALES_QUOTE` FOREIGN KEY (`quote_id`) REFERENCES `sales_flat_quote` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE)
我该如何解决?