When you use the commerce product add-on with layout builder then on the manage default layout tab there is no product id available so it gives an error.

Solution:
We need to check the product id is not null or we can use is_object after the product load call and return [] so no error shown

$product = $this->entityTypeManager->getStorage('commerce_product')->load($product_id);
+if(!is_object($product)) {
+ return [];
+}
$default_variation = $product->getDefaultVariation();
if (!$default_variation) {
return [];
}

Comments

21kPiyush created an issue. See original summary.

  • jsacksick committed 9231ef4d on 8.x-1.x
    Issue #3445914 by 21kPiyush, jsacksick: Commerce Product Add-on with...
jsacksick’s picture

Status: Active » Fixed

Pushed a fix, thanks for the report.

Status: Fixed » Closed (fixed)

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