Error: Call to a member function getUnit() on null

Created on 7 May 2025, about 1 month ago

Problem/Motivation

We have notice an error, when recalculating shipping charges on a "placed" order, while adding a new shipment. Error: Call to a member function getUnit() on null in Drupal\commerce_ups\UPSSdk->getPackages() (line 289 of /var/www/html/web/modules/contrib/commerce_ups/src/UPSSdk.php).

Steps to reproduce

When a shipment is added on a "placed" order from path "/admin/commerce/orders/{commerce_order}/shipments/add/{commerce_shipment_type}"

or follow these steps:

  • Edit any "placed" order from "/admin/commerce/orders".
  • Click on "Shipments" tab.
  • Click "Add shipment".
  • Now, don't select any Shipment items and click on "Recalculate shipping".
  • After an AJAX request completion, you'll notice an error message "Oops, something went wrong. Check your browser's developer console for more details.".
  • In the developer console and watchdog, you'll notice the above fatal error.

Proposed resolution

The issue is, executing the getWeight() method on a shipment entity object, while no shipment item was selected. Though, on the "Add shipment" form the field "Shipment items" is marked as required, but it is not validated against the "Recalculate shipping" button action. We should either validate the button action or block the getWeight() method execution when no shipment item was selected.

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇮🇳India vipin.j

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024