Tags/topics: 
1
Answers
Vote up!
1
Vote down!

Multiple Orders in one Cart

Can you have multiple orders in one Cart? As an anonymous user, you can add to a cart. At checkout, you log in. If the checkout process is not completed, you end up with an order(order #1) that has not completed the checkout process. You log out, add another item to the cart as an anonymous user. At checkout, you log in. The current item in your cart is the current order(order #2) showing for checkout. Now you have two orders (order #1 and order #2). I would like to have the items in order #1 automatically show in order #2. Essentially, there would only be one active order per user. Items are all rolled up into one order all the way to checkout completion. If there is a better way to avoid multiple active orders per user, please provide a suggestion.

Asked by: ronmorton
on June 26, 2013

1 Answer

Vote up!
0
Vote down!

I was experiencing the same behavior on multiple started checkouts.
On top of it, it seems that once 1 of the 'shopping cart' orders is really getting to a checkout completion status, the cart gets re-initialized with 1 of the other still pending 'shopping cart' orders.
From a ux perspective this can look very confusing and lead to buggy conclusions.

I think there's a way to achieve what ronmorton is suggesting by merging multiple cart orders into one order.

For another occassion, i had to execute some logic right before the first creation of an order instance.
I managed to do this as follows :

function my_module_commerce_order_presave($order) {
if (!isset($order->order_id) && $order->status == 'cart') {
// execute merge logic on other remaining cart orders
}
}

This question remains:
Do you really want to present your authenticated user with a previously started cart instance that might already be a few months old, maybe filled with products that are no longer available in stock ?
Therefore i believe cleaning up remaining order instances would be a less confusing solution from a user perspective. Can be achieved by executing the commerce_cart_order_empty() function on the remaining order instances. As such the involved order_id's are getting reused, which save us some little extra space on the database :)

Answer by: rawdesk
Posted: Jan 17, 2016