Accidentally, I've found this small issue. The use case does not make sense at all. However it's easy to trigger that problem and Commerce should be fault tolerant enough to not run into a fatal error.

To reproduce: create a product entity with status active, assign a single product variation to it, but leave its status disabled -> save. 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_product\ProductVariationFieldRenderer::renderFields() must implement interface Drupal\commerce_product\Entity\ProductVariationInterface, null given, called in /var/www/drupalvm/web/modules/commerce/modules/product/commerce_product.module on line 85 and defined in Drupal\commerce_product\ProductVariationFieldRenderer->renderFields() (line 67 of modules/commerce/modules/product/src/ProductVariationFieldRenderer.php).

Comments

agoradesign created an issue. See original summary.

mglaman’s picture

Shoot. The variation field injection isn't validating that there are actually variations. The hook_ENTITY_TYPE_view() needs to be updated before trying to pass variations to the service.

agoradesign’s picture

Status: Active » Needs review
StatusFileSize
new889 bytes
mglaman’s picture

mglaman’s picture

Assigned: Unassigned » bojanz

Assigning to bojanz to get review of fix and test on PR.

  • mglaman committed 28b0bc6 on 8.x-2.x authored by agoradesign
    Issue #2734627 by agoradesign, mglaman: Product entities without an...
  • mglaman authored 605aa7f on 8.x-2.x
    Merge pull request #399 from mglaman/2734627-product-without-variation-...
mglaman’s picture

Status: Needs review » Fixed

Thanks! PR merged :)

Status: Fixed » Closed (fixed)

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