Here In this article I will explain the detailed steps to add the product to the user's basket or basket of the anonymous user.
In commerce server, user's order is divided into 3 states: Basket, Order Template and Purchase Order. Here Basket is the customer's shopping cart. (Reference: http://msdn.microsoft.com/en-us/library/microsoft.commerceserver.runtime.orders.basket%28CS.90%29.aspx )
Basket is represented by Basket class and which is in namespace Microsoft.CommerceServer.Runtime.Orders
Step 1: Get the basket instance of current user:
To get the basket instance of the current user, get the UserID of the current user as follows
CommerceContext csContext = CommerceContext.Current;
string UserID = csContext.UserID;
Here,
CommerceContext : This class is available in namespace Microsoft.CommerceServer.Runtime(Reference: http://msdn.microsoft.com/en-us/library/microsoft.commerceserver.runtime.commercecontext%28CS.90%29.aspx )
Once we get the UserID we can get the basket instance for the user as follows
basket = CommerceContext.Current.OrderSystem.GetBasket(new Guid(UserID));
But in our project we have scenario, to add the items for the anonymous users. In this case we will get UserID as a null. So here we are using a ShoppingController class from the microsoft CommerceSharePointExtensibilityKit. Once you installed commerce server 2009 SDK this kit will be available for you. This kit contains all the source code for the commerce server webparts. You can find this kit in your CommerceServer folder (For ex. - C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Sdk\Samples)
ShoppingController class is available in Microsoft.Commerce.Portal.Common namespace. So to get the basket for the anonymous user
ShoppingController shoppingController =
new ShoppingController(true,
false,
false,
false,
false,
false
);

Sr KarthigaPosted Apr 3, 2016, 12:02 AM
good one
Sr KarthigaPosted Apr 3, 2016, 12:02 AM
nice explanation
Narasimha MurthyPosted Jul 26, 2011, 11:46 AM
Greetings, It is a very good article, I have implemented the code. but in the site "My Shopping cart", items are not displaying. Could you please let me know is there any thing need to add to the code to disply the added items in the current logged in user's site basket (My Shopping Cart) Thanks, Murthy.
Narasimha MurthyPosted Jul 26, 2011, 11:40 AM
Hi Prasham, Greetings, It is a very good article, I have implemented the code. but in the site "My Shopping cart", items are not displaying. Could you please let me know is there any thing need to add to the code to disply the added items in the current logged in user's site basket (My Shopping Cart) Thanks, Murthy.