Currently the code assumes that $order_item->getPurchasedEntity() will always return an entity, but this can return NULL:

/**
 * Gets the purchased entity.
 *
 * @return \Drupal\commerce\PurchasableEntityInterface|null
 *   The purchased entity, or NULL.
 */
public function getPurchasedEntity();

This can easily happen in practice, especially taking https://www.drupal.org/project/commerce/issues/3047357 into consideration. For anyone with off-site payment methods having hundreds or even thousands of old, locked draft orders that have been abandoned in the payment step is not uncommon. And currently all these orders go through the order processors. If the referenced product variation of such an order has been deleted in the meantime then getPurchasedEntity() will return NULL.

The resolver should check to see if it has an entity and just bail out if there isn't one.

CommentFileSizeAuthor
#2 3115093-2.patch647 bytestwiik

Comments

TwiiK created an issue. See original summary.

twiik’s picture

Status: Active » Needs review
StatusFileSize
new647 bytes

Patch attached.

jsacksick’s picture

Status: Needs review » Fixed

Committed, thanks!

  • jsacksick committed a60688a on 8.x-1.x authored by TwiiK
    Issue #3115093 by TwiiK: Ensure the purchased entity exists before...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.