【发布时间】:2011-10-27 23:14:13
【问题描述】:
我正在研究一个观察者,它需要在下订单后向购物车中的每个项目添加(a)序列密钥。
我现在正在收听活动 sales_model_service_quote_submit_success。
我已经能够访问订单、获取商品列表、遍历它们并获取产品选项。当我尝试 setProductOptions 或保存时,我的代码失败 - 我不确定是哪一个,也许两者兼而有之。
以下是相关代码:
// Get access to order information
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($lastOrderId);
// Get the items from the order
$items = $order->getAllItems();
foreach ($items as $item)
{
// Pretend here is the call that fetches the serial keys for this item and stores them in $keyString
// If we actually received the keys in a string, store them with the item
if (!empty($keyString))
{
$productOptions = array();
if (count($item->getProductOptions()))
{
$productOptions = $item->getProductOptions();
}
$productOptions['keys'] = $keyString;
$item->setProductOptions($productOptions);
$item->save();
}
}
任何想法我忘记或做错了什么?非常感谢。
【问题讨论】: