Problem/Motivation
If a user is created before enabling commerce_purchase_order, when that user attempts to checkout, an error is thrown:
Notice: Trying to get property 'value' of non-object in /app/web/modules/contrib/commerce_purchase_order/src/Plugin/Commerce/Condition/PurchaseOrderCustomerApproved.php on line 30
Once the user account is edited and saved, there will not be an error, because field_purchase_orders_authorized will now have a value.
Steps to reproduce
- Create a user (userA).
- Enable commerce_purchase_order
- Create an order for userA ( this can be done via /admin/commerce/orders/add, or as userA using a shopping cart )
- Once you attempt to checkout ( from shopping cart ), or add payment ( via order admin ), the error is thrown.
Proposed resolution
There was a similar error reported in Assigned to: FatherShawn
#3159980: Unable to complete Purchase β
, which was solved by changing src/Plugin/Commerce/PaymentGateway/PurchaseOrderGateway.php:
$user_approved = ($customer->hasField('field_purchase_orders_authorized') && $customer->field_purchase_orders_authorized->first()->value);
to:
$user_approved = (
$customer->hasField('field_purchase_orders_authorized')
&& !$customer->get('field_purchase_orders_authorized')->isEmpty()
&& $customer->get('field_purchase_orders_authorized')->first()->value
);
Currently, src/Plugin/Commerce/Condition/PurchaseOrderCustomerApproved.php has:
return (bool) ($customer->hasField('field_purchase_orders_authorized') && $customer->field_purchase_orders_authorized->first()->value);
Which maybe should have a similar change:
return (bool) (
$customer->hasField('field_purchase_orders_authorized')
&& !$customer->get('field_purchase_orders_authorized')->isEmpty()
&& $customer->get('field_purchase_orders_authorized')->first()->value
);
Remaining tasks
Create a patch...