- π¬π§United Kingdom alexku
Same issue as in comment #9.
$product_id is empty on Manage layout page of a product type (admin/commerce/config/product-types/default/edit/display/full)
Adding a check if $product_id is empty resolves the issue
public function ajaxAddToCartForm($product_id, $view_mode, $combine) { /** @var \Drupal\commerce_order\OrderItemStorageInterface $order_item_storage */ $order_item_storage = $this->entityTypeManager->getStorage('commerce_order_item'); if (empty($product_id)) { return []; } /** @var \Drupal\commerce_product\Entity\ProductInterface $product */ $product = $this->entityTypeManager->getStorage('commerce_product')->load($product_id); $default_variation = $product->getDefaultVariation(); if (!$default_variation) { return []; } $order_item = $order_item_storage->createFromPurchasableEntity($default_variation); /** @var \Drupal\commerce_cart\Form\AddToCartFormInterface $form_object */ $form_object = $this->entityTypeManager->getFormObject('commerce_order_item', 'dc_ajax_add_cart'); $form_object->setEntity($order_item); // The default form ID is based on the variation ID, but in this case the // product ID is more reliable (the default variation might change between // requests due to an availability change, for example). $form_object->setFormId($form_object->getBaseFormId() . '_commerce_product_' . $product_id); $form_state = (new FormState())->setFormState([ 'product' => $product, 'view_mode' => $view_mode, 'settings' => [ 'combine' => $combine, ], ]); return $this->formBuilder->buildForm($form_object, $form_state); }
- πΊπΈUnited States bob.hinrichs
Thanks for this info, is a patch or update available that fixes #12 also?
- Status changed to Needs work
over 1 year ago 12:04am 5 April 2023 - πΊπΈUnited States bob.hinrichs
I am sorry to change status, but in order for this to work, I believe the adjustments in #12 would be necessary in order to avoid the errors reported?
- πΊπΈUnited States SocialNicheGuru
I think this has been incorporated into the MR at π Drupal 10 update Needs review
Might be a duplicate a this point
I suggest merging the MR in π Drupal 10 update Needs review as it incorporates this issues' changes as well as the D10 compatibility changes from π Drupal 10 update Needs review .