CS 2007 - Recurring Orders Sample Code
Here is a code sample which illustrates how you can achieve a common scenario on a B2B / B2C eCommerce site – placing repeated Orders containing the same set of products over and over again, without the hassle of having to search for and save the set of products you are interested in (think of an someone placing an Order for the same set of supplies every few months for e.g.).
In the Commerce Server 2007 Order capture system you can achieve this in a variety of ways, including iterating over and saving the collections you are interested in, in your own module (especially if you have an extended Order system where you want to control this completely). The sample I provide below uses the Named Baskets feature of CS 2007 and I think this is most appropriate here, because it gives a lot of flexibility (you can have as many wish lists as you want for each user browsing the site) and ease of site code development.
We first create a named Basket called “WishList” and add some products to it (in a helper function). We save this “WishList” and use the Add(OrderGroup) method to add all the items in this wish list to new Baskets created for the user (same userId Guid has to be used). Once the items are present in a new Basket, we can do the various operations such as running the pipelines etc. before checking out completely via the SaveAsOrder method.
Basket myWishList = OrderContext.Current.GetBasket(uid, "WishList");
AddOrderFormsWithValidLineItems(1, myWishList, 2);
myWishList.Save();
Basket myBasket1 = CommerceContext.Current.OrderSystem.GetBasket(uid, "myBasket1");
myBasket1.Add(myWishList);
//Run the pipelines etc. and then save as order
PurchaseOrder myOrder1 = myBasket1.SaveAsOrder();
Basket myBasket2 = CommerceContext.Current.OrderSystem.GetBasket(uid, "myBasket2");
myBasket2.Add(myWishList); //Same items are being checked out again
//Run the pipelines etc. and then save as order
PurchaseOrder myOrder2 = myBasket2.SaveAsOrder();
Hope you find the sample useful.
Comments
Anonymous
June 06, 2006
Sorry, I wasn't sure where else to post this question.
I get an error that the ws cannot be found when i try to invoke:
http://localhost/CatalogWebService/CatalogWebService.asmx
I have installed CS2006 beta and all the associated software (Marketing Manager, Catalog Manger, etc). But I cannot find the "CatalogWebService.asmx" file anywhere on my computer. I get a similar error when I run the Catalog Manager.
Thanks,
NaderAnonymous
June 06, 2006
Hi Nader,
You need to unpack the CSharpSite (which is empty) or the Beta of the StarterSite and add the web service application from the CSharpSite to get any of the web services. You will also need to add the current user to the Authorization Manager to give permissions for doing various operations from the UIs.
Hope that helps.
NihitAnonymous
August 01, 2006
The comment has been removedAnonymous
August 01, 2006
Hi Colin,
I'll try and cover that in one of the blog postings soon. Thanks for the feedback on what you'd like to see.
Thanks,
NihitAnonymous
November 28, 2006
How would you setup recurring payments in CS2007? Let say you offer a payment plan on an item. Is there a sample of this some where? In addition, this code only places two orders into the system in different PO. Does the customer see these orders in their profile? Secondly, why do we need to create 2 different POs can't we simply create 1 PO with 2 different orders in it? I apologize if these are newbie questions. Thank you, FrankAnonymous
January 03, 2007
Hi Frank, Sorry for the delayed response - I was OOF on vacation. I am not sure what you mean by recurring payments. If you mean pay $100 in 10 payments of $10 each month, then there is nothing in-built with CS 2007 to handle this - it would require your custom handling. The customer will see 2 orders placed in their profile. The reason to create 2 PurchaseOrders (which is what a placed 'order' is referred to in CS 2007 and is different from the PurchaseOrder payment type commonly used in business) is that these would typically be placed at different times. For e.g. a manager might be ordering the same set of supplies from Office Depot every 6 months. They will not need to add the items into their Basket everytime if they use this method. Hope that helps explain. Nihit