Fix null address handling and prevent warnings in CustomerProfileWrapper and ColissimoRelayProfile
This merge request fixes a fatal error and related PHP warnings that occur when the customer profile has no address field or when the field is empty during checkout.
Error message example:
Error: Call to a member function getValue() on null in
Drupal\commerce_shipping_colissimo\CustomerProfileWrapper->getAddress()
(line 42 of modules/contrib/commerce_shipping_colissimo/src/CustomerProfileWrapper.php)
Changes
- Added null checks and field existence validation in
CustomerProfileWrapper. - Ensured that address fields are only accessed or set when available.
- Updated
ColissimoRelayProfileto use safe default values (?? '') for hidden address form fields. - Prevented PHP notices and warnings during checkout when no address is defined.
Testing
Steps to reproduce before the patch:
- Install Drupal 10 with Commerce 3.x.
- Enable the Commerce Shipping Colissimo module.
- Start checkout without a saved address.
- Observe fatal error or PHP warnings in logs.
After applying the patch:
- Checkout works correctly, even when no address is yet defined.
- No more PHP warnings or fatal errors.
Compatibility
- Tested on Drupal 10.3 + Commerce 3.3.
- Compatible with PHP 7.4+.
- No API or data model changes.
Edited by devator