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 REST "A shipment cannot have a KGS/IN or LBS/CM or OZS/CM as its unit of measurements" #38618

Closed sanmic closed 2 months ago

sanmic commented 5 months ago

Preconditions and environment

Magento version 2.4.7

Steps to reproduce

Set European Union as Origin of the Shipment in Sales->Delivery Methods->UPS

Expected result

UPS rates is visible in checkout and cart.

Actual result

No UPS rates is visible in checkout and cart.

Additional information

Seems like UnitOfMeasurement is hardcoded to "IN". If you have European Union (other origins may experience the same problem) as Origin of the Shipment this will cause an error in the UPS REST request: "A shipment cannot have a KGS/IN or LBS/CM or OZS/CM as its unit of measurements"

1147 foreach ($rowRequest->getPackages() as $package) { 1148 $rateParams['RateRequest']['Shipment']['Package'][] = [ 1149 "PackagingType" => [ 1150 "Code" => "{$params['48_container']}", 1151 "Description" => "Packaging" 1152 ], 1153 "Dimensions" => [ 1154 "UnitOfMeasurement" => [ 1155 "Code" => "IN", 1156 "Description" => "Inches" 1157 ], 1158 "Length" => "5", 1159 "Width" => "5", 1160 "Height" => "5" 1161 ], 1162 "PackageWeight" => [ 1163 "UnitOfMeasurement" => [ 1164 "Code" => "{$rowRequest->getUnitMeasure()}" 1165 ], 1166 "Weight" => "{$this->_getCorrectWeight($package['weight'])}" 1167 ] 1168 ]; 1169 }

Release note

No response

Triage and priority

m2-assistant[bot] commented 5 months ago

Hi @sanmic. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

sanmic commented 5 months ago

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

magento-deployment-service[bot] commented 5 months ago

Hi @sanmic. Thank you for your request. I'm working on Magento instance for you.

m2-assistant[bot] commented 5 months ago

Hi @sanmic! :wave: Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

magento-deployment-service[bot] commented 5 months ago

Hi @sanmic, here is your Magento Instance: https://b2437ad179063c5f7eb8a7bbdd57dc08.instances-prod.magento-community.engineering Admin access: https://b2437ad179063c5f7eb8a7bbdd57dc08.instances-prod.magento-community.engineering/admin_cb7b Login: 6fb81ec6 Password: 3fb4d7b8b374

m2-assistant[bot] commented 5 months ago

Hi @engcom-Dash. 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:


m2-assistant[bot] commented 5 months ago

Hi @engcom-Delta. 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:

sanmic commented 5 months ago

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

magento-deployment-service[bot] commented 5 months ago

Hi @sanmic. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 5 months ago

Hi @sanmic, here is your Magento Instance: https://b2437ad179063c5f7eb8a7bbdd57dc08.instances-prod.magento-community.engineering Admin access: https://b2437ad179063c5f7eb8a7bbdd57dc08.instances-prod.magento-community.engineering/admin_5a0f Login: d7361ba1 Password: f4687c1b2cca

sanmic commented 5 months ago

To reproduce: Sales -> Delivery methods -> UPS Set Origin of the Shipment to Shipments Originating in the European Union Set Weight Unit to KGS

No UPS rates is visible in frontend.

If Weight Unit is set to LBS rates is visible in fronted. I can see by myself that LBS is hardcoded in the core files.

REST-EU-Origin-KGS1 REST-EU-Origin-KGS2 REST-EU-Origin-LGS1 REST-EU-Origin-LGS2 REST-US-Origin1 REST-US-Origin2

sanmic commented 5 months ago

@engcom-Delta

How can I add a Add label to the ticket?

"Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to."

github-jira-sync-bot commented 5 months ago

Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x, ^Area:.*

Once all required labels are present, please add Issue: Confirmed label again.

github-jira-sync-bot commented 5 months ago

Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x, ^Area:.*

Once all required labels are present, please add Issue: Confirmed label again.

engcom-Delta commented 5 months ago

Hi @sanmic ,

Verified the issue and the issue is reproducible.

Hence, Confirming the issue.

Steps to reproduce

  1. Sales -> shipping methods -> UPS
  2. Enable UPS method
  3. Set Origin of the Shipment to Shipments Originating in the European Union
  4. Set Weight Unit to KGS
  5. Go to frontend and verify the shipping methods available

    Please refer the attached screenshot

