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).
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | fix_empty_variations_rendering-2734627-3.patch | 889 bytes | agoradesign |
Comments
Comment #2
mglamanShoot. 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.Comment #3
agoradesign commentedComment #4
mglamanI've created a PR for this: https://github.com/drupalcommerce/commerce/pull/399
Comment #5
mglamanAssigning to bojanz to get review of fix and test on PR.
Comment #7
mglamanThanks! PR merged :)