我正在LAMP堆栈环境中运行Magento 1.8.1.0(已修补的SUPEE-5344、SUPEE-1533、SUPEE-5994和SUPEE-6285)。
我已经安装了
Phoenix COD extension
(第1.0.8节)。
在我的开发环境中
缓存已禁用
.
我已经实现了一个模块
自动创建发票
根据付款方式的种类(COD、PayPal、信用卡等)。生成COD订单时,订单总数正确,但
在发票总额中,COD费用未显示
.
自动发票模块
这是我的模块的/etc/modules/文件:
<?xml version="1.0"?>
<config>
<modules>
<MyCompany_Autoinvoice>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Sales />
<Phoenix_CashOnDelivery />
</depends>
</MyCompany_Autoinvoice>
</modules>
</config>
我在
sales_order_save_after
事件
public function salesSaveAfter( $event ) {
$order = $event->getOrder();
$payment_method_code = $order->getPayment()->getMethodInstance()->getCode();
$is_Paypal = ( strpos( $payment_method_code, 'paypal' ) !== false ) ? true : false;
$is_Xpay = ( strpos( $payment_method_code, 'xpay' ) !== false ) ? true : false;
$is_Cod = ( strpos( $payment_method_code, 'cashondelivery' ) !== false ) ? true : false;
if ( $order->canInvoice() && ( $is_Paypal || $is_Xpay || $is_Cod ) ) {
$invoice = Mage::getModel( 'sales/service_order', $order )->prepareInvoice();
if ( ! $invoice->getTotalQty() ) {
Mage::throwException( $this->__( 'Cannot create an invoice without products.' ) );
return;
}
$invoice->register();
$transactionSave = Mage::getModel( 'core/resource_transaction' )
->addObject( $invoice )
->addObject( $invoice->getOrder() );
$transactionSave->save();
} else {
return;
}
}
还有一些注释
您是否可以看到我的模块取决于Phoenix_CacheOnDelivery,因此该函数应在任何观察者的函数之后触发。
如果我手动生成发票,一切正常。
如果我以编程方式启动一个脚本来生成第二张发票(对于一个订单,第一张发票没有COD费用),那么发票只生成COD费用:所以一切都很好。