Description
Preconditions and environment
- Magento version: 2.4.7-p3
- UPS module
Steps to reproduce
- Set UPS credentials in admin and enable UPS shipping
- Calculate UPS shipping rates for a destination where only 1 shipping rate is available at UPS.
Example: Cyprus, 3030
Expected result
Show the single available UPS rate
Actual result
No result displayed, customers cannot place order, losing sales
Additional information
Honestly I would call it a bug in the UPS response format.
The problem is that UPS returns RatedShipment
as an array if there are multiple rates, but if there is only a single rate available then it returns that rate directly.
Example:
Single rate:
'result' => '{"RateResponse":{"Response":{"ResponseStatus":{"Code":"1", "Description":"Success"}, "Alert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "TransactionReference":{"CustomerContext":"Rating and Service"}}, "RatedShipment":{"Service":{"Code":"65", "Description":""}, "RatedShipmentAlert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "BillingWeight":{"UnitOfMeasurement":{"Code":"KGS", "Description":"Kilograms"}, "Weight":"6.5"}, "TransportationCharges":{"CurrencyCode":"HUF", "MonetaryValue":"38750.00"}, "ServiceOptionsCharges":{"CurrencyCode":"HUF", "MonetaryValue":"0.00"}, "TotalCharges":{"CurrencyCode":"HUF", "MonetaryValue":"38750.00"}, "RatedPackage":{"Weight":"6.4"}}}}',
Multiple rates:
'result' => '{"RateResponse":{"Response":{"ResponseStatus":{"Code":"1", "Description":"Success"}, "Alert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "TransactionReference":{"CustomerContext":"Rating and Service"}}, "RatedShipment":[{"Service":{"Code":"07", "Description":""}, "RatedShipmentAlert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "BillingWeight":{"UnitOfMeasurement":{"Code":"KGS", "Description":"Kilograms"}, "Weight":"6.5"}, "TransportationCharges":{"CurrencyCode":"HUF", "MonetaryValue":"41750.00"}, "ServiceOptionsCharges":{"CurrencyCode":"HUF", "MonetaryValue":"0.00"}, "TotalCharges":{"CurrencyCode":"HUF", "MonetaryValue":"41750.00"}, "RatedPackage":{"Weight":"6.4"}}, {"Service":{"Code":"54", "Description":""}, "RatedShipmentAlert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "BillingWeight":{"UnitOfMeasurement":{"Code":"KGS", "Description":"Kilograms"}, "Weight":"6.5"}, "TransportationCharges":{"CurrencyCode":"HUF", "MonetaryValue":"51900.00"}, "ServiceOptionsCharges":{"CurrencyCode":"HUF", "MonetaryValue":"0.00"}, "TotalCharges":{"CurrencyCode":"HUF", "MonetaryValue":"51900.00"}, "RatedPackage":{"Weight":"6.4"}}, {"Service":{"Code":"65", "Description":""}, "RatedShipmentAlert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "BillingWeight":{"UnitOfMeasurement":{"Code":"KGS", "Description":"Kilograms"}, "Weight":"6.5"}, "TransportationCharges":{"CurrencyCode":"HUF", "MonetaryValue":"38750.00"}, "ServiceOptionsCharges":{"CurrencyCode":"HUF", "MonetaryValue":"0.00"}, "TotalCharges":{"CurrencyCode":"HUF", "MonetaryValue":"38750.00"}, "RatedPackage":{"Weight":"6.4"}}]}}',
How to fix:
In magento\module-ups\Model\Carrier.php
line 1273 is the following:
$arr = $rateResponseData['RateResponse']['RatedShipment'] ?? [];
Add the following code below this line in order to convert it to an array if the single rate is exposed directly, not in array:
if (array_key_exists("Service", $arr)) $arr = [$arr];
Maybe it is a bit dirty, but I cannot think about a more fancy solution.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.