Skip to content

UPS shipping method rates request has no caching #26482

Open
@MichaelThessel

Description

@MichaelThessel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CacheComponent: UpsIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P4No current plan to fix. Fixing can be deferred as a logical part of more important work.Progress: ready for devReported on 2.3.3Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchRisk: highSeverity: S4Affects aesthetics, professional look and feel, “quality” or “usability”.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions