如何将名称添加到Magento 1通讯

时间:2018-06-24 14:40:18

标签: magento newsletter

我一直在尝试将订阅者的名字添加到Magento通讯中。我在Google上找不到任何东西。我看过Adding a custom field to Magento's subscription module ,但对我来说还不清楚。我在newsletter_subscriber表中的字段称为数据库和管理网格中的subscriber_firstname

我创建了一个像这样的模块:

在app / etc / modules / Afe_Newslettername.xml中

<?xml version="1.0"?>
<config>
    <modules>
        <Afe_Newslettername>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Newsletter/>
            </depends>
        </Afe_Newslettername>
    </modules>
</config>

在app / code / local / Afe / Newslettername / etc / config.xml中

<?xml version="1.0"?>
<config>    
<global>
<frontend>
    <events>
        <newsletter_subscriber_save_before>
            <observers>
                <afe_newslettername>
                    <class>afe_newslettername/observer</class>
                    <method>newsletterSubscriberSave</method>
                </afe_newslettername>
            </observers>
        </newsletter_subscriber_save_before>
    </events>
</frontend>
</global>
</config>

在app / code / local / Afe / Newslettername / Model / Observer.php中

<?php
class Afe_Newslettername_Model_Observer
{
public function newsletterSubscriberSave(Varien_Event_Observer $observer)
{
    $subscriber = $observer->getEvent()->getSubscriber();
    $name = Mage::app()->getRequest()->getParam('subscriber_firstname');

    $subscriber->setSubscriberName($name);

    return $this;
}
}

...但是该名称不会保存到数据库或显示在管理员通讯订阅者网格中。

我想念什么?

更新:

我将config.xml更改为:

<?xml version="1.0"?>
<config>
  <modules>
    <Afe_Newslettername>
      <version>1.0.0.0</version>
    </Afe_Newslettername>
  </modules>
  <global>
    <models>
      <afenewsletters>
        <class>Afe_Newslettername_Model</class>
      </afenewsletters>
    </models>
  </global>
       <events>
        <newsletter_subscriber_save_before>
            <observers>
                <add_name>
                    <class>afe_newslettername/observer</class>
                    <method>newsletterSubscriberSave</method>
                </add_name>
            </observers>
        </newsletter_subscriber_save_before>
       </events>
</config>

但是现在我收到此错误:

Warning: include(Mage/Afe/Newslettername/Model/Observer.php): failed to open stream: No such file or directory  in /home/www/public_html/lib/Varien/Autoload.php on line 94
Warning: include(): Failed opening 'Mage/Afe/Newslettername/Model/Observer.php' for inclusion (include_path='/home/www/public_html/app/code/local:/home/www/public_html/app/code/community:/home/www/public_html/app/code/core:/home/www/public_html/lib:.:/opt/cpanel/ea-php70/root/usr/share/pear')  in /home/www/public_html/lib/Varien/Autoload.php on line 94

不确定为什么要在Mage文件夹中查找?

1 个答案:

答案 0 :(得分:0)

我认为您的事件声明代码中存在一些问题。请尝试以下代码。希望它能起作用。

config.xml文件:

<newsletter_subscriber_save_before>
    <observers>
        <afe_newslettername>
            <class>Afe_Newslettername_Model_Observer</class>
            <method>newsletterSubscriberSave</method>
        </afe_newslettername>
    </observers>
</newsletter_subscriber_save_before>

Observer.php文件:

public function newsletterSubscriberSave($observer)