1

In Mage 1.5.1.0 with the ASchroder.com SMTP Pro Email extension, I have things properly configured, as far as I can tell, because when an order is placed and the status is pending* I get the order email. However, when the status is immediately processing*, I do not get the order email.

*Immediately set status, no further action taken, either via Magento or the related payment processor gateway.

Is this behavior by default? If yes, how can I set Mage to send email when an order with ANY status is submitted?

1

Just updating the status/state of the order does not trigger any emails to be sent. The most relevant code is in

app/code/core/Mage/Sales/Model/Order.php

protected function _setState($state, $status = false, $comment = '', $isCustomerNotified = null, $shouldProtectState = false)
{
    // attempt to set the specified state
    if ($shouldProtectState) {
        if ($this->isStateProtected($state)) {
            Mage::throwException(Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state));
        }
    }
    $this->setData('state', $state);

    // add status history
    if ($status) {
        if ($status === true) {
            $status = $this->getConfig()->getStateDefaultStatus($state);
        }
        $this->setStatus($status);
        $history = $this->addStatusHistoryComment($comment, false); // no sense to set $status again
        $history->setIsCustomerNotified($isCustomerNotified); // for backwards compatibility
    }
    return $this;
}

which does not include any calls to the email sending code. This is usually handled by each individual payment method and can differ substantially. Some will send the order confirmation email, some will send the invoice confirmation email only. If your payment method does not send any emails at all this seems like an oversight during development. For example in

/app/code/core/Mage/Paypal/Model/Express/Checkout.php you will find $order->sendNewOrderEmail() to trigger the email sending part.

If all payment methods are not sending any emails check your email sending settings under System > Configuration > Sales Email if this is not disabled it is time to further check your email configuration and server/Magento error logs for further clues as to why no emails are being sent once you have confirmed what your code is meant to send.

| improve this answer | |
1

You can use Magento event/observer.
1. Add observer for sales_order_save_after event:

<global>
    <events>
        <sales_order_save_after>
            <observers>
                <some_module>
                    <class>Some_Module_Model_Observer</class>
                    <method>salesOrderSaveAfter</method>
                </some_module>
            </observers>
        </sales_order_save_after>
    </events>
</global>

2.Send email in the observer if new order email was not sent already:

class Some_Module_Model_Observer
{
    public function salesOrderSaveAfter($observer)
    {
        /**
         * @var $order Mage_Sales_Model_Order
         */
        $order = $observer->getDataObject();
        if(!$order->getEmailSent()){
            try{
                $order->sendNewOrderEmail();
                $historyItem = Mage::getResourceModel('sales/order_status_history_collection')
                    ->getUnnotifiedForInstance($order, Mage_Sales_Model_Order::HISTORY_ENTITY_NAME);
                //track history
                if ($historyItem) {
                    $historyItem->setIsCustomerNotified(1);
                    $historyItem->save();
                }
            }catch (Exception $e){
                //some exception handling
            }
        }
    }
}

By the way sales_order_save_after event fires when order status changed via admin panel or payment module and your observer sends email if order confirmation email not sent.

| improve this answer | |
  • Thanks. But is it default behavior NOT to send email when status is processing? – Gaia Jan 16 '14 at 9:34
  • 1
    @Gaia, it is not correct behavior. Normally Magento should send automatically one "Order Confirmation Email" when order state changed to processing. Maybe there is some issues with your store configuration, I can't figure out, but you can try the solution given above. – mageUz Jan 16 '14 at 10:54
  • How would I go about installing it? I found inchoo.net/ecommerce/magento/…, could I start from there? – Gaia Jan 23 '14 at 17:20
  • Seems like you should do some troubleshooting before resorting to building an extension that patches something that should work fine by default. This is a good guide on debugging Magento. magento.stackexchange.com/questions/428/… – jesseconnr Feb 14 '14 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.