Magento: modifying the newsletter module
The newsletter table of magento comes with first and last name fields but in the default setup only the email address is being saved. I'd like to make use of the first name field but am having a bit of trouble locating where the record is saved.
this is now what my form looks like:
<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="newsletter-validate-detail">
<div class="block-content">
<table>
<tr>
<td><label for="firstname"><?php echo $this->_开发者_如何学运维_('Name:') ?></label></td>
<td>
<div class="input-box">
<input type="text" name="firstname" id="firstname" title="<?php echo $this->__('Name') ?>" class="input-text" />
</div>
</td>
</tr>
<tr>
<td> <label for="newsletter"><?php echo $this->__('Email:') ?></label></td>
<td>
<div class="input-box">
<input type="text" name="email" id="newsletter" title="<?php echo $this->__('Sign up for our newsletter') ?>" class="input-text required-entry validate-email" />
</div>
</td>
</tr>
<tr>
<td></td>
<td>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Subscribe') ?>" class="button"><?php echo $this->__('Sign Up') ?></button>
</div>
</td>
</tr>
</table>
</div>
</form>
There's a similar post but I think it's now outdates as I can't seem to locate an _prepareSave function.
Can someone help in the right direction?
Thanks, Billy
A bit easier solution for adding custom fields to Magento newsletter subscriber object can be found here
The newsletter and subscriber tables don't contain firstname and lastname fields at least in the latest release, Magento EE 1.9.1.1.
If you want to add an additional field to the subscriber table, you should update the subscribe
method of Mage_Newsletter_Model_Subscriber
class (it receives just an e-mail address, you should pass additional arguments) and the controller Mage_Newsletter_SubscriberController
, action newAction
so that it extracts other fields from $_POST array and uses in the creation of newsletter subscription (search for the instruction $status = Mage::getModel('newsletter/subscriber')->subscribe($email)
).
精彩评论