我正在使用 Magento 的观察者挂钩来挂钩订单保存过程。我想在订单设置完成并保存后向网络服务发送消息。
但是我注意到网络服务经常收到重复的订单项目。
这是我的代码的简化版本,我知道它存在问题:
<?php
class Name_Modulename_Model_Observer {
public function sales_order_save_commit_after($observer) {
// Gets the order which is being saved.
$order = $observer->getOrder();
$status = $order->getStatus();
if($status != "complete") {
continue;
}
// PROBLEM - The number of Mage_Sales_Model_Order_Item
// in this array sometimes does not correspond with the
// The number of items in the basket.
$items = $order->getAllItems();
$itemsInOrder = array();
foreach($items as $item) {
$product = $item->getProduct();
$itemsInOrder[] = $product->name;
}
// At the end of the loop $itemsInOrder can contain
// multiple name entries for the same line item. Why is this?
}
}
?>