Magento 1.7 – Send New Order Email with Cron Job Only

cronmagento-1.7orders

I want to disable the default new order email sending functionality and instead I want to send this email with cron job only. How can I identify, if the new order is placed and send email ?

Best Answer

Here is a simple way of doing it.
Rewrite the method Mage_Sales_Model_Order::sendNewOrderEmail and make it look like this:

public function sendNewOrderEmail() {
    if (!$this->getForceSendEmail()) {
        return $this;
    }
    //do what it does by default
    parent::sendNewOrderEmail();
}

This will prevent the e-mail sending from the website because getForceSendEmail will always return false (unless you tell it not to).

Now, when running the cron to send e-mails you will have to do somthing like this:

$orders = ....; //retrieve orders somehow
$foreach ($orders as $order) {
    $order->setForceSendEmail(true); //tell the order to force the e-mail
    $order->sendNewOrderEmail();
}
Related Topic