Traditionally, monolithic ecommerce platforms assume that each user session has one shopping cart. When a new user visits the website, a new session is created and used to hold the current user's shopping cart.
Even though this approach is almost always sufficient, there are cases when you want to maintain more shopping carts per user session. Such cases call for a stateless shopping cart that is decoupled from the user's session. Stateless cart engines allow you to maintain as many carts as you need and connect them to user sessions using different session keys.
The logic to store and retrieve carts and possibly group one or more carts together to create multi-order experiences is up to you. There are many use cases that require this level of flexibility. Below are some of the most common.
When selling internationally, each country or region may have different price lists, stock availability, and promotions. Therefore, a cart that works in one country might not work in another. If a customer changes the shipping country, you'd have to re-process your current shopping cart to change prices and remove items that are out of stock or not sellable.
Maintaining this logic can be complex and confusing for customers as well. It is much cleaner to maintain a shopping cart for each country, using the country code as part of the session key.
If the shipping country of the customer changes, you can simply recover the current cart with the country code. When a customer adds items to the shopping cart and then switches countries, the cart content will be recovered if the customer switches back to the previous country.
Generally, a multi-vendor marketplace will maintain one shopping cart and differentiate vendors by line item. Upon placing the order, you split it into multiple shipments or sub-orders and assign each one to a vendor. One cart per session is sufficient in this scenario.
However, there are situations when you want to provide different experiences and maintain separate shopping carts for each vendor. It's more of a "shop by vendor" experience than a multi-vendor shopping cart. In the same way as the previous multi-country example, you can achieve this experience by using a vendor identifier in the session cart key.
As a customer navigates through vendors, the cart changes according to the vendor and any items previously added to the cart are persistent, making the experience very consistent.
Another common scenario where a multi-cart session may be required is on B2B ecommerce websites. Imagine a sales agent placing multiple orders simultaneously for several clients. In order to make the experience smoother and faster, the sales agent should be able to initiate a multi-client shopping session that produces multiple orders in a batch. Essentially, sales agents place orders on behalf of clients in a single transaction.
Here again, the current cart can change based on context (the current client), and instead of placing just one order, several orders are placed simultaneously. In a B2B scenario, the customer address and payment method are usually already stored on file. This allows you to place multiple orders for multiple clients in just one click.