Magento: Sending Order Emails Only to Admin
As a senior developer and Magento expert, I often receive inquiries regarding customization of order email settings. Nico’s question about sending order emails only to the admin is a common requirement in scenarios where customer communication is handled through an external system.
Understanding Magentoâs Default Behavior
By default, Magento sends multiple order confirmation emails: one to the customer with order details and shipping information, another to the store owner (admin) with order status updates. The system does not provide an out-of-the-box configuration option to send only admin emails for new orders.
Overriding Core Files: A Caution
Some developers suggest overriding the core Mage_Sales_Model_Order::sendEmail method in local files to achieve this functionality. However, I strongly advise against this approach.
- Security Risks: Modifying core files violates Magento’s structure and could lead to security vulnerabilities.
- Upgrade Compatibility: Future upgrades will overwrite your changes, causing potential issues.
- Support Implications: Changes to the core may void warranty or support from the Magento development community and official support channels.
The Recommended Solution: Using an Event Observer
The cleanest solution involves creating a custom module with an event observer. This approach allows you to intercept the sales_order_place_after event, which triggers after a new order is placed but before any emails are sent.
Creating a Custom Module (Step-by-Step)
-
Create your module folder structure: In
app/code/local, create a new namespace and module directory following the Magento naming convention:local/YourCompany/SendOrderToAdmin. -
Define your module configuration: Create an
etc/config.xmlfile with basic module information:
<?xml version="1.0"?>
<config>
<modules>
<YourCompany_SendOrderToAdmin>
<active>true</active>
<codePool>local</codePool>
<depends>
<!-- Add any dependencies here -->
</depends>
</YourCompany_SendOrderToAdmin>
</modules>
</config>
- Create the event observer: In
app/code/local/YourCompany/SendOrderToAdmin/etc/events.xml, define your observer:
<?xml version="1.0"?>
<events>
<sales_order_place_after>
<observers>
<yourcompany_sendordertoadminObserver>
<type>singleton</type>
<class>YourCompany_SendOrderToAdmin_Model_Observer</class>
<method>stopSendingCustomerEmail</method>
</yourcompany_sendordertoadminObserver>
</observers>
</sales_order_place_after>
</events>
- Implement the observer method (Model Observer.php): In
app/code/local/YourCompany/SendOrderToAdmin/Model/Observer.php:
class YourCompany_SendOrderToAdmin_Model_Observer
{
public function stopSendingCustomerEmail($observer)
{
$order = $observer->getEvent()->getOrder();
if ($order) {
// Remove the customer from the email recipients list
$order->setCustomerIsGuest(true);
}
}
}
This observer method removes the customer from the email recipients using setCustomerIsGuest, ensuring that only admin emails are sent.
Conclusion
While Magento’s default settings for order emails cannot be configured to send only admin notifications, a clean and safe solution involves creating a custom module with an event observer. This approach allows you to intercept the order placement process without modifying core files or risking upgrade compatibility issues.
Remember to clear your cache after installing this module and test it thoroughly on a staging environment before deploying it to your live Magento site.
For more advanced Magento customizations and expert advice, consider reaching out to our team at Laravel Company. We specialize in providing high-quality Magento development services tailored to meet the unique needs of e-commerce businesses.