Screenshot 2024-04-17 at 6 19 45 PM Screenshot 2024-04-17 at 6 21 56 PM Screenshot 2024-04-17 at 6 43 04 PM Screenshot 2024-04-17 at 6 49 49 PM Screenshot 2024-04-17 at 6 51 41 PM
github-jira-sync-bot commented 5 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-11811 is successfully created for this GitHub issue.

m2-assistant[bot] commented 5 months ago

:white_check_mark: Confirmed by @engcom-Delta. Thank you for verifying the issue.
Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

github-jira-sync-bot commented 5 months ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11811

engcom-Delta commented 5 months ago

@engcom-Delta How can I add a Add label to the ticket? "Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to."

Hi @sanmic , I have added the labels on the ticket. Let us know if you need any changes.

glo05363 commented 5 months ago

@sanmic I can reproduce this issue, while analysing the same, i can see that

  1. If we setup config with LBS we get the results for rates quotes:

    Screenshot 2024-04-19 at 1 50 09 AM
  2. If we config KGS to get the Rate data we do not get the results.

    Screenshot 2024-04-19 at 1 50 25 AM

I am checking on how the weight/Dimension units are affecting the results as it is known the measurement units sometimes are not valid for the given country: Here with the same payload i have tried with both LBS/KGS & INCHES/CM

Screenshot 2024-04-19 at 1 57 14 AM

The analysis is in progress and thank you for this finding , we shall see on how to incorporate the dynamic Measurement units for Rates Quote Data, as we might need to implement the country based UPS support for the same.

glo05363 commented 5 months ago

@sanmic To add more to the issue: UPS has global Unit Of measures "IN" and "CM" and they needs to be used as per the "Weight" units that we are using in our UPS admin configurations. We are working on the implementations of the same, we will update here on the progress.

If you're using kilograms (KGS) as the weight unit, ensure that you are also using centimeters (CM) as the unit for dimensions (length, width, and height).

If you're using pounds (LBS) or ounces (OZS) as the weight unit, ensure that you are using inches (IN) as the unit for dimensions (length, width, and height).

That is what we can understand with the given error response : "A shipment cannot have a KGS/IN or LBS/CM or OZS/CM as its unit of measurements"

Other than that while configuring the UPS in admin you can make sure you setup the Weight unit as per the Shipper country origin by confirming the same on UPS support.

sanmic commented 5 months ago

@glo05363 I have pretty good knowledge about the UPS shipping API. We have developed an application for creating the UPS shipments and are aware of the sensitive settings for weight and dimensions (we ship from Sweden). In this case we only use the UPS settings in Magento to show the rates in the cart and checkout.

A builtin time-in-transit function would be nice in Magento as well :)

engcom-Bravo commented 5 months ago

Hi @sanmic,

Our internal team is working on the issue and we have following updates

Please refer the Comments:

https://github.com/magento/magento2/issues/38618#issuecomment-2065269636

https://github.com/magento/magento2/issues/38618#issuecomment-2066513710

Thanks.

digitalrisedorset commented 5 months ago

@magento I am working on this

digitalrisedorset commented 5 months ago

Do we have some UPS access details to use to replicate the issue on a local environment?

sanmic commented 4 months ago

@digitalrisedorset Have you been able to get UPS access details?

digitalrisedorset commented 4 months ago

@sanmic no I have not. I got as far as creating the UPS account but a lot of settings were required and by the time I had the setup created to handle the task, I was doomed to have setup the UPS service differently to what is needed to replicate the issue we have in this ticket. So, I'd like instead to verify if I can use a test UPS environment that is ready to use to just perform the Magento test and fix after this

sanmic commented 4 months ago

@sanmic no I have not. I got as far as creating the UPS account but a lot of settings were required and by the time I had the setup created to handle the task, I was doomed to have setup the UPS service differently to what is needed to replicate the issue we have in this ticket. So, I'd like instead to verify if I can use a test UPS environment that is ready to use to just perform the Magento test and fix after this

@digitalrisedorset I guess I can create a UPS test app / credentials so you can continue your work. I'll need a Callback URL and an email or similar to send the details.

digitalrisedorset commented 4 months ago

