CartId is unique identifier that Sitecore Commerce Engine uses to unambiguously identify cart of current user.
Sitecore Commerce is prepared for having multiple carts per user. They are differed by their cart name.
SXA Storefront components use “Default” as name of the cart for every user / customer / buyer:
When you are doing requests through Postman, “Cart01” is used as cart name in sample collections:
How can Commerce Engine know for which user you are asking to have cart when calling LoadCart method from Commerce.Connect just by providing “Default” or “Cart01” or anything else as a name?
Answer is pretty simple.
Sitecore Commerce Engine Connect uses CartId to identify cart. This is handled itself under the hood for you.
There is a LoadCart processor in namespace Sitecore.Commerce.Engine.Connect.Pipelines.Carts in Sitecore.Commerce.Engine.dll that will shed some light for you / us.
It takes the LoadCartRequest with your cartId a.k.a. “Default” or “Cart01”. Let’s call this string CartName for the reminder of this article.
Then it extracts also UserId and ShopName from the very same request.
At the end these strings are combined together with this magic formula:
CartId = CartName + UserId + ShopName
CartId will be therefore always unique when processed by Sitecore Commerce.
If you provide different cart names when creating/loading cart, you can create solution where customers can have various carts at the same time. This will support scenarios where you need to have wishlist next to cart functionality. Wishlist will be just another cart in this scenario and you will use “Wishlist” as cart name instead of “Default” which will be used for “normal” shopping cart functionality.
Happy shopping!
Good work writing it. and the magic GIF of Shia LaBeouf always get my attention 🙂
Thanks. When I hear somebody saying “magic”, I imagine this GIF 😀
Can you give a proper example? this is not working for me
Thanks for question. Can you please elaborate more, what is not working for you? What do you mean by proper example? Which version of Sitecore Commerce do you use?