客户注册时:
默认情况下,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
如果这是“间接” - 什么是“直接”方法?
任何人?