Magento 将订阅者设置为第一位姓
当有人订阅 Magento 时事通讯时,我还希望他们填写自己的名字和姓氏。我已将两个输入字段添加到表单中。字段名称为“名字”和“姓氏”。
我将
在 newAction() 中扩展 Mage/Newsletter/controllers/SubscriberController.php:
我已在此处检索了帖子变量:
$email = (string) $this->getRequest()->getPost('email');
$firstname = (string) $this->getRequest()->getPost('firstname');
$lastname = (string) $this->getRequest()->getPost('lastname');
我在成功消息:
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$subscriber->setEmail("[email protected]");
$subscriber->setFirstname("ADAM");
$subscriber->setLastname("MOSS");
$subscriber->save();
我只想让名字和姓氏方法正常工作 - setEmail 部分工作完美。我查看了 Model/Subscriber.php 并发现没有设置订阅者名称的功能。
查看管理中的网格,我还注意到它显示“客户名字”和“客户姓氏”,因此我假设这些名称属于客户模型而不是订阅者模型。
有办法解决这个问题吗?我希望能够在订阅者订阅时事通讯时将客户名称分配给订阅者。我尝试了这篇文章中提到的观察者方法,但我认为存在同样的问题: 向 Magento 的订阅模块添加自定义字段
任何帮助将不胜感激。
When someone subscribes to the Magento newsletter I also want them to fill in their first and last name. I have added the two input fields to the form. The field names are 'firstname' and 'lastname'.
I'm going to extend Mage/Newsletter/controllers/SubscriberController.php
In newAction():
I have retrieved the post variables here:
$email = (string) $this->getRequest()->getPost('email');
$firstname = (string) $this->getRequest()->getPost('firstname');
$lastname = (string) $this->getRequest()->getPost('lastname');
I have added the following code after the success message:
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$subscriber->setEmail("[email protected]");
$subscriber->setFirstname("ADAM");
$subscriber->setLastname("MOSS");
$subscriber->save();
I just want to get the first and last name method working - the setEmail part works perfectly. I looked in Model/Subscriber.php and saw that there's no function for setting subscriber names.
Looking at the grid in the admin I also noticed that it says 'Customer First Name' and 'Customer Last Name' so I assume the names belong to the customer model rather than the subscriber model.
Is there a way around this? I want to be able to assign the customer name to the subscriber when they subscribe to the newsletter. I tried the observer method mentioned on this post, but I think the same issue exists: Adding a custom field to Magento's subscription module
Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看数据库中的 newsletter_subscriber 表。没有名字或姓氏。您仅在新闻通讯模型上设置这些字段。
订阅者模型中的 subscribe() 方法将订阅者与客户 ID 关联起来,因此网格确实显示客户的名字和姓氏。
如果您还希望与客户无关的订阅者也拥有这些字段,则应通过添加这两个字段来修改 newsletter_subscriber 数据库表。
Take a look at newsletter_subscriber table in the database. There is no firstname or lastname. You set these fields only on the newsletter model.
The subscribe() method from subscriber model associate the subscriber to customer id so the grid shows indeed the customer firstname and lastname.
If you want to have these fields also for subscribers that are not associated to cutomers you should modify the newsletter_subscriber database table by adding these two fields.
您必须创建以下内容的本地副本:
应用程序/代码/核心/Mage/Newsletter/controllers/SubscriberController.php
app/code/core/Mage/Newsletter/Model/Subscriber.php
在 app/code/core/Mage/Newsletter/controllers/SubscriberController.php 第 44 行后添加:
然后从: 更改
为:
现在在 app/code/core/ 中Mage/Newsletter/Model/Subscriber.php 在第 307 行编辑 subscribe 函数签名 from:
to:
在第 338 行后添加此内容:
并添加 getter 和 setter it:
您还需要将名字和姓氏列添加到 newsletter_subscriber,如其他 anwser 中所述。
You must create a local copy of:
app/code/core/Mage/Newsletter/controllers/SubscriberController.php
app/code/core/Mage/Newsletter/Model/Subscriber.php
In app/code/core/Mage/Newsletter/controllers/SubscriberController.php add after line 44:
Then change from:
to:
Now in app/code/core/Mage/Newsletter/Model/Subscriber.php edit the subscribe function signature at line 307 from:
to:
Add this after line 338:
And add the getters and setters for it:
You also need to add firstname and lastname columns to newsletter_subscriber as said in the other anwser.