【问题标题】:Magento Shipment Create (programatically) - odd bugMagento Shipment Create(以编程方式) - 奇怪的错误
【发布时间】:2013-08-10 12:09:53
【问题描述】:

我使用以下函数为给定的订单生成发货,sku/qty:

function CreateShipment($order_info)
{
    // Anticipate Error
    try
    {
        // Load Magento Order
        $order = Mage::getModel('sales/order')
        ->loadByIncrementId($order_info->MagentoOrderIncrementId);

        // Load Magento Order Lines
        $order_items = $order->getItemsCollection();

        // Parse Despatch Lines
        $despatch_skus = array();
        foreach ($order_info->DespatchLines as $DespatchLine) {
            $despatch_skus[$DespatchLine->Sku] = $DespatchLine->Qty;
        }

        // Build Item Qtys
        $item_qtys = array();
        foreach ($order_items as $order_item) {
            if (array_key_exists($order_item->getSku(), $despatch_skus)) {
                $item_qtys[$order_item->getItemId()] = 
                    $despatch_skus[$order_item->getSku()];
            } else {
                $item_qtys[$order_item->getItemId()] = 0;
            }
        }

        // Create Shipment
        $shipment = $order->prepareShipment($item_qtys);
        $shipment->register();
        $shipment->sendEmail(false)
                 ->setEmailSent(false)
                 ->save();
        $transactionSave = Mage::getModel('core/resource_transaction')
                 ->addObject($shipment)
                 ->addObject($shipment->getOrder())
                 ->save();

        // Finished
        $order = null;
        $shipment = null;
        $transactionSave = null;
        return true;
    }
    catch (Exception $ex)
    {
        // Log Error
    }
    return false;
}

其中,$order_info 是一个如下所示的对象:

stdClass Object
(
    [MagentoOrderIncrementId] => 100010039
    [DespatchLines] => Array
        (
            [0] => stdClass Object
                (
                    [Sku] => VCF001
                    [Qty] => 1
                )
        )
)

该函数返回 true,但是 magento 中的订单不显示“已发货:1” - 看看:http://i.imgur.com/Z9S1AY2.png

但是,如果我点击“发货”标签,我可以看到以下内容:http://i.imgur.com/GJCLtwW.png

所以看起来货件确实已创建。如果我进入条目,我会看到我的 sku 和数量:http://i.imgur.com/e5wZGAP.png

知道为什么我刚刚创建的货件没有正确更新订单吗?

注意*如果我使用右上角的“运送”按钮,它将允许我再次运送该物品,这一次它可以正常工作(当我在管理 UI 中执行此操作时)。通过我上面发布的功能代码,它只是没有按预期工作。

任何提示/提示/建议将不胜感激。问候,Latheesan。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    通过在“$transactionSave”代码块之后添加此行来解决此问题:

    $order->save()
    

    【讨论】:

      【解决方案2】:

      也许不是最佳实践,我添加了对我有用的这两行:

      $orderItem->setQtyShipped(1); 
      $orderItem->save();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-11
        • 2018-04-17
        • 1970-01-01
        • 2018-06-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多