小智 6
使用扩展Mage_Customer_AccountController包含的控制器创建一个模块createPostAction().我复制了处理账单地址的位,找到这个if-block:
if ($this->getRequest()->getPost('create_address')) {
Run Code Online (Sandbox Code Playgroud)
并将其添加到它的末尾:
if ($this->getRequest()->getPost('create_shipping_address')) {
$shippingAddress = Mage::getModel('customer/address');
$shippingAddressForm = Mage::getModel('customer/form');
$shippingAddressForm->setFormCode('customer_register_address')
->setEntity($shippingAddress);
$shippingAddressData = array(
'firstname' => $addressData['firstname'],
'lastname' => $addressData['lastname'],
'company' => $this->getRequest()->getPost('shipping_company'),
'street' => $this->getRequest()->getPost('shipping_street'),
'city' => $this->getRequest()->getPost('shipping_city'),
'country_id' => $this->getRequest()->getPost('shipping_country_id'),
'region' => $this->getRequest()->getPost('shipping_region'),
'region_id' => $this->getRequest()->getPost('shipping_region_id'),
'postcode' => $this->getRequest()->getPost('shipping_postcode'),
'telephone' => $this->getRequest()->getPost('shipping_telephone'),
'fax' => $this->getRequest()->getPost('shipping_fax')
);
$shippingAddressErrors = $addressForm->validateData($shippingAddressData);
if ($shippingAddressErrors === true) {
$shippingAddress->setId(null)
->setIsDefaultBilling($this->getRequest()->getParam('shipping_default_billing', false))
->setIsDefaultShipping($this->getRequest()->getParam('shipping_default_shipping', false));
$shippingAddressForm->compactData($shippingAddressData);
$customer->addAddress($shippingAddress);
$shippingAddressErrors = $shippingAddress->validate();
if (is_array($shippingAddressErrors)) {
$errors = array_merge($errors, $shippingAddressErrors);
}
} else {
$errors = array_merge($errors, $shippingAddressErrors);
}}
Run Code Online (Sandbox Code Playgroud)
当然,您还需要在主题中复制表单template/customer/form/register.html,特别是if-block中的代码:
if($this->getShowAddressFields()): ?>
Run Code Online (Sandbox Code Playgroud)
使用shipping_为所有字段名称ID和复制的代码添加前缀.在底部的JavaScript中,您需要复制RegionUpdater行,如下所示:
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
new RegionUpdater('country', 'shipping_region', 'shipping_region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
Run Code Online (Sandbox Code Playgroud)
(几乎)完整的代码可以在这里找到:
AccountController.php:http: //pastebin.com/9h9HqYAa
register.html:http: //pastebin.com/Q7EawU7L
它完美地运作
| 归档时间: |
|
| 查看次数: |
4547 次 |
| 最近记录: |