Создайте модуль с контроллером, который расширяет Mage_Customer_AccountController
, содержащий createPostAction()
.Я продублировал бит, который обрабатывает адрес выставления счета, нашел этот блок if:
if ($this->getRequest()->getPost('create_address')) {
И добавил в конец его:
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);
}}
Конечно, вам также нужно продублироватьформа в ваших темах template/customer/form/register.html
, в частности код внутри этого if-блока:
if($this->getShowAddressFields()): ?>
Префикс всех идентификаторов имен полей и в скопированном коде с shipping_.В 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');
(почти) полный код можно найти здесь:
AccountController.php: http://pastebin.com/9h9HqYAa
register.html: http://pastebin.com/Q7EawU7L
Отлично работает