0

I need to check the status of an order 30 minutes after it is placed, and send an email accordingly.

I tried running magento cron but it executes every 30 minutes

In config.xml :

<crontab>
    <jobs>
      <send_mail_sms>
          <schedule>
                <cron_expr>0 30 * * * *</cron_expr>
            </schedule>
            <run> 
                <model>namespace_module/cron::sendMail</model>
            </run>
        </send_mail_sms>
    </jobs>
</crontab>  

I need to run the Cron only once and run it from the observer of sales_order_place_after where i can provide the orderid.

  • 2
    you can make the cron run every minute and inside the script of the cron just retrieve the orders places between 29 and 30 minutes before the cron ran. You cannot trigger a cron from an event observer. – Marius Nov 25 '16 at 8:53
  • thank you @Marius for replying. how to retrieve the orders places between 29 and 30 minutes before the cron ran. – subodhkalika Nov 25 '16 at 8:59
1

Based on the comments...
You can check for order place between 29 and 30 minutes ago like this:

$now = Mage::app()->getLocale()->date();
$past29Minutes = Mage::app()->getLocale()->date()->subMinute(29);
$past30Minutes = Mage::app()->getLocale()->date()->subMinute(30);
$orders = Mage::getModel('sales/order')->getCollection();
    ->addFieldToFilter('created_at', array('date' => true, 'to' => $past30Minutes))
    ->addFieldToFilter('created_at', array('date' => true, 'from' => $past29Minutes));

But you will have to mark the order somehow after you send the email so you won't process it again. Then you can add an other filter to the collection to exclude the ones that already have the e-mail sent.

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.