在magento系統中,預設是在支付成功後發送確認訂單郵件的,但是有時我們會碰到支付不成功的情
況或者客戶不想支付,那我們怎樣才能在支付前就發送訂單郵件呢?首先我們開啟appcodecoreMageCheckoutModelType檔案夾下
的Onepage.php檔案,找到saveOrder()方法,可以看到有這麼幾句:
$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());
}
}
可以發現magento系統是在儲存訂單資料後就立即跳轉到支付URL上去了,而如果沒有支付跳轉,則會發送郵件。那我們現在就可以把
if(!$redirectUrl){
try {
$order->sendNewOrderEmail();
} catch (Exception $e) {
Mage::logException($e);
}
}
中的if條件注釋掉,這樣就可以保證無論是否存在支付跳轉,系統都會發送訂單確認郵件。