In the magento system, the confirmation order email is sent by default after the payment is successful, but sometimes we encounter the payment failure.
If the customer doesn't want to pay, how can we send the order email before the payment? First, open the appcodecoremagecheckoutmodeltype folder.
In the onepage. php file, find the saveorder () method, you can see the following sentence:
$ Order = $ service-> getorder ();
If ($ order ){
Mage: dispatchevent ('checkout _ type_onepage_save_order_after ',
Array ('order' => $ order, 'quote' => $ this-> getquote ()));
/**
* A flag to set that there will be redirect to third party after confirmation
* Eg: PayPal standard IPN
*/
$ Redirecturl = $ this-> getquote ()-> getpayment ()-> getorderplaceredirecturl ();
/**
* We only want to send to customer about new order when there is no redirect to third party
*/
If (! $ Redirecturl ){
Try {
$ Order-> sendneworderemail ();
} Catch (exception $ e ){
Mage: logexception ($ E );
}
}
// Add order information to the session
$ This-> _ checkoutsession-> setlastorderid ($ order-> GETID ())
-> Setredirecturl ($ redirecturl)
-> Setlastrealorderid ($ order-> getincrementid ());
// As well a billing agreement can be created
$ Agreement = $ order-> getpayment ()-> getbillingagreement ();
If ($ agreement ){
$ This-> _ checkoutsession-> setlastbillingagreementid ($ agreement-> GETID ());
}
}
It can be found that the magento system jumps to the payment URL immediately after saving the order data. If there is no payment jump, an email will be sent. Now we can
If (! $ Redirecturl ){
Try {
$ Order-> sendneworderemail ();
} Catch (exception $ e ){
Mage: logexception ($ E );
}
}
If condition comment out, so that the system will send an order confirmation email no matter whether there is a payment jump.