puhonien33

I'm building a C# pipeline component to handle credit card processing. I'm able to get the order form values without a problem. However, I'm not sure how to get the value for "soldtoname" which is stored at the PurchaseOrder level. Does anyone have any code examples where they've done this, or have suggestions

Re: Commerce Server 2007 Getting SoldToName in Pipeline Component

Joseph Johnson

You typically add properties to the COM orderform object through the OrderPipelineMappings file in your solution. The file provided with the starter site has the following properties:

<!--Following properties in this map are in the OrderForm where as in the object model these properties reside in the OrderGroup class. This is an exceptional case for these three properties. This kind of mapping is not allowed for other properties.-->
<
Property Name="TrackingNumber" DictionaryKey="order_number" />
<
Property Name="SoldToId" DictionaryKey="user_id" />
<
Collection Name="Addresses" DictionaryKey="Addresses" KeyType="Dictionary" ReferTo="OrderAddress" />

As such, you wont be able to use all of the properties from your purchase order / basket object, but the property you're looking for should be "user_id".






Re: Commerce Server 2007 Getting SoldToName in Pipeline Component

puhonien33

I need the user's email address. user_id gives me the GUID for the Soldto. How do I get back to that



Re: Commerce Server 2007 Getting SoldToName in Pipeline Component

Joseph Johnson

As you've probably noted, the rest of the OrderGroup values are inaccessible in the pipeline.

You can either use the email address in the address dictionary, or you can attach the value in the ordergroup field to the context dictionary prior to running the pipeline.

IE:
PipelineInfo p = new PipelineInfo();
p["sold_to_name"] = bas["sold_to_name"];

That only takes care of reading from this value, and I know of no clever tricks for writing to this value in the pipeline. I'll reiterate that the pipelines operate at the orderform level, and the product team worte very specific logic to capure the aforementioned three values at that level, so I'm not sure how difficult it would be to add another value (It specifically says in that mapping file that this kind of mapping is not allowed for other properties).






Re: Commerce Server 2007 Getting SoldToName in Pipeline Component

puhonien33

How do you reference the context value in the pipeline component



Re: Commerce Server 2007 Getting SoldToName in Pipeline Component

Joseph Johnson

I believe the context dictionary is passed in as the second parameter to the execute method within a pipeline component (have a look at the method signature).

You should be able to cast it as a dictionary and work with it the exact same way you work with the OrderForm.






Re: Commerce Server 2007 Getting SoldToName in Pipeline Component

Max Akbar - MSFT

Joseph is correct if you need a sample of how this is done look at my blog:

Everything you ever wanted to know about pipelines but were afraid to ask (Part III)

Here is a sample code (from ASP.NET):

Basket basket = CommerceContext.Current.OrderSystem.GetBasket(userID);
PipelineInfo pipeinfo = new PipelineInfo("Basket");

pipeinfo["OrderContext"] = CommerceContext.Current.OrderSystem;

basket.RunPipeline(pipeinfo);

Code inside your pipeline:

public int Execute(object pdispOrder, object pdispContext, int lFlags)
{
Int32 ReturnValue = StatusSuccess;

// How to get our Custom OrderContext
IDictionary Context = (IDictionary)pdispContext;
OrderContext myOrderContext = (OrderContext)Context["OrderContext"];

// How to get MessageManager Context
IMessageManager MessageManager = (IMessageManager)Context["MessageManager"];

// do some work here...


return ReturnValue;

}






Re: Commerce Server 2007 Getting SoldToName in Pipeline Component

Colin Bowern

The quick and dirty way in my mind is to pump it into the order form and pull the value out in the pipeline. You can either do it before RunPipeline or if you use an extended Basket object you can override the RunPipline method:

public override PipelineExecutionResult RunPipeline(PipelineInfo pipelineInfo, PipelineBase pipeline)

{

// Propogate OrderGroup items down to the OrderForm level.

foreach (OrderForm orderForm in this.OrderForms)

{

orderForm[OrderForm.Keys.StoreName] = this.storeName;

orderForm[OrderForm.Keys.UserComments] = this.userComments;

orderForm[OrderForm.Keys.UserFirstName] = this.userFirstName;

orderForm[OrderForm.Keys.UserLastName] = this.userLastName;

orderForm[OrderForm.Keys.UserEmailAddress] = this.userEmailAddress;

orderForm[OrderForm.Keys.UserIpAddress] = this.userIpAddress;

orderForm[OrderForm.Keys.UserBrowserAgent] = this.userBrowserAgent;

orderForm[OrderForm.Keys.UserHostName] = this.userHostName;

orderForm[OrderForm.Keys.UserLocale] = this.userLocale;

orderForm[OrderForm.Keys.ExchangeRate] = new CurrencyWrapper(this.exchangeRate);

orderForm[OrderForm.Keys.BillingCurrency] = this.BillingCurrency;

}

PipelineExecutionResult ReturnValue;

if (pipeline == null)

{

ReturnValue = base.RunPipeline(pipelineInfo);

}

else

{

ReturnValue = base.RunPipeline(pipelineInfo, pipeline);

}

// Promote OrderForm items up to the OrderGroup.

if (this.OrderForms.Count > 0)

{

decimal decimalValue;

if (Helper.TryCast<decimal>(this.OrderForms[OrderForm.DefaultOrderFormName][OrderForm.Keys.ExchangeRate], out decimalValue))

{

this.exchangeRate = decimalValue;

}

}

return ReturnValue;

}

We've done this to "promote" additional Order Group level properties to the pipeline when we need it.

Then in your pipeline code you can access the property and pull a value out. Check out my latest blog post with an example of how to access the order form and pipeline context using a strongly-typed wrapper as well.

Cheers,
Colin