At customer registration:
By default, Magento uses the supplied customer name to auto-populate the default shipping / billing information. We are a B2B, and need to gather that information separately at the time of registration. Additionally, we need to get the address fax number.
These are not custom attributes (already made a bunch of those, and have integrated them into a greatly expanded registration form), but the standard first name, last name and fax fields associated with a customer address.
I've attempted this:
<span class="msg">Default shipping and billing information.</span>
<ul class="form-list">
<li class="fields">
<div class="field billing_name">
<label for="billing_firstname" class="required"><em>*</em><?php echo $this->__('First Name') ?></label>
<div class="input-box">
<input type="text" name="billing_firstname" id="billing_firstname" value="<?php echo $this->htmlEscape($this->getFormData()->getFirstName()) ?>" title="<?php echo $this->__('First Name') ?>" class="input-text required-entry" />
</div>
</div>
<div class="field billing_name">
<label for="billing_lastname" class=""><em>*</em><?php echo $this->__('Last Name') ?></label>
<div class="input-box">
<input type="text" name="billing_lastname" id="billing_lastname" value="<?php echo $this->htmlEscape($this->getFormData()->getLastName()) ?>" title="<?php echo $this->__('Last Name') ?>" class="input-text required-entry" />
</div>
</div>
</li>
but I'm not clear what the input name should be. Whatever the case, the account names are used instead.
Looking for a little information on maybe the "name" of the form fields required, and some method of disabling the auto-populate feature, should that also be required.
cheers
Looking at this a little more closely.
I'm overriding the mage/customer/controller/accountController.php :: createPostAction() and I see in the controller the location where the form is processed and populated as a customer entity.
I'm trying something like this
if ($this->getRequest()->getPost('create_address')) {
/* @var $address Mage_Customer_Model_Address */
$address = Mage::getModel('customer/address');
/* @var $addressForm Mage_Customer_Model_Form */
$addressForm = Mage::getModel('customer/form');
$addressForm->setFormCode('customer_register_address')
->setEntity($address);
$addressData = $addressForm->extractData($this->getRequest(), 'address', false);
$addressErrors = $addressForm->validateData($addressData);
if ($addressErrors === true) {
$address->setId(null)
->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
$addressForm->compactData($addressData);
// attempting to jam vars into address obj
$address['_data']['firstname'] = $this->getRequest()->getPost('billing_firstname');
$address['_data']['lastname'] = $this->getRequest()->getPost('billing_lastname');
$address-['_data']['fax'] = $this->getRequest()->getPost('billing_fax');
// end
Mage::log('createPostAction, after var jam: '. print_r($address, true ) );
$customer->addAddress($address);
$addressErrors = $address->validate();
if (is_array($addressErrors)) {
$errors = array_merge($errors, $addressErrors);
}
} else {
$errors = array_merge($errors, $addressErrors);
}
}
When i log this out:
2012-12-18T01:51:10+00:00 DEBUG (7): createPostAction, after var jam: Mage_Customer_Model_Address Object
(
[_customer:protected] =>
[_eventPrefix:protected] => customer_address
[_eventObject:protected] => customer_address
[_resourceName:protected] => customer/address
[_resource:protected] =>
[_resourceCollectionName:protected] => customer/address_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[entity_type_id] => 2
[entity_id] =>
[is_default_billing] => 1
[is_default_shipping] => 1
[firstname] => Chirp // customer firstname
[lastname] => Anaplex // customer lastname
[company] => some agency
[street] => 2345 somewhere dr
[city] => somecity
[country_id] => US
[region] =>
[region_id] => 44
[postcode] => 84151
[telephone] => 123-123-1233
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] => entity_id
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
The form variables are getting passed successfully ( i see them in the log ), but I seem to be unable to insert them into the address object this way. I get the following Notice:
2012-12-18T16:39:39+00:00 ERR (3): Notice: Indirect modification of overloaded element of Mage_Customer_Model_Address has no effect in /root/namespace/module/controllers/AccountController.php on line 79
If this is "Indirect" - what is the "Direct" method?
Anyone?
Derp. This works.
$address->setData('firstname', $this->getRequest()->getPost('billing_firstname'));
$address->setData('lastname', $this->getRequest()->getPost('billing_lastname'));
$address->setData('fax', $this->getRequest()->getPost('billing_fax'));
Anyone else needing this?
Add form fields into your/theme/template/persistent/forms/register.phtml
override Mage_Customer_AccountController
setData('key', 'value')
in yourmodule/customer/controller/accountController.php :: createPostAction()