【发布时间】:2012-05-29 01:26:06
【问题描述】:
我不相信 Magento 有一种开箱即用的方法来发送电子邮件以在收到付款时通知所有者,那么有什么方法可以对其进行编程吗?
到目前为止,我已经阅读了this,但看起来它可能更专注于将电子邮件发送给客户而不是供应商;和this,但除了完全迷路(听起来是OP)之外,有人说接受的答案有点过时了,而且我不确定它是否是我需要的。
【问题讨论】:
标签: magento
我不相信 Magento 有一种开箱即用的方法来发送电子邮件以在收到付款时通知所有者,那么有什么方法可以对其进行编程吗?
到目前为止,我已经阅读了this,但看起来它可能更专注于将电子邮件发送给客户而不是供应商;和this,但除了完全迷路(听起来是OP)之外,有人说接受的答案有点过时了,而且我不确定它是否是我需要的。
【问题讨论】:
标签: magento
基本上,您需要(惊喜)一个观察者模块来做到这一点。而且,这和in one of the links you provided的工作完全一样。
要制作一个准系统的观察者模块,你只需要三个文件:
/app/etc/modules/Electricjesus_Notifyowner.xml
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Notifyowner>
<active>true</active>
<codePool>local</codePool>
</Electricjesus_Notifyowner >
</modules>
</config>
/app/code/local/Electricjesus/Notifyowner/etc/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_payment_pay>
<observers>
<notifyOwnerEvent>
<class>notifyowner/observer</class>
<method>notifyOwnerEvent</method>
</notifyOwnerEvent>
</observers>
</sales_order_payment_pay >
</events>
</global>
</config>
/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
$ownerEmail = 'owner@shop.com';
/*
- build data
- build email structure
- send email via any php mailer method you want
*/
return $this; // always return $this.
}
}
您还可以使用其他事件代替sales_order_payment_pay(请参阅config.xml)。有关事件的半完整列表及其参数,请参阅 this list。在this document 上,有一些技术可以检查/获取当前事件列表及其参数的更新。
我建议使用 Zend_Mail 在观察者内部处理邮件。没什么特别的,我只是偏爱 Zend 的东西。
http://framework.zend.com/manual/en/zend.mail.html
--- 编辑
如果您想要一个现成的扩展来执行此操作(以及更多),并且您不介意为此付费,您可以查看:
http://www.magentocommerce.com/magento-connect/admin-email-notifications.html
【讨论】: