1

I have installed a store pick up module.

So, I am trying to uncheck the checkbox of "My billing and shipping address are same" once the module is enabled.

I have refered the below link, this will uncheck the checkbox always regardless of which shipping method selected.

How to uncheck "My billing and shipping address are the same" checkbox during checkout? One Page/Magento2

Can we uncheck only when store pick up is selected as "Yes" or when the particular shipping method is selected during the checkout?

Can this be achieved? Please anyone look into this and update me your Answers.

Thanks in advance!!!

1 Answer 1

3

I've added the modification logic to the original code. Please check:

Copy the following file to your theme:

vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js

applyBillingAddress: function () {
    var shippingAddress;

    if (quote.billingAddress()) {
        selectBillingAddress(quote.billingAddress());

        return;
    }
    shippingAddress = quote.shippingAddress();

    if (shippingAddress &&
        shippingAddress.canUseForBilling() &&
        (shippingAddress.isDefaultShipping() || !quote.isVirtual())
    ) {
        if(quote.shippingMethod()['method_code']=='store pick_up code'){
           //uncheck here
        }else{
           //check here
           selectBillingAddress(quote.shippingAddress());
        }
    }
}

And also copy the following file to your theme:

vendor/magento/module-checkout/view/frontend/web/js/model/shipping-save-processor/default.js

saveShippingInformation: function () {
    var payload;

    if (!quote.billingAddress()) {
        if(quote.shippingMethod()['method_code']=='store pick_up code'){
           //uncheck here
        }else{
           //check here
           selectBillingAddress(quote.shippingAddress());
        }
    }

    payload = {
        addressInformation: {
            'shipping_address': quote.shippingAddress(),
            'billing_address': quote.billingAddress(),
            'shipping_method_code': quote.shippingMethod()['method_code'],
            'shipping_carrier_code': quote.shippingMethod()['carrier_code']
        }
    };

    payloadExtender(payload);

    fullScreenLoader.startLoader();

    return storage.post(
        resourceUrlManager.getUrlForSetShippingInformation(quote),
        JSON.stringify(payload)
    ).done(
        function (response) {
            quote.setTotals(response.totals);
            paymentService.setPaymentMethods(methodConverter(response['payment_methods']));
            fullScreenLoader.stopLoader();
        }
    ).fail(
        function (response) {
            errorProcessor.process(response);
            fullScreenLoader.stopLoader();
        }
    );
}

Don't forget to run static-content:deploy and cache flush.

9
  • @magefrms, i am getting this error in console,default.js:44 Uncaught ReferenceError: selectBillingAddress is not defined May 31, 2019 at 6:19
  • 1
    thanks i am able to resolve by changing this line to selectBillingAddressAction(quote.shippingAddress()); from selectBillingAddress(quote.shippingAddress()); in default.js May 31, 2019 at 6:23
  • that's great. sorry I was busy did not able to check your comment
    – fmsthird
    May 31, 2019 at 6:31
  • sure let me checj
    – fmsthird
    May 31, 2019 at 7:11
  • @jafarpinjar but I can't seem to understand why it happened. can you send me your custom module and let me check from my machine
    – fmsthird
    Jun 4, 2019 at 7:55

Your Answer

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

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