我创建了一个事件观察器,它将在订单完成时发送电子邮件。 当从category1订购产品时,我发送电子邮件至email_address1,并在从cateogory2订购产品时向email_address2发送电子邮件。因此,我为此创建了一个观察者事件。
但是当我点击“下订单”按钮时没有任何反应。有什么问题?
在magento / app / etc / modules / Custom_Email.xml中:
<?xml version="1.0"?>
<config>
<modules>
<Custom_Email>
<codePool>local</codePool>
<active>true</active>
</Custom_Email>
</modules>
</config>
在magento / app / code / local / Custom / Email / etc / config.xml中:
<?xml version="1.0"?>
<config>
<global>
<models>
<customemail>
<class>Custom_Email_Model</class>
</customemail>
</models>
<events>
<sales_order_place_after>
<observers>
<custom_email_order_observer>
<type>singleton</type>
<class>customemail/order_observer</class>
<method>sendOrder</method>
</custom_email_order_observer>
</observers>
</sales_order_place_after>
</events>
</global>
</config>
in magento / app / code / local / Custom / Email / Model / Order / Observer.php:
<?php
class Custom_Email_Model_Order_Observer
{
public function __contruct()
{
}
/**
* Exports new orders to an xml file
* @param Varien_Event_Observer $observer
* @return Feed_Sales_Model_Order_Observer
*/
public function sendOrder($observer){
$order = $observer->getEvent()->getOrder();
$cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
echo $cat_id;
//Implement logic here
...
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('rehab');
$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);
echo 'email sent';
}
}
?>
所以任何人都知道问题在哪里?
答案 0 :(得分:1)
图层在订单上下文中不存在,选择产品的类别也不可用作报价或订单商品的属性。这是Magento的一个已知缺陷,不幸的是它限制了分割。