如何在magento中发送基于类别的订单电子邮件? [英] How to send category based order emails in magento?
问题描述
我的magento网站中有两个根目录类别.一个是家用产品",另一个是办公产品".
I have two root categories in my magento site. One is "Home Products" and the other is "Office products".
这两个根类别也有一些子类别.
我想将与家用产品"相关的订单发送到此电子邮件地址"email_home@example.com",
并将办公产品"的相关订单发送到此电子邮件地址"email_office@example.com".
These two root categories have some sub categories also.
I want to send "Home Products" related orders to this email address "email_home@example.com",
And to send "Office Products" related orders to this email address "email_office@example.com".
我将如何做?
推荐答案
我建议您编写自己的Observer进行订购.
I suggest you to write own Observer to order.
sales_order_place_after
活动最适合您的目的.
如果买方只能从1个类别中添加商品到购物车中.
If buyer can add to shopping cart items only from 1 cateogry.
您的模块应该:
- 通过观察者获得订单.
- 获取订单的第一项并获取其类别
- 根据类别选择电子邮件
发送电子邮件
public function sendOrder(){
$order = $observer->getEvent()->getOrder();
...
//Implement logic here
...
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('your_template');
$emailTemplateVariables = array();
$emailTemplateVariables['order'] = $order;
$emailTemplate->setSenderName('Your shops name');
$emailTemplate->setSenderEmail('addres@from.com');
$emailTemplate->setTemplateSubject(Subject');
$emailTemplate->send('to@addres.com','Name', $emailTemplateVariables);
}
更新1
首先,我坚持要求您在评论区域中看到我提供的链接.
First of all I insist that you see the link I provide in the comments area.
然后: 要创建模块:
-
在app/etc/modules/Company_Module.xml文件中创建.内容与此类似:
Create in app/etc/modules/ Company_Module.xml file. With the content similiar to this one:
真的 当地的 这告诉magento,在app/code/local/Company/Module中有一些值得关注的事情.
true local This eill tell magento, that in app/code/local/Company/Module there is something interesting to watch.
创建正确的文件夹和文件结构. 对于您的模块,我认为就足够了:
Create proper folder and file structure. For you module I think it would be enough:
Company
-Module
--etc
---config.xml
--Model
---Observer.php
--Helper
---Data.php
config.xml:
config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Company_Module>
<version>0.1.0</version>
</Company_Module>
</modules>
<global>
<models>
<company_module>
<class>Company_Module_Model</class>
</company_module>
</models>
<helpers>
<cmod>
<class>Company_Module_Helper</class>
</cmod>
</helpers>
<events>
<sales_order_place_after>
<observers>
<sales_order_place_after_observer>
<class>company_module/observer</class>
<method>handleOrder</method>
</sales_order_place_after_observer>
</observers>
</sales_order_place_after>
</events>
</global>
</config>
Data.php-它为空,但应该为空.
Data.php - It is empty but it should be.
class Company_Module_Helper_Data extends Mage_Core_Helper_Abstract{
}
Observer.php
Observer.php
class Company_Module_Model_Observer{
public function handleOrder($observer){
$order = $observer->getEvent()->getOrder();
...
//Implement logic here
...
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('your_template');
$emailTemplateVariables = array();
$emailTemplateVariables['order'] = $order;
$emailTemplate->setSenderName('Your shops name');
$emailTemplate->setSenderEmail('addres@from.com');
$emailTemplate->setTemplateSubject(Subject');
$emailTemplate->send('to@addres.com','Name', $emailTemplateVariables);
}
}
这篇关于如何在magento中发送基于类别的订单电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!