Try our conversational search powered by Generative AI!

Issue with merging cart after login if SKU already exists in users cart.

Vote:
 

Hi All,

I am running into a weird issue that happens when you add line items to your cart while not being logged in. If the items exist in your logged in cart, they don't get merged with the non-logged in line items, a separate line item is created. Wondering if this is a known bug and if there is a work around? Below is a screen shot of a cart where this is happening. 

Episerver Commerce Cart Bug

Here are the versions of Episerver I am running:


  
  
  
  
  
  
  

Any help is greatly appreciated. 

Thanks!

-John

#179991
Jun 27, 2017 23:55
Vote:
 

No, this is not a known bug. I also tested on our latest Quicksilver and everything is fine. How do you add the item to the cart? 

#180001
Jun 28, 2017 9:55
Vote:
 

Hi Quan,

Here is my function to add item to cart:

private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            CartHelper ch = new CartHelper(name);
            string messages = string.Empty;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            // Need entry for adding to cart
            var entry = CatalogContext.Current.GetCatalogEntry(lineItem.Code);
            ch.AddEntry(entry, lineItem.Quantity, false, new CartHelper[] { });

            // Need content for easier access to more information
            ContentReference itemLink = _referenceConverter.GetContentLink(entry.CatalogEntryId,
                CatalogContentType.CatalogEntry, 0);
            EntryContentBase entryContent = _contentLoader.Get<EntryContentBase>(itemLink);

            if (string.IsNullOrEmpty(lineItem.ImageUrl))
            {
                lineItem.ImageUrl = entryContent.GetDefaultImage();
            }

            if (string.IsNullOrEmpty(lineItem.ArticleNumber))
            {
                lineItem.ArticleNumber = entry.ID;
            }

            lineItem.Name = TryGetDisplayName(entry);

            messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            ch.Cart.AcceptChanges();

            return new CartActionResult() { Success = true, Message = messages };
        }

Thanks!

John

#180027
Jun 28, 2017 16:06
Vote:
 

While I can't explain why that happens - you can workaround by override the cart merging process and take the control yourself:

http://vimvq1987.com/2017/06/merging-carts-customer-logs/

I can't reproduce the problem on our WebForm sample site, which is using CartHelper like yours.

#180029
Jun 28, 2017 16:22
Vote:
 

Hi John,

Does your site use VNext feature? Is there any shipment in your cart?

#180051
Jun 29, 2017 10:41
Vote:
 

Hi Bien,

No on both accounts. 

-John

#180096
Jun 29, 2017 16:29
Vote:
 

Ok, I think I found where's the issue and will file a bug for that. A workaround could be:

  • Enable VNext feature

Or

  • when adding item to cart, also add that item to a shipment in the cart as well, create a shipment for cart if no shipment exists.

/Bien

#180107
Jun 30, 2017 8:08
Vote:
 

Heck yeah, thanks Bien!

-John

#180174
Jun 30, 2017 18:27
Vote:
 

This fix was released as part of Commerce 11.1.0 - see http://world.episerver.com/documentation/Release-Notes/ReleaseNote/?releaseNoteId=COM-4812.

#181352
Edited, Aug 16, 2017 16:19
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.