在客户注册时:
默认情况下,Magento使用提供的客户名称自动填充默认的送货/结算信息。我们是B2B,需要在注册时单独收集这些信息。此外,我们需要获取地址传真号码。
这些不是自定义属性(已经成为一组,并将它们集成到一个大大扩展的注册表单中),但标准与客户关联的名字,姓氏和传真字段地址。
我试过这个:
<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>
但我不清楚输入名称应该是什么。无论如何,都使用帐户名称。
查找可能需要的表单字段“名称”的一些信息,以及禁用自动填充功能的一些方法,也应该是必需的。
欢呼仔细观察这一点。
我正在覆盖 mage / customer / controller / accountController.php :: createPostAction(),我在控制器中看到表单处理的位置并填充为客户实体。
我正在尝试这样的事情
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);
}
}
当我记录下来时:
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
(
)
)
表单变量成功传递(我在日志中看到它们),但我似乎无法以这种方式将它们插入到地址对象中。我收到以下通知:
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
如果这是“间接” - 什么是“直接”方法?
任何?
答案 0 :(得分:0)
DERP。这有效。
$address->setData('firstname', $this->getRequest()->getPost('billing_firstname'));
$address->setData('lastname', $this->getRequest()->getPost('billing_lastname'));
$address->setData('fax', $this->getRequest()->getPost('billing_fax'));
其他人需要这个吗?
将表单字段添加到your/theme/template/persistent/forms/register.phtml
中
覆盖Mage_Customer_AccountController
setData('key', 'value')
yourmodule/customer/controller/accountController.php :: createPostAction()