【问题标题】:Can we prevent an item being shipped if the item has not been invoiced. Magento如果物品尚未开具发票,我们能否阻止物品被运送? Magento
【发布时间】:2014-10-16 07:07:06
【问题描述】:

理想情况下,如果订单上的任何物品没有创建发票,我们希望防止它们被运送。

目前,即使没有为订单创建发票,Magento (1.7.0.2) 也允许创建发货。我意识到这是为希望先发货然后开票的网站所有者设计的,但我们的工作流程要求在创建发票时先付款,然后再允许发货。

任何人都可以就如何更改提供任何代码明智的建议吗?我认为正确的文件是/app/code/local/Mage/Sales/Model/Order/Shipment.php,我们需要更改的代码如下,但我不确定如何单独检查每个项目的发票。

编辑 - 下面的代码可以正常工作吗?

protected function _beforeSave()
{
    if ((!$this->getId() || null !== $this->_items) && !count($this->getAllItems())) {
        Mage::throwException(
            Mage::helper('sales')->__('Cannot create an empty shipment.')
        );
    }

    $order = $this->getOrder();
    if ($order->canInvoice()) {
        Mage::throwException(
            Mage::helper('sales')->__('Cannot ship items without an Invoice.')
        );
    }

【问题讨论】:

    标签: magento


    【解决方案1】:

    您可以通过查看以下代码获得一些关于要使用的代码的提示:\app\code\core\Mage\Sales\Model\Order.php in public function canInvoice():

    public function canInvoice()
    {
        if ($this->canUnhold() || $this->isPaymentReview()) {
            return false;
        }
        $state = $this->getState();
        if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
            return false;
        }
    
        if ($this->getActionFlag(self::ACTION_FLAG_INVOICE) === false) {
            return false;
        }
    
        foreach ($this->getAllItems() as $item) {
            if ($item->getQtyToInvoice()>0 && !$item->getLockedDoInvoice()) {
                return true;
            }
        }
        return false;
    }
    

    【讨论】:

    • 谢谢我更新了问题,你觉得我的解决方案怎么样?
    猜你喜欢
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多