Hi,
We are experiencing a problem when logging in with the following setting (all true):
- Recalculate a user's cart when the user logs in
- Keep anonymous cart when user logs in
- Merge the anonymous cart content with the cart saved on the user when logging in
We have multiple OrderContexts, and when logging in, it duplicates the content from the anonymous cart.
In the BeforeLoginSubscriber in Ecoomerce.Common, you add carts to Dynamicweb.Context.Current.Items.Item("Dynamicweb:Ecommerce.CartsBeforeUserLogin").
First you add a cart without a context, then you add a cart for each existing context. - My suspicion is that the first one (the one without context) defaults back to a cart that actually has a context (maybe from the session), adding that exact cart twice.
My testing shows that the duplicates in Dynamicweb.Context.Current.Items.Item("Dynamicweb:Ecommerce.CartsBeforeUserLogin") have the same OrderContext (the orders are identical), which is weird that it is possible at all, and from the code, it seems to be the only explanation.
Later in the AfterLoginSubscriber, you loop through Dynamicweb.Context.Current.Items.Item("Dynamicweb:Ecommerce.CartsBeforeUserLogin") and add the orderlines from each order to the current order.
Maybe you could check if the same order allready exists in Dynamicweb.Context.Current.Items.Item("Dynamicweb:Ecommerce.CartsBeforeUserLogin") before adding it?
Kind regards
Mikkel Ulstrup