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 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验