【发布时间】:2013-12-15 23:49:14
【问题描述】:
我正在尝试基于this answer. 创建一个观察者模块,最终结果是在购买特定产品并收到付款后发送电子邮件。我希望通过设置观察者在订单完成时触发来实现这一点。 到目前为止,我已经根据我在上面的链接中读到的内容实现了观察者,并要求它通过电子邮件向我发送订单信息。到目前为止,它完全没有做任何事情。难道我做错了什么?我对所提供的内容所做的唯一修改如下:
/app/code/local/Electricjesus/Notifyowner/Model/Observer.php
<?php
class Electricjesus_Notifyowner_Model_Observer
{
public function notifyOwnerEvent($observer)
{
// parameters you can get from the $observer parameter:
// array(’payment’ ? $this, ‘invoice’ ? $invoice)
$payment = $observer->getPayment();
$invoice = $observer->getInvoice();
// derivative data
$order = $invoice->getOrder(); // Mage_Sales_Model_Order
$email = array(
'to' => 'me@mydomain.com',
'subject' => 'Confirmed Purchase',
'message' => 'Hello World. This is a test. $order = ' . $order,
'headers' => 'From: My Store'
);
mail($email['to'], $email['subject'], $email['subject'], $email['headers']);
/*
- build data
- build email structure
- send email via any php mailer method you want
*/
return $this; // always return $this.
}
}
我还尝试使用file_put_contents('observer_log.txt', '$order = '.$order); 将相关信息写入文件,但没有效果。任何建议都将不胜感激。我为我的笨拙道歉。
编辑:我的 config.xml [更新] 文件如下:
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Notifyowner>
<version>0.1.0</version>
</Electricjesus_Notifyowner>
</modules>
<global>
<models>
<notifyowner>
<class>Electricjesus_Notifyowner_Model</class>
</notifyowner>
</models>
<events>
<sales_order_invoice_pay>
<observers>
<notifyOwnerEvent>
<class>notifyowner/observer</class>
<method>notifyOwnerEvent</method>
</notifyOwnerEvent>
</observers>
</sales_order_invoice_pay>
</events>
</global>
</config>
编辑2:我已经修改了我的config.xml它曾经是
<events>
<sales_order_payment_pay>
<observers>
我将事件更改为您在上面看到的内容,尽管所有变量都显示为空,因此在发送电子邮件之前我无法查看订单是否包含我关心的产品。
【问题讨论】:
-
你能添加你的 config.xml 文件吗?
-
我进行了编辑以包含 config.xml。这与我链接的问题完全相同。
-
notifyOwnerEvent方法是否被执行?尝试添加Mage::log()或die() -
我真的不知道。不幸的是,我对 Magento 还是很陌生。我在哪里添加这些行?我一直在检查日志,但没有看到对我创建的文件的引用。