Reputation: 337
I am having some problems with a module i wrote. I have created observer that upload XML and send notification for admin.
I have testet with 2 events: <sales_order_place_after>
and <sales_order_save_after>
.
The problem is that i offer 2 types of payment option (bank transfer and creditcard). One change state immediately to [New]
(banktransfer) and other is payment by credit card which goes to state [Processing]
before payment is captured and then after payment has been captured [New]
.
This gives me problem as because i only want to upload XML once for every order and <sales_order_save_after>
trigger event for every order update and <sales_order_place_after>
only gets triggered once and and not when payment have been captured.
I think solution would be to use same event as Magento use to send out order confirmation mail. Which event is that?
This is my observer that does not work correct.
public function salesOrderSaveAfter($observer)
{
....
if ($orderStatus == 'pending' || $orderStatus == 'bank_transfer' ) {
Any suggestions to solve this problem?
Upvotes: 3
Views: 4839
Reputation: 2125
Order confirmation emails are not triggered from an event. They are triggered from the saveOrder()
method within class Mage_Checkout_Model_Type_Onepage
.
You should see some code like;
/**
* 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 && $order->getCanSendNewEmailFlag()) {
try {
$order->sendNewOrderEmail();
} catch (Exception $e) {
Mage::logException($e);
}
}
This basically sends the confirmation email as soon as the order is placed unless the payment method has a redirect URL (i.e. Third party payment pages like PayPal standard).
If you do not want the email to be sent for a particular payment method you could override the function above and make it check the payment type;
if (!$redirectUrl && $order->getPayment()->getMethod() != 'your_payment_method' && $order->getCanSendNewEmailFlag()) {
try {
$order->sendNewOrderEmail();
} catch (Exception $e) {
Mage::logException($e);
}
}
To trigger the sending of a confirmation email from your observer, simply load the order object and call $order->sendNewOrderEmail();
.
Upvotes: 2