我在LAMP堆栈环境中运行Magento 1.8.1.0(修补了SUPEE-5344,SUPEE-1533,SUPEE-5994,SUPEE-6285)。 我已经安装了Phoenix COD extension(v.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费用:所以一切都很好。
答案 0 :(得分:1)
我自己找到了解决方案!
问题:Phoenix_CashOnDelivery通过附加sales_order_payment_place_end
之后的事件sales_order_save_after
来添加COD费用,因此它们在发票生成中设置为0的顺序时间。
解决方案:只需将事件更改为在sales_order_place_after
中收听。
另外,sales_order_save_after
被调用的次数要多很多次,所以代码优化了!耶!
我希望这对那里的人有用。