dsfsad089111 2014-03-31 15:26
浏览 13
已采纳

能够以编程方式创建Magento货件但无法将其标记为已发货吗?

I have the following code that would create a shipment for an order. But still the shipped item isn't marked as shipped. And SHIP button at the top is still there. Therefore, I cant create RMA if needed.

Please check screenshot (link)

$order = Mage::getModel('sales/order') -> loadByIncrementId($order_id);
$itemQty = $order -> getItemsCollection() -> count();

$convertOrder = new Mage_Sales_Model_Convert_Order();
$shipment = Mage::getModel('sales/service_order', $order) -> prepareShipment($itemQty);

$items = $order -> getAllItems();

foreach ($items as $item) {
    $shipped_item = $convertOrder -> itemToShipmentItem($item);
    $shipped_item -> setQty($item -> getQtyOrdered());
    $shipment -> addItem($shipped_item);
}

$shipment -> register();
$shipment -> setOrder($order);
$shipment -> save();
  • 写回答

1条回答 默认 最新

  • dongyukui8330 2014-03-31 16:32
    关注

    I always hop to the source for problems like these. The code that determines if that button displays is here

        #File: app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
        if ($this->_isAllowedAction('ship') && $order->canShip()
            && !$order->getForcedDoShipmentWithInvoice()) {
            $this->_addButton('order_ship', array(
                'label'     => Mage::helper('sales')->__('Ship'),
                'onclick'   => 'setLocation(\'' . $this->getShipUrl() . '\')',
                'class'     => 'go'
            ));
        }
    

    Looking at that, your best bet is the canShip method

    #File: app/code/core/Mage/Sales/Model/Order.php
    public function canShip()
    {
        if ($this->canUnhold() || $this->isPaymentReview()) {
            return false;
        }
    
        if ($this->getIsVirtual() || $this->isCanceled()) {
            return false;
        }
    
        if ($this->getActionFlag(self::ACTION_FLAG_SHIP) === false) {
            return false;
        }
    
        foreach ($this->getAllItems() as $item) {
            if ($item->getQtyToShip()>0 && !$item->getIsVirtual()
                && !$item->getLockedDoShip())
            {
                return true;
            }
        }
        return false;
    }
    

    Drop some var_dump/Mage::log debugging in here and you should be able to figure out why Magento thinks it needs to display the shipping button. Once you know that, you should be able to figure out what additional state you need to save.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决