How to prevent new order email from frontend and allow it only from backend for a particular website?
-
16-10-2019 - |
Pergunta
We have a multi-store ecommerce site. Each store is separate website. For one particular website (say website with id '6'), the new order email should not be triggered while the customer places the order.
But when the admin checks the order in the admin panel and then push the "sent email" button, now the email should go to the customer.
What I tried:
overriden Mage_Core_Model_Email_Template::sendTransactional
method and replaced $this->setSentSuccess($this->send($email, $name, $vars));
with
if($storeId == 6){
$this->setSentSuccess(false);
} else{
$this->setSentSuccess($this->send($email, $name, $vars));
}
But this won't check if it is invoked from frontend or backend. Can someone give me a hint?
Solução
I'd go the route of setting up an event-observer on sales_order_save_after
which handles orders placed on the front-end as opposed to sales_order_place_after
which handles backend order placement.
Outras dicas
You shouldn't rewrite Mage_Core_Model_Email_Template::sendTransactional
. That is used for ALL e-mails sent from Magento.
If you want only the new order e-mail to not be sent rewrite Mage_Sales_Model_Order::sendNewOrderEmail()
.
In your new class make the method look like this:
public function sendNewOrderEmail() {
if (Mage::app()->getStore()->getId() == 6) {
return $this;
}
return parent::sendNewOrderEmail();
}
This is just an example. Don't hard code the value 6
. You can make a config setting where you can select the store views for which the e-mail is not sent.