Hi @sanmic , I have setup a demo site at https://demo.digitalrisedorset.co.uk/ and the email may be herve@digitalrisedorset.co.uk. Many thanks

sanmic commented 4 months ago

@digitalrisedorset Check you email :)

digitalrisedorset commented 4 months ago

@sanmic .. we should be almost there. I have setup UPS, to start with, I'd like to verify I can get it to work as per the screenshots above, I have setup the credentials with European origin and yet Pounds rather than Kgs. I have also used an address from the states. I attach both screenshots. Am I missing something?

I will start troubleshooting either way, thank you very much indeed

Screenshot from 2024-04-26 12-22-49 Screenshot from 2024-04-26 12-22-06

sanmic commented 4 months ago

@digitalrisedorset I think you have to set "Origin of the Shipment" to, for example, "Shipments Originating in United States". The weight unit parameter may depend on the Magentos origin settings, Sales->Shipping settings->Origin, but I'm not 100% sure. Our Origin, for example, is Sweden which uses KGS. If origin is US which use LBS. Do some testing based on that, I think you will figure it out.

digitalrisedorset commented 4 months ago

@sanmic I am not lucky just yet.. I have a successful response and in fact, some times for possible delivery time do appear. Unfortunately, it does return eventually the error message that UPS is not available. I will try to read more on UPS before debugging further. I apologise, it seems to be something that will take a while.

