1

When i checkout as a logged in user, and if i have added my address in an earlier purchase, i am presented with previous addresses which i have entered on checkout page. I want to add fresh address each time even i am logged in and i have already default addresses. enter image description here

1 Answer 1

4

Case 1: Always shows the address form

In order to archive this, you will have to tell Magento to not load the address-list. To do this, you can create a fallback to the Magento_Customer/js/model/address-list.js in your theme and changes its content to:

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */
define([
    'ko',
], function (ko) {
    'use strict';

    return ko.observableArray([]);
});

To take away: Keep in mind it won't prevent Magento to keep saving new addresses to the customer account, it just tells to knockoutjs that the address-list is an empty array.

Case 2: Only shows the default addresses

In this do the fallback to Magento_Customer/js/model/customer-addresses.js

And change it's content to only push to the list items that default_billing or default_shipping is true.

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */
define([
    'jquery',
    'ko',
    './customer/address'
], function ($, ko, Address) {
    'use strict';

    var isLoggedIn = ko.observable(window.isCustomerLoggedIn);

    return {
        /**
         * @return {Array}
         */
        getAddressItems: function () {
            var items = [],
                customerData = window.customerData;

            if (isLoggedIn()) {
                if (Object.keys(customerData).length) {
                    $.each(customerData.addresses, function (key, item) {
                        // Only push the default items
                        if (item.default_billing || item.default_shipping) {
                            items.push(new Address(item));
                        }
                    });
                }
            }

            return items;
        }
    };
});
5
  • It worked like a charm. Thanks @Ziru Zanrgeiff Commented Jan 22, 2020 at 16:36
  • i replaced this js file in my theme here app / design / frontend /Vendor / theme / Magento_Customer / js / model / address-list.js but it does not work. Commented Jan 23, 2020 at 12:28
  • Hi, take into consideration after that you have to clean up your previous compiled theme and compile it again. I have tested it before posting here and it was working fine. Commented Jan 23, 2020 at 12:47
  • the only problem is i have to make changes to core file address-list.js, i want to replace it with theme file. Commented Jan 23, 2020 at 14:03
  • Yes, this is what I mean when I told you to fallback to that file. Commented Jan 23, 2020 at 14:45

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.