Magento - 更新sales_flat_order_item表中的发票数量

时间:2016-05-12 11:23:11

标签: php mysql magento

我需要更改qty_invoiced表中某个订单的sales_flat_order_item列的值,但遗憾的是没有任何事情发生。

这是我的代码:

$allOrders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('status', 'complete');

foreach ($allOrders as $value) {
  $order = Mage::getModel('sales/order')->load($value->getId());
  if($order->getincrementId() == '100000003'){
    foreach ($order->getAllItems() as $item) {
      $qtyOrdered = $item->getQtyOrdered();
      $item->setQtyInvoiced($qtyOrdered);
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我认为您需要在设置新数量后保存项目和订单。

foreach ($allOrders as $value) {
    $order = Mage::getModel('sales/order')->load($value->getId());
    if($order->getincrementId() == '100000003'){
        /** @var $item Mage_Sales_Model_Order_Item */
        foreach ($order->getAllItems() as $item) {
            $qtyOrdered = $item->getQtyOrdered();
            $item->setQtyInvoiced($qtyOrdered);
            $item->save();

        }
    }
    $order->save();
}