magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

UPS shipping method rates request has no caching #26482

Open MichaelThessel opened 4 years ago

MichaelThessel commented 4 years ago

Preconditions (*)

  1. Magento 2.3.3 & 2.4-develop.

Steps to reproduce (*)

  1. This problem only appears when M2 is extended and UPS shipping set up
  2. I have an installation where 3 different modules fetch the shipping totals on the cart page
  3. They do this via:

Magento\Quote\Model\Quote\TotalsCollector->collectAddressTotals()

which then executes:

Magento\Shipping\Model\Rate->getAllRates()

which then executes:

Magento\Ups\Model\Carrier->_getXmlQuotes()

The problem is now that _getXmlQuotes does a remote request to: https://onlinetools.ups.com/ups.app/xml/Rate which takes 2-3s per request (see: vendor/magento/module-ups/Model/Carrier.php line 782).

The problem is that the remote request to the UPS API is not cached. So in my case this is executed 3 times for each page load of the cart page. Additionally this is worsened by the fact that the cart page does 2 more API calls to:

rest/default/V1/guest-carts/[token]/totals-information (see: vendor/magento/module-checkout/etc/webapi.xml)                          
rest/default/V1/guest-carts/[token]/estimate-shipping-methods (see: vendor/magento/module-quote/etc/webapi.xml)     

which trigger the same extensions again resulting in 3 additional calls each. So in total for each page load of the cart page 9 identical requests to the UPS API are sent.

In case somebody else runs into this. In my case the initiating modules are:

vendor/amasty/promo/Plugin/Quote/Model/Quote/TotalsCollectorPlugin.php 119    
vendor/aheadworks/module-sarp2/Model/Shipping/RatesCollector.php 77    
vendor/mirasvit/module-rewards/src/Rewards/Model/Total/Quote/Discount.php 259  

Additionally:

While looking at vendor/magento/module-ups/Model/Carrier.php I noticed that the XML for the remote request is manually pieced together. The parameters inserted into the XML are not escaped. If any of the parameters contains i.e. '<' the entire request falls apart. Simplexml is a system requirement for M2 and the XML should be generated using a XML lib.

Expected result (*)

  1. Remote request is cached.

Actual result (*)

  1. Remote request gets executed multiple times
m2-assistant[bot] commented 4 years ago

Hi @MichaelThessel. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@MichaelThessel do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


m2-assistant[bot] commented 4 years ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @engcom-Hotel Thank you for verifying the issue. Based on the provided information internal tickets MC-30805 were created

Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

ltay13 commented 4 years ago

I was about to raise a similar request when I came across this one, except we see this issue in the context of DHL. So for whoever ends up working on this issue, I think the issue is wider than UPS and is happening with other carriers too (well, at least with DHL).

This problem has a significant impact on the checkout experience in our case, with some of the DHL requests taking 7s to return, then being repeated several times in a row without caching. So total time waiting is commonly 30s+.

dwightc commented 3 years ago

I would also like to add some additional data to this issue. I can confirm that this happens with all shipping carriers on vanilla Magento 2.3.6.

I am managing a store that has USPS, UPS, FedEx, and DHL configured for shipping rates. Merely visiting the shopping cart page can cause several identical calls to each shipping API to be made.

Deleting an item from the cart while on the shopping cart page causes each API to be called several times each. Clicking the "Update Shopping Cart" button also causes several identical calls to each shipping API to be made.

All of these redundant shipping API calls result in some significant slowdown of checkout process.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

dverkade commented 3 years ago

Posting a comment. Issues should not be automatically closed.

MichaelThessel commented 3 years ago

Definitely still an issue for us. Don't close issues because they have no activity.

schizek commented 2 years ago

Any update on this?

dazz397 commented 2 years ago

I have this issue also. Any updates?

emastyle commented 2 years ago

Posting a comment to not automatically closed this issue.

nvorhees commented 1 year ago

Still broken. Also the FedEx shipping provider in Magento 2.4.3 is still using SOAP. In the year two thousand twenty three, SOAP is still a protocol that is being used.