【问题标题】:Getting Magento to send email when a payment is received收到付款后让 Magento 发送电子邮件
【发布时间】:2012-05-29 01:26:06
【问题描述】:

我不相信 Magento 有一种开箱即用的方法来发送电子邮件以在收到付款时通知所有者,那么有什么方法可以对其进行编程吗?

到目前为止,我已经阅读了this,但看起来它可能更专注于将电子邮件发送给客户而不是供应商;和this,但除了完全迷路(听起来是OP)之外,有人说接受的答案有点过时了,而且我不确定它是否是我需要的。

【问题讨论】:

    标签: magento


    【解决方案1】:

    基本上,您需要(惊喜)一个观察者模块来做到这一点。而且,这和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

    【讨论】:

    • 谢谢,我想说将准系统观察者转换为可工作的生产代码可能需要相当长的时间,而我的客户可能不想为此付费。你知道是否有可用的插件,因为我不想重新发明轮子。
    猜你喜欢
    • 1970-01-01
    • 2014-06-30
    • 2014-01-26
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 2018-02-09
    相关资源
    最近更新 更多