getPurchasedEntity can return NULL and there can be error

Created on 4 July 2024, about 1 year ago
Updated 10 September 2024, 10 months ago

Problem/Motivation

In some cases the order_item->getPurchasedEntity(); code can return NULL and produce the error:
Error: Call to a member function id() on null in Drupal\facebook_pixel_commerce\FacebookCommerce->getOrderItemData() (line 90 of /app/web/modules/contrib/facebook_pixel/modules/facebook_pixel_commerce/src/FacebookCommerce.php).

Proposed resolution

Add condition in FacebookCommerce::getOrderItemData() to check if the $entity = $order_item->getPurchasedEntity() is not NULL. Though I'm not sure if we should just return empty array if it's NULL or return all available data except those which are received from the $entity.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code (Facebook Pixel Commerce)

Created by

πŸ‡ΊπŸ‡¦Ukraine khiminrm

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024