DCSIMG
June 2010 - Posts - Arik Veeder Blog

June 2010 - Posts

 

Lately I've returned playing a bit with CS2009 for a POC which meant to show how easy it is to interfere with the Commerce server processes and integrate them with backend systems.

We needed to show integration with external profile (login in the commerce environment and get some information from external resource)   and calculation of the basket in external system (This is probably better doing in the basket \ total pipelines , but I wanted to play with the multi channel a bit).

First, we needed to extract information from external web service regarding the logged in user.

I've looked at this whitepaper which gives good example on how to achieve the profile integration :

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ce5629ad-2473-4c25-8f89-91c8530cd764

 

Then we needed to manipulate the items which are inside the orderform of the user basket.

To do so, we wrote a class which inherits from OperationSequenceComponent.

  • Override the Execute method

  public override void Execute(CommerceOperation operation,

                                     OperationCacheDictionary operationCache,

                                     CommerceOperationResponse  response)

  • Next, retrieves the ordergroups from the operation cache.

OrderGroupCollection cachedOrderGroups =                OrderGroupCache.GetCachedCommerceServerOrderGroups(operationCache);

  • Get the basket (at least try to)

CommerceEntity entity = operation.TryGetSearchModel("Basket");

if (((entity != null) && entity.ModelName.Equals("Basket")))

  • Now loop over the ordergroups and apply changesas needed               

foreach (OrderGroup group in cachedOrderGroups)

{   

if (group is Basket)

{

//create new line item                  

 LineItem line = new LineItem("Adventure Works Catalog", "AW053-10", "37", 2);

//override some properties sa this code will run after the basket //pipline

   line.ExtendedPrice = 23;

   line["_product_Image_filename"] = "abc.png";

//or add new discount to the line item                       

DiscountApplicationRecord disc = new DiscountApplicationRecord();

disc.BasketDisplayMessage = "this is generated discount";

disc.DiscountAmount = 2;               

line.ItemLevelDiscountsApplied.Add(disc);

//add the new line item

group.OrderForms[0].LineItems.Add(line);

//or remove some line prevoise  items                       

group.OrderForms[0].LineItems.Remove(0);

}

}

 

Now all we need is to place this at the right place in the operation sequence - since I wanted to manipulate the line items , I've put it after the Order Pipelines Processor

Just before the Basket Committer.

One thing that I've notice is that if we remove line items from the basket in the custom operation sequence and place the custom operation before "Line Items processor" component - we get an error

  • Type : System.ServiceModel.FaultException`1[[Microsoft.Commerce.Contracts.Faults.ItemDoesNotExistFault, Microsoft.Commerce.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Message : The requested item does not exist

 

The 3rd component we needed is to export the completed order after payment

In the Execute method, we check: ((string)operation.Model.Properties["Status"] == "ReadyForCheckout"))

And in the forech section we've checked that the OrderGroup is of PurchaseOrder Type

foreach (OrderGroup group in cachedOrderGroups)

                {

                    if (group is PurchaseOrder)

                    {

                        writer.WriteFile(group); 

                    }

                }