diff -u b/modules/cart/src/Form/AddToCartForm.php b/modules/cart/src/Form/AddToCartForm.php --- b/modules/cart/src/Form/AddToCartForm.php (date 1701797111222) +++ b/modules/cart/src/Form/AddToCartForm.php (date 1709129964342) @@ -232,16 +232,35 @@ $this->getDestination($form_state) === 'checkout' && $this->moduleHandler->moduleExists('commerce_checkout') ) { - /** @var \Drupal\commerce_order\Entity\OrderInterface $order */ - $order = $this->entityTypeManager->getStorage('commerce_order') - ->create([ + $order = NULL; + $order_storage = $this->entityTypeManager->getStorage('commerce_order'); + + // For authenticated user, try to get existing draft order to reduce + // duplicates for the same item. + if ($this->currentUser->isAuthenticated()) { + $order_ids = $order_storage->getQuery() + ->condition('type', $order_type_id) + ->condition('store_id', $store->id()) + ->condition('uid', $this->currentUser->id()) + ->condition('state', 'draft') + ->condition('order_items.entity.purchased_entity', $purchased_entity->id()) + ->accessCheck() + ->execute(); + if (!empty($order_ids)) { + $order = $order_storage->load(reset($order_ids)); + } + } + if (!$order) { + /** @var \Drupal\commerce_order\Entity\OrderInterface $order */ + $order_storage->create([ 'type' => $order_type_id, 'store_id' => $store->id(), 'uid' => $this->currentUser()->id(), 'cart' => FALSE, ]); - $order->addItem($order_item); - $order->save(); + $order->addItem($order_item); + $order->save(); + } // Add the order as a completed cart to allow anonymous checkout access. // @todo Find a better way for this. reverted: --- b/modules/product/tests/src/FunctionalJavascript/ProductLayoutBuilderIntegrationTest.php (date 1701797107377) +++ a/modules/product/tests/src/FunctionalJavascript/ProductLayoutBuilderIntegrationTest.php (revision 8ea8a7ecfcffcd4da5998763302f76746078013b) @@ -290,7 +290,6 @@ $save_layout = $this->getSession()->getPage()->findButton('Save layout'); $save_layout->focus(); $save_layout->click(); - $this->assertSession()->waitForElementVisible('css', '.messages-list__wrapper'); $this->assertSession()->pageTextContains('The layout has been saved.'); }