4

One of customers contacted him to point out that he is not able to specify different billing and shipping addresses for his account. When he changes one address, the other automatically changes as well.

I logged into the Magento admin console to try and separate the addresses myself, but I didn’t find a way.

Any Idea!!!!

4 Answers 4

2

I have also had customers complain about not being able to separately edit their billing and shipping addressees. This is due to what is rather non-intuitive behavior of Magento.

It appears to the customer that there are two addresses each with separate edit links. However, by default, there really is only one record being displayed twice! Editing either address actually edits same underlying record, resulting in the behavior customers complain about.

The work-around for customers is to 'Add' an address to their address book. Now they will have two address records that can be edited independently. They can also choose which address is default for billing and which is default for shipping.

There is definitely room for Magento improvement here! One simple approach might be to just display one address and indicate it is both the shipping and billing address. And then provide a button to create a separate shipping (or billing) address.

2

Couldn't find a way to separate the addresses either, though I've been able to stop this problem from occurring with new registrations by creating two separate addresses for billing and shipping. Tried this only on 1.9.1.0. You have to override the Mage_Customer_AccountController and change the _getErrorsOnCustomerAddress method.

protected function _getErrorsOnCustomerAddress($customer)
{
    $errors = array();
    /* @var $address Mage_Customer_Model_Address */
    $address = $this->_getModel('customer/address');
    /* @var $addressForm Mage_Customer_Model_Form */
    $addressForm = $this->_getModel('customer/form');
    $addressForm->setFormCode('customer_register_address')
        ->setEntity($address);

    $addressData = $addressForm->extractData($this->getRequest(), 'address', false);
    $addressErrors = $addressForm->validateData($addressData);
    if (is_array($addressErrors)) {
        $errors = array_merge($errors, $addressErrors);
    }

    $address->setId(null)
        ->setIsDefaultBilling(1)
        ->setIsDefaultShipping(0);
    $addressForm->compactData($addressData);
    $customer->addAddress($address);

    $shipaddress = $this->_getModel('customer/address');
    /* @var $addressForm Mage_Customer_Model_Form */
    $shipaddressForm = $this->_getModel('customer/form');
    $shipaddressForm->setFormCode('customer_register_address')
    ->setEntity($shipaddress);

    $shipaddressData = $shipaddressForm->extractData($this->getRequest(), 'address', false);
    $shipaddressErrors = $shipaddressForm->validateData($shipaddressData);
    if (is_array($shipaddressErrors)) {
        $errors = array_merge($errors, $shipaddressErrors);
    }
    $shipaddress->setId(null)
    ->setIsDefaultBilling(0)
    ->setIsDefaultShipping(1);
    $shipaddressForm->compactData($shipaddressData);
    $customer->addAddress($shipaddress);

    $addressErrors = $address->validate();
    if (is_array($addressErrors)) {
        $errors = array_merge($errors, $addressErrors);
    }
    return $errors;
}
0

Sort of super late, but what I did when facing this problem was add a variable to the generated link for the save url. so it was like

 domain/customer/address/edit/id/idnumber/?edittype=billing or ?edittype=shipping

then in php I overwrote the AddressController.php's

 formPostAction()

Method and basically copied it and added

$editType=Mage::app()->getRequest()->getParam('edittype');   
if($editType=='billing'){
                $address->setIsDefaultBilling(1);
                $address->setID(null);
            }else if($editType=='shipping'){
                $address->setIsDefaultShipping(1);
                $address->setId(null);
            }

Just make sure you do it before you hit the $address->validate() and it should save the old address, and assign this new one be default shipping or billing address based on what

0

For magento 2 the below code will work to create separate entry for billing and shipping.

i am skipping to module create basic step. here is the direct required changes to fulfill the requirement.

First create the di file on the below location.

app/code/[Vendor]/[Module_Name]/etc/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <type name="Magento\Customer\Model\Address">
        <plugin name="after_customer_save" type="[Vendor]\[Module_Name]\Plugin\Model\CustomerAfterSave" sortOrder="10"/>
    </type>
</config>

After declaration plugin need to create plugin class in directory. app/code/[Vendor]/[Module_Name]/Plugin/Model/CustomerAfterSave.php

<?php

namespace [Vendor]\[Module_Name]\Plugin\Model;

use Magento\Customer\Model\AddressFactory;
use Psr\Log\LoggerInterface;

class CustomerAfterSave
{
    const SHIPPING_ADDRESS_COUNT = '1';

    /**
     * Construct function
     *
     * @param AddressFactory         $address
     * @param LoggerInterface        $logger
     */
    public function __construct(
        AddressFactory $address,
        LoggerInterface $logger
    ) {
        $this->addressModel             = $address;
        $this->logger                   = $logger;
    }

    /**
     * Create New address after magento address saved
     *
     * @param \Magento\Customer\Model\Address $subject
     * @param string $savedAddress
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     * @return mixed
     */
    public function afterSave(
        \Magento\Customer\Model\Address $subject,
        $savedAddress
    ) {
        $customer = $savedAddress->getCustomer();
        if (is_object($customer) &&
            $customer->getDefaultBilling()  ==
            $customer->getDefaultShipping() &&
            $customer->getAddressesCollection()->getSize() <= self::SHIPPING_ADDRESS_COUNT
        ) {
            $this->customerAddressSaveAfter($savedAddress);
        }
        return $savedAddress;
    }

    /**
     * Create new default shipping address
     *
     * @param \Magento\Customer\Model\Address $address
     * @return this
     */
    private function customerAddressSaveAfter($address)
    {
        try {
            if ($address->getIsDuplicate()) {
                return $this;
            }
            $oriAddress = $this->addressModel->create()->load($address->getId());
            $oriAddress->setIsDefaultShipping(true)
                    ->setIsDuplicate(true)
                    ->__clone();
            $oriAddress->save();
        } catch (\Exception $e) {
            $this->logger->critical($e->getMessage());
        }
        return $this;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.