sales_quote_add_item - 保存报价时出错

时间:2012-10-23 06:05:32

标签: magento

我在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)

我该如何解决?

1 个答案:

答案 0 :(得分:22)

您不应该在观察者中保存引用项目对象,因此只需删除此行$quote_item->save(); 它会自动保存对象,因为它是通过引用传递的。