719-286-0751 info@cadence-labs.com

Magento 2 – Fix Admin Panel Reloads Shipping Method After Every Field Change

The Issue

If you have a Magento 2.x installation, you’ve probably noticed a really frustrating “feature” in the admin Create New Order screen. Everytime you change a payment method, address field, or product, the Shipping Method section automatically “reloads” and removes your selected shipping method, and interrupts whatever you are doing on the Create New Order screen with a “Loading” spinner.

This bug is a major time sink, and forces your customer service team to process orders slower than necessary.

Click here to view the GitHub repository for this extension

Our Fix

This module and associated github provide a Magento 2 extension which resolves this issue by preventing Magento from making an ajax request when the shipping methods need to be updated. Use at your own risk. Here’s the gist of how our module fixes this:

  1. After installing the module, changing fields while creating an order will no longer automatically reset the shipping method section.
  2. After you have filled in an address (or added a product), you must remember to click the Get Shipping Methods and Rates button to see an updated shipping quote.
  3. Even if you’ve selected a shipping method, the section will not be reloaded unless you click the button (even if you add/remove a product or change the shipping address).
  4. The one exception to this is changing the Ship To Country field – that will always reload this section.
  5. If you have selected a shipping method and change the shipping address, the method will be “deselected” (but the reload spinner will not appear)

You’ll notice the “Get shipping methods and rates” button is always available. .

The fix works by modifying the below below (via a JS override)

vendor/magento/module-sales/view/adminhtml/order/create/scripts.js

You can see the diff of the code we change below:

221a222,225
>             /**
>              * @mod @author Alan Barber
>              * Do not reset shipping on change events. Ever.
>              */
223,230c227,233
<                 this.resetShippingMethod(data);
<             } else {
<                 this.saveData(data);
<                 if (name == 'country_id' || name == 'customer_address_id') {
<                     this.loadArea(['shipping_method', 'billing_method', 'totals', 'items'], true, data);
<                 }
<                 // added for reloading of default sender and default recipient for giftmessages
< //this.loadArea(['giftmessage'], true, data); 
--- 
>                 jQuery("#order-shipping-method-choose, #order-shipping-method-custom").remove();
>             }
> 
>             this.saveData(data);
> 
>             if (name == 'country_id' || name == 'customer_address_id') {
>                 this.loadArea(['shipping_method', 'billing_method', 'totals', 'items'], true, data);
610c613
< && Form.Element.getValue(elms[i])) 
--- 
>                             && Form.Element.getValue(elms[i]))
1038a1042,1045
>                         /**
>                          * @mod Force reloading of the content area
>                          */
>                         jQuery('#' + this.getAreaId(id)).trigger('contentUpdated');
1122c1129
< || this.excludedPaymentMethods.indexOf(this.paymentMethod) == -1); 
--- 
>                 || this.excludedPaymentMethods.indexOf(this.paymentMethod) == -1);

Install Our Module

Follow the below steps to install our module from github:

# cd to your magento root first
mkdir -p app/code/Cadence/AdminPerformance && git clone https://github.com/cadencelabs-master/magento2-admin-performance.git app/code/Cadence/AdminPerformance
bin/magento setup:upgrade

This extension is licensed under OSL 3.0, click here to read the license

Conclusion

After the extension is installed, the issue should be fixed moving forward. Hope this helps reduce headache in your store!

Alan Barber is the Lead Web Developer at Cadence Labs and a Magento Certified developer.

Need help with Magento 2 Bugs?

We’ve had a lot of experience fixing problems with Magento 2. If you need help, head over to the Cadence Labs contact page, or email us at info@cadence-labs.com. We offer affordable rates for our Magento development services. 

Submit a Comment

Your email address will not be published. Required fields are marked *

Share This