Came accross to this when exporting product data from external system and wanted temporarily inactivate the product variation as exported data had faulty price in it.

To reproduce: create a product entity with status active, assign a single product variation to it, uncheck Active checkbox to set variation as inactive, update variation and then save product entity.

If you now try to open the detail page of the product entity, you'll get this error:

Recoverable fatal error: Argument 1 passed to Drupal\commerce_order\OrderItemStorage::createFromPurchasableEntity() must implement interface Drupal\commerce\PurchasableEntityInterface, null given, called in /var/www/drupalvm/drupal/web/modules/contrib/commerce/modules/product/src/ProductLazyBuilders.php on line 59 and defined in Drupal\commerce_order\OrderItemStorage->createFromPurchasableEntity() (line 16 of modules/contrib/commerce/modules/order/src/OrderItemStorage.php).

CommentFileSizeAuthor
#2 product_entities-2852273-2.patch1.25 KBmitrpaka
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mitrpaka created an issue. See original summary.

mitrpaka’s picture

mitrpaka’s picture

Status: Active » Needs review
bojanz’s picture

Title: Product entities without an active variation cannot be rendered, causing recoverable fatal error » Fatal error when trying to render an add to cart form for a product with no active variations

We also need to document that getDefaultVariation() can be NULL.

  • bojanz committed 44e8052 on 8.x-2.x authored by mitrpaka
    Issue #2852273 by mitrpaka: Fatal error when trying to render an add to...
bojanz’s picture

Status: Needs review » Fixed

Tweaked and committed, thanks!

niko-’s picture

Status: Fixed » Needs work

In this case better solution will show product page with disabled add to cart button

niko-’s picture

I propose select first variation and show product page with disabled or hidden $form['actions'] here

vasike’s picture

Status: Needs work » Fixed

i think this issue is fixed (closed).

@niko- imho, it think it's best to open new issue(s) about add to cart and no default variation.
thanks

bojanz’s picture

If there's no default variation, that means that there are no active variations at all. So it's not possible to do #7 / #8.

Status: Fixed » Closed (fixed)

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