magento中的自动开票 [英] Automatic invoicing in magento

查看:85
本文介绍了magento中的自动开票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了新的自定义产品类型,该产品类型扩展了magento中的虚拟产品.现在,我想阻止在线付款的自动开票,例如.当订单包含至少一种自定义产品类型时为贝宝.使用此类产品的所有订单都必须手动开票.我该如何解决?

I have created new custom product type which extends virtual product in magento. Now I would like to block automatic invoicing for online payments eg. paypal when order contains at least one custom product type. All orders with such product have to be invoiced manually. How should I resolve this?

推荐答案

最好的方法是将观察者注册为在付款捕获过程中引发的事件,但不幸的是,我没有看到太多相关的事件.您可以尝试sales_order_invoice_save_before截取save(),但我对此并不感兴趣,因为它可能会使控制器无法理解为什么发票保存失败.

The best approach to this would be register an Observer to an Event thrown during the payment capture process, but I'm not seeing too many relevant ones unfortunately. You could try sales_order_invoice_save_before to intercept the save(), but I'm not keen on that as it may confuse the controller(s) as to why the invoice save failed.

浏览Paypal代码,您会在Mage_Paypal_Model_Ipn::_processOrder()中看到成功时它会调用$this->_registerPaymentCapture(),而后者又会调用$payment->registerCaptureNotification().

Looking through the Paypal code, you will see in Mage_Paypal_Model_Ipn::_processOrder() that it calls $this->_registerPaymentCapture() on success, which in turn calls $payment->registerCaptureNotification().

Mage_Sales_Model_Order_Payment::registerCaptureNotification($amount)如果尚不存在新的发票,并且付款是订单的全部金额,则创建一个新的发票.它使用_isCaptureFinal($amount)方法进行验证.

Mage_Sales_Model_Order_Payment::registerCaptureNotification($amount) creates a new invoice if one doesn't already exist and the payment is the full amount of the order. It uses the _isCaptureFinal($amount) method to verify this.

一种选择是扩展Mage_Sales_Model_Order_Payment并使用类似以下代码的代码覆盖_isCaptureFinal($amount):

One option would be to extend Mage_Sales_Model_Order_Payment and override _isCaptureFinal($amount) with code along the lines of:

foreach($this->getOrder()->getAllItems() as $oOrderItem){
  if($oOrderItem()->getProduct()->getTypeId() == 'your_custom_product_type'){
    return false;
  }
}
return parent::_isCaptureFinal($amountToCapture);

别忘了给父母的最后电话!

Don't forget the final call to parent!!

您可以在自定义模块中进行所有操作(如果需要,可以从 ModuleCreator 开始),然后插入将以下内容放入config.xml

You would do all this in a custom module (start with the ModuleCreator if you want), and insert the following into the config.xml

<global>
    <models>
        <modulename>
            <class>Namespace_Modulename_Model</class>
        </modulename>
        <sales>
            <rewrite>
                <order_payment>Namespace_Modulename_Model_Order_Payment</order_payment>
            </rewrite>
        </sales>
    </models>

使用标准免责声明,您在这里搞乱了资金交易,因此请确保您真的真的对其进行了彻底的测试.

Standard disclaimers apply, you're messing with funds transactions here, so makes sure that you test it really really thoroughly.

请注意,这种方法将适用于所有调用Mage_Sales_Model_Order_Payment::registerCaptureNotification($amount)的付款方式,而不仅限于Paypal.

Note that this approach will apply to all payment methods that call Mage_Sales_Model_Order_Payment::registerCaptureNotification($amount), not just Paypal.

祝你好运,
京东

Good Luck,
JD

这篇关于magento中的自动开票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