Commerce Server Blog

Build world class ecommerce applications using Microsoft Commerce Server
  •  
  • Home
  • Advertise
  • Copyright Policy
  • Disclaimer
  • About

Modifying Purchase Order in Commerce Server

ravikanth | August 3, 2008

After placing order, there are many cases where the order modification may happen. Commerce server allows us to modify the purchase order but make sure you don’t allow any modifications of purchase after some stage. For example, don’t allow purchase order modification once the ordered products are dispatched. In this article, I am explaining how to remove items from purchase order.

Here is the code snippet used to simulate modifications to an order.

OrderContext OrderContext = CommerceContext.Current.OrderSystem;
ProfileContext profileContext = CommerceContext.Current.ProfileSystem;
Profile userProfile = profileContext.GetProfile(“GeneralInfo.email_address”, “ravi@ava.com”, “UserObject”);
string userId = new Guid().ToString();
if (userProfile != null)
{
       userId = userProfile["GeneralInfo.user_id"].Value.ToString();
}
else
{
       Response.Write(“Login Failed”);
}

OrderGroupCollection ogCollection= OrderContext.GetPurchaseOrdersForUser(new Guid(userId));
OrderGroup og = ogCollection[0];
PurchaseOrder po = OrderContext.GetPurchaseOrder(new Guid(userId), og.OrderGroupId);
Response.Write(“Item Total Before removing item:” + po.OrderForms[0].Total.ToString());
po.OrderForms[0].LineItems.Remove(0);
PipelineInfo pipeLineInfo = new PipelineInfo(“basket”);
po.RunPipeline(pipeLineInfo);
pipeLineInfo = new PipelineInfo(“total”);
po.RunPipeline(pipeLineInfo);
po.Save();
Response.Write(“Item Total After removing item:” + po.OrderForms[0].Total.ToString());

 

For example, I created an order with three products and order total is coming to 221$ (as shown in the figure below.)

Purchase Order before removing item.

In the code, I am taking the order of the user, removing first item from the order, running basket and total pipeline.  Note: If you don’t execute pipelines the code will not give any error but the totals will be wrong.

After executing the code the order details are shown below.

Purchase Order after removing item.

 

A product of price 9$ is removed from the order and the current total is decreased to 212.40$.

Comments
No Comments »
Categories
commerce server 2007
Tags
commerce server order system, modify purchase order, post order, purchase order
Comments rss Comments rss
Trackback Trackback

Sign up for Newsletter


Categories

Quiz

  • Catalog Quiz for Beginners
  • Profile Quiz for Beginners
  • Quiz 1 for Advance Users
  • Quiz for Beginners

Recent Posts

  • Staging Deployment – Security Considerations
  • Pipeline Editor displays registered custom pipeline components as unknown in 64 Bit version.
  • How commerce server staging works
  • Steps to extend payments in Commerce Server 2009
  • Introduction to Commerce Server Staging
  • Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information
  • Commerce server staging throws Remote authorization failed to server. Ensure the service has access to this server.
  • Updated Commerce Server 2009 template pack for SharePoint 2007 released
  • RCXml2Resx.exe tool stops working
  • Commerce Server Profile Importer Tool

Archives

  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008

Tags

add discounts add images to profile Advantages of commerce server approve discounts authentication auto login process automatic user creation basket Brand Management business tools campaign management Catalog catalog import Category commerce server commerce server 2007 commerce server manager Commerce Server SP2 commerce server staging discounts ecommerce Estimation Installation inventory Kanth Koppala marketing system migration error Mojave operation components operation sequence Order subsystem Product profile profile subsystem property metadata purchase order quick checkout Ravi Ravi Kanth site cache refresh starter site tools transactions error Variant
(c) 2009 Commerce Server Blog. All rights Reserved. Articles cannot be reproduced without permission from the author.Write to me at kanth@ravikanth.net if you have any comments, questions, suggestions about this site or would like to send us a tip
About Us | Terms of Use | Disclaimer | Advertise .