0

I have a magento 1.9.2.4 with multistore (3 websites), and it has configured global accounts.

I need to filter the customer addresses by website.

For example, let's say the countries are France, Germany and UK.

If a customer with a french shipping address logs in the german website, I need that the french address is not available in the german website (or the Uk website).

If a customer with a german shipping address logs in the UK website, it shouldn't have available the german address in the UK website (or french).

But I have no clue where I should begin with this....

EDIT: In system > configuration > SALES > Shipping Methods > Ship to Applicable Countries I have set Specific Countries option and selected a different country by website.

Now, customers can't ship to a different country, but I need to not list at all the addresses from another countries and the other countries addresses are still there.

EDIT 2: I'm still searching, and I've tracked this code in app/design/frontend/rwd/myproject/template/opc/onepage/billing.phtml

<?php if ($this->customerHasAddresses()): ?>
    <li class="wide">
        <label for="billing-address-select" class="notice"><?php echo $this->__('Select a billing address from your address book or enter a new address.') ?></label>
        <div class="input-box">
            <?php echo $this->getAddressesHtmlSelect('billing') ?>
        </div>
    </li>
<?php endif; ?>

and getAddressesHtmlSelect leads me to:

public function getAddressesHtmlSelect($type)
{
    if ($this->isCustomerLoggedIn()) {
        $options = array();
        foreach ($this->getCustomer()->getAddresses() as $address) {
            $options[] = array(
                'value' => $address->getId(),
                'label' => $address->format('oneline')
            );
        }

        $addressId = $this->getAddress()->getCustomerAddressId();
        if (empty($addressId)) {
            if ($type=='billing') {
                $address = $this->getCustomer()->getPrimaryBillingAddress();
            } else {
                $address = $this->getCustomer()->getPrimaryShippingAddress();
            }
            if ($address) {
                $addressId = $address->getId();
            }
        }

        $select = $this->getLayout()->createBlock('core/html_select')
            ->setName($type.'_address_id')
            ->setId($type.'-address-select')
            ->setClass('address-select')
            ->setExtraParams('onchange="'.$type.'.newAddress(!this.value)"')
            ->setValue($addressId)
            ->setOptions($options);

        $select->addOption('', Mage::helper('checkout')->__('New Address'));

        return $select->getHtml();
    }
    return '';
}
0

Finally I've found a solution, I copy it here because it maybe helps somebody in the future:

I had to override app/code/core/Mage/Checkout/Block/Onepage/Abstract.php with app/code/local/Mage/Checkout/Block/Onepage/Abstract.php, and there I changed the function getAddressesHtmlSelect() with this code:

public function getAddressesHtmlSelect($type)
{
    if ($this->isCustomerLoggedIn()) {
        $options = array();
        $store_id = Mage::app()->getStore()->getStoreId();
        $all_addresses = $this->getCustomer()->getAddresses();

        if (Mage::getStoreConfig('carriers/flatrate/sallowspecific', $store_id)) {
            $allowed_countries = explode( ',', Mage::getStoreConfig('carriers/flatrate/specificcountry', $store_id) );
            foreach ($all_addresses as $address) {

                if (in_array($address->getCountryId(), $allowed_countries)) {
                    $options[] = array(
                        'value' => $address->getId(),
                        'label' => $address->format('oneline')
                    );
                }

            }
        } else {
            foreach ($all_addresses as $address) {
                $options[] = array(
                    'value' => $address->getId(),
                    'label' => $address->format('oneline')
                );
            }
        }

        if (!empty($options)) {

            $addressId = $this->getAddress()->getCustomerAddressId();
            if (empty($addressId)) {
                if ($type=='billing') {
                    $address = $this->getCustomer()->getPrimaryBillingAddress();
                } else {
                    $address = $this->getCustomer()->getPrimaryShippingAddress();
                }
                if ($address) {
                    $addressId = $address->getId();
                }
            }

            $select = $this->getLayout()->createBlock('core/html_select')
                ->setName($type.'_address_id')
                ->setId($type.'-address-select')
                ->setClass('address-select')
                ->setExtraParams('onchange="'.$type.'.newAddress(!this.value)"')
                ->setValue($addressId)
                ->setOptions($options);

            $select->addOption('', Mage::helper('checkout')->__('New Address'));

            return $select->getHtml();
        }
        return false;
    }
    return '';
}

next stop is to change the app/design/frontend/rwd/myproject/template/opc/onepage/billing.phtml and app/design/frontend/rwd/myproject/template/opc/onepage/shipping.phtml with following code:

<?php if ($this->customerHasAddresses()): ?>
   <li class="wide">
       <label for="shipping-address-select" class="notice"><?php echo $this->__('Select a shipping address from your address book or enter a new address.') ?></label>
       <div class="input-box">
           <?php $select_address = $this->getAddressesHtmlSelect('shipping'); ?>  // this is for shipping.phtml, remember to change the argument 'shipping' for 'billing' in the billing.phtml
            <?php echo $select_address ?>
       </div>
   </li>
<?php endif ?>
<li id="shipping-new-address-form"<?php if ($this->customerHasAddresses() && $select_address ): ?> style="display:none;"<?php endif ?>>

And in the end there is only rest to comment the values of the billing/shipping form inputs to not being autocompleted with the default address.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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