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.

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