I have a situation where each browser session needs to have a unique cart, even if it's the same user. This is for a Punchout situation where we're supporting adding items to the cart and then passing the pick list back to the Punchout system.
For this to work, I need someone to be able to start the Punchout session in two different browsers, but using the same username, and each browser should have isolated carts. The Punchout system starts off by sending the requests to a page that is listening with a custom module. On this module I do a number of things, including creating a new order.
I'm attempting to do this by using unique Order Contexts. What I'm struggling with is to create a new cart and set the OrderContextID. Here's the code that I'm currently using:
Order cart = Dynamicweb.eCommerce.Common.Context.Cart;
if (cart == null)
{
cart = new Order() { IsCart = true, LanguageID = EComContext.LanguageID, ShopID = "SHOP1", OrderContextID = contextId };
cart.Save();
Context.SetCart(cart);
}
The contextId is a string value containing an available order context Id which hasn't been used by this user in the last 24 hours.
The thing that goes wrong is that, when the cart doesn't already exist (i.e. cookies are cleared), this code is executed, but when adding an item to the cart, it ignores this new cart and creates a new one. I can see in the EcomOrders table that the first cart was created successfully. However, after adding a new item to the cart, a new cart is created rather than using the cart that I just created.
It tried to make the cart more valid by setting CustomerAccessUserID, CustomerAccessUserUserName, CustomerNumber, and VisitorSessionID (all of which are null after running the code above). However, that doesn't appear to help. A new cart is always created, so it ignores the one that I created.
So my question is: How do I correctly create a new cart and assign it a unique OrderContextID?
Thanks,
Scott