{
   "RateResponse":{
      "Response":{
         "ResponseStatus":{
            "Code":"1",
            "Description":"Success"
         },
         "Alert":[
            {
               "Code":"110971",
               "Description":"Your invoice may vary from the displayed reference rates"
            },
            {
               "Code":"120902",
               "Description":"Negotiated rates cannot be returned without a valid account number."
            },
            {
               "Code":"111685",
               "Description":"TPFCNegotiatedRatesIndicator is applicable only for Third party/Freight Collect shipments."
            }
         ],
         "TransactionReference":{
            "CustomerContext":"Rating and Service"
         }
      },
      "RatedShipment":[
         {
            "Disclaimer":{
               "Code":"05",
               "Description":"Rate excludes VAT. Rate includes a fuel surcharge, but excludes taxes, duties and other charges that may apply to the shipment."
            },
            "Service":{
               "Code":"01",
               "Description":""
            },
            "RatedShipmentAlert":[
               {
                  "Code":"120902",
                  "Description":"Negotiated rates cannot be returned without a valid account number."
               },
               {
                  "Code":"110971",
                  "Description":"Your invoice may vary from the displayed reference rates"
               }
            ],
            "BillingWeight":{
               "UnitOfMeasurement":{
                  "Code":"LBS",
                  "Description":"Pounds"
               },
               "Weight":"2.0"
            },
            "TransportationCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"106.66"
            },
            "ServiceOptionsCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"0.00"
            },
            "TotalCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"106.66"
            },
            "GuaranteedDelivery":{
               "BusinessDaysInTransit":"1",
               "DeliveryByTime":"10:30 A.M."
            },
            "RatedPackage":{
               "TransportationCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"106.66"
               },
               "ServiceOptionsCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"0.00"
               },
               "TotalCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"106.66"
               },
               "Weight":"2.0",
               "BillingWeight":{
                  "UnitOfMeasurement":{
                     "Code":"LBS",
                     "Description":"Pounds"
                  },
                  "Weight":"2.0"
               }
            }
         },
         {
            "Disclaimer":{
               "Code":"05",
               "Description":"Rate excludes VAT. Rate includes a fuel surcharge, but excludes taxes, duties and other charges that may apply to the shipment."
            },
            "Service":{
               "Code":"02",
               "Description":""
            },
            "RatedShipmentAlert":[
               {
                  "Code":"120902",
                  "Description":"Negotiated rates cannot be returned without a valid account number."
               },
               {
                  "Code":"110971",
                  "Description":"Your invoice may vary from the displayed reference rates"
               }
            ],
            "BillingWeight":{
               "UnitOfMeasurement":{
                  "Code":"LBS",
                  "Description":"Pounds"
               },
               "Weight":"2.0"
            },
            "TransportationCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"42.22"
            },
            "ServiceOptionsCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"0.00"
            },
            "TotalCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"42.22"
            },
            "GuaranteedDelivery":{
               "BusinessDaysInTransit":"2"
            },
            "RatedPackage":{
               "TransportationCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"42.22"
               },
               "ServiceOptionsCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"0.00"
               },
               "TotalCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"42.22"
               },
               "Weight":"2.0",
               "BillingWeight":{
                  "UnitOfMeasurement":{
                     "Code":"LBS",
                     "Description":"Pounds"
                  },
                  "Weight":"2.0"
               }
            }
         },
         {
            "Disclaimer":{
               "Code":"05",
               "Description":"Rate excludes VAT. Rate includes a fuel surcharge, but excludes taxes, duties and other charges that may apply to the shipment."
            },
            "Service":{
               "Code":"03",
               "Description":""
            },
            "RatedShipmentAlert":[
               {
                  "Code":"120902",
                  "Description":"Negotiated rates cannot be returned without a valid account number."
               },
               {
                  "Code":"110971",
                  "Description":"Your invoice may vary from the displayed reference rates"
               }
            ],
            "BillingWeight":{
               "UnitOfMeasurement":{
                  "Code":"LBS",
                  "Description":"Pounds"
               },
               "Weight":"2.0"
            },
            "TransportationCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"15.12"
            },
            "ServiceOptionsCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"0.00"
            },
            "TotalCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"15.12"
            },
            "RatedPackage":{
               "TransportationCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"15.12"
               },
               "ServiceOptionsCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"0.00"
               },
               "TotalCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"15.12"
               },
               "Weight":"2.0",
               "BillingWeight":{
                  "UnitOfMeasurement":{
                     "Code":"LBS",
                     "Description":"Pounds"
                  },
                  "Weight":"2.0"
               }
            }
         },
         {
            "Disclaimer":{
               "Code":"05",
               "Description":"Rate excludes VAT. Rate includes a fuel surcharge, but excludes taxes, duties and other charges that may apply to the shipment."
            },
            "Service":{
               "Code":"12",
               "Description":""
            },
            "RatedShipmentAlert":[
               {
                  "Code":"120902",
                  "Description":"Negotiated rates cannot be returned without a valid account number."
               },
               {
                  "Code":"110971",
                  "Description":"Your invoice may vary from the displayed reference rates"
               }
            ],
            "BillingWeight":{
               "UnitOfMeasurement":{
                  "Code":"LBS",
                  "Description":"Pounds"
               },
               "Weight":"2.0"
            },
            "TransportationCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"33.64"
            },
            "ServiceOptionsCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"0.00"
            },
            "TotalCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"33.64"
            },
            "GuaranteedDelivery":{
               "BusinessDaysInTransit":"3"
            },
            "RatedPackage":{
               "TransportationCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"33.64"
               },
               "ServiceOptionsCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"0.00"
               },
               "TotalCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"33.64"
               },
               "Weight":"2.0",
               "BillingWeight":{
                  "UnitOfMeasurement":{
                     "Code":"LBS",
                     "Description":"Pounds"
                  },
                  "Weight":"2.0"
               }
            }
         },
         {
            "Disclaimer":{
               "Code":"05",
               "Description":"Rate excludes VAT. Rate includes a fuel surcharge, but excludes taxes, duties and other charges that may apply to the shipment."
            },
            "Service":{
               "Code":"13",
               "Description":""
            },
            "RatedShipmentAlert":[
               {
                  "Code":"120902",
                  "Description":"Negotiated rates cannot be returned without a valid account number."
               },
               {
                  "Code":"110971",
                  "Description":"Your invoice may vary from the displayed reference rates"
               }
            ],
            "BillingWeight":{
               "UnitOfMeasurement":{
                  "Code":"LBS",
                  "Description":"Pounds"
               },
               "Weight":"2.0"
            },
            "TransportationCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"97.20"
            },
            "ServiceOptionsCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"0.00"
            },
            "TotalCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"97.20"
            },
            "GuaranteedDelivery":{
               "BusinessDaysInTransit":"1"
            },
            "RatedPackage":{
               "TransportationCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"97.20"
               },
               "ServiceOptionsCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"0.00"
               },
               "TotalCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"97.20"
               },
               "Weight":"2.0",
               "BillingWeight":{
                  "UnitOfMeasurement":{
                     "Code":"LBS",
                     "Description":"Pounds"
                  },
                  "Weight":"2.0"
               }
            }
         },
         {
            "Disclaimer":{
               "Code":"05",
               "Description":"Rate excludes VAT. Rate includes a fuel surcharge, but excludes taxes, duties and other charges that may apply to the shipment."
            },
            "Service":{
               "Code":"14",
               "Description":""
            },
            "RatedShipmentAlert":[
               {
                  "Code":"120902",
                  "Description":"Negotiated rates cannot be returned without a valid account number."
               },
               {
                  "Code":"110971",
                  "Description":"Your invoice may vary from the displayed reference rates"
               }
            ],
            "BillingWeight":{
               "UnitOfMeasurement":{
                  "Code":"LBS",
                  "Description":"Pounds"
               },
               "Weight":"2.0"
            },
            "TransportationCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"141.84"
            },
            "ServiceOptionsCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"0.00"
            },
            "TotalCharges":{
               "CurrencyCode":"USD",
               "MonetaryValue":"141.84"
            },
            "GuaranteedDelivery":{
               "BusinessDaysInTransit":"1",
               "DeliveryByTime":"8:00 A.M."
            },
            "RatedPackage":{
               "TransportationCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"141.84"
               },
               "ServiceOptionsCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"0.00"
               },
               "TotalCharges":{
                  "CurrencyCode":"USD",
                  "MonetaryValue":"141.84"
               },
               "Weight":"2.0",
               "BillingWeight":{
                  "UnitOfMeasurement":{
                     "Code":"LBS",
                     "Description":"Pounds"
                  },
                  "Weight":"2.0"
               }
            }
         }
      ]
   }
}
digitalrisedorset commented 4 months ago

I have looked into UPS guides further. I have worked out that the setup can go wrong with the information: User ID, Password, Gateway URL and origin setting:

Could we double check these information settings before we go any further?

https://amasty.com/knowledge-base/how-to-set-up-ups-in-magento-2.html

https://www.ups.com/upsdeveloperkit

sanmic commented 4 months ago

@digitalrisedorset I can confirm those settings work for me as long as I have LBS as weight unit. Changing the "Origin of the Shipment" to "Europe", weight to KGS and the "Shipping Origin" to our address, "77463, Dalarnas Län, Avesta, Sweden", will break it.

I've just spent a short time on this, but this is what I've found out so far. UPS will return rates if:

UPS will NOT return rates if:

UPS will NOT return rates if:

I want to setup my store like this:

I can change line 1155 in /vendor/magento/module-ups/Model/Carrier.php -> "Code" => "CM", to make it work with above settings.

digitalrisedorset commented 4 months ago

I have a draft PR in place for this issue. The changes in the PR do resolve the problem but I'd like to check if we can also ensure that the integration can work with the other modes without being restricted to Inches before I finalise the PR

see: https://github.com/magento/magento2/pull/38673

digitalrisedorset commented 4 months ago

@sanmic in the same way that Inch is hard-coded, I can see the dimensions for the request is also hard-coded. This is just below the place that you had patched:

"Length" => "5",
                    "Width" => "5",
                    "Height" => "5"

I have changed the part you recommended us to change but I have not changed the dimensions. Would you be able to comment whether we should change it or not?

sanmic commented 4 months ago

@digitalrisedorset Yes, I've noticed that also. I cannot find an option to set or use dimensions in the UPS settings section so I guess the hardcoded 5x5x5 is there for some kind of fallback 🤔

digitalrisedorset commented 4 months ago

@sanmic the PR is now in review, I have tested today all the use cases you have mentioned and all is working with the simple changes added.

digitalrisedorset commented 4 months ago

@magento run all tests

hostep commented 3 months ago

It looks like this was fixed in Magento 2.4.7-p1 which was released today: https://github.com/magento/magento2/commit/d10435b11ada4e502dca7539f8fd31d059d3c482#diff-8baae2f7a7af0d5144a7a6d168ad5e92161d596179feef9daa24ebefbb44d86d

engcom-Charlie commented 2 months ago

The required changes has been published in https://github.com/magento/magento2/commit/493e01f54c8922c620fe9c9f2bfdd1aa536b9bb6 for 2.4 develop.