Error for users created before purchase order module enabled

Created on 26 March 2021, over 3 years ago
Updated 1 April 2023, over 1 year ago

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

  1. Create a user (userA).
  2. Enable commerce_purchase_order
  3. Create an order for userA ( this can be done via /admin/commerce/orders/add, or as userA using a shopping cart )
  4. 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...

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States scottsawyer Atlanta

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024