如果物品尚未开具发票,我们是否可以阻止物品运送? Magento的

时间:2014-08-22 12:15:22

标签: magento

理想情况下,我们希望阻止订单中的任何商品在未创建发票时发货。

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

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

编辑 - 以下代码是否可以正常运行?

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.')
        );
    }

1 个答案:

答案 0 :(得分:0)

您可以通过查看以下代码来获得有关要使用的代码的一些提示:公共函数canInvoice()中的\ app \ code \ core \ Mage \ Sales \ Model \ Order.php:

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;
}