magento sales_order_place_after观察器不起作用 [英] magento sales_order_place_after observer not working

查看:21
本文介绍了magento sales_order_place_after观察器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个事件观察器,该观察器将在订单完成时发送电子邮件.我从category1订购产品时将电子邮件发送到email_address1,而从cateogory2订购产品时将电子邮件发送到email_address2.因此,我为此创建了一个观察者事件.

I have created an event observer that will send email on order completion. I am sending email to email_address1 when a product is ordered from the category1 and sending email to email_address2 when a product is ordered from the cateogory2. Therefore I have created an observer event for this.

但是,当我单击下订单"按钮时,没有任何反应.有什么问题吗?

But when I click on the "Place Order" button nothing happens. What is the problem?

在 magento/app/etc/modules/Custom_Email.xml 中:

in 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中:

in 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>

在magento/app/code/local/Custom/Email/Model/Order/Observer.php中:

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';      
 }
 }
 ?>

所以有人知道问题出在哪里吗?

So any one know where is the problem?

推荐答案

订单上下文中不存在该层,从中选择产品的类别也不能用作报价或订单项的属性.这是Magento中的已知缺陷,很不幸地限制了细分.

The layer does not exist in the order context, nor is the category from which the product was selected available as a property of quote or order items. It's a known deficiency in Magento which unfortunately limits segmentation.

这篇关于magento sales_order_place_after观察器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