How to disable email sending when programatically creating an order in Magento
2 Comments 23rd JUL 2010 | Posted by Vedran Subotic in Magento

Here is a little snippet of code that can come in handy if you are like me handling a task of programatically creating an order in Magento. My issue was that I had to disable emails beeing sent out to the customers, while at the same time leave the normal frontend process. Thus I could not just go under Magento admin System > Congifuration and disable email sending from there.
Here is the sample line code you just need to place above final $order->save() or possibly $checkout->saveOrder():
Mage::app()->getStore()->setConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_ENABLED, "0");
To post code in comments, place your code inside [code] and [/code] tags.


















July 23rd, 2010 at 13:56
nice. I assume it needs to be turned back on again after saving the order?
July 26th, 2010 at 6:08
@Jonathan
Config is not saved so you don’t need to turn anything back. This code is merely used to overide saved config value at the moment you need it.