While doing an implementation of Commerce Server 2209 and the extensibility kit for a client of mine, we noticed that during a checkout, no error messages are being returned by the pipelines.
Let me explain:
Let say you write a pipeline component that looks like this:
[ComVisible(true)]
[GuidAttribute ("D452305E-50C9-4031-BC94-6839BE6066EE")]
public class MyPipelineComponentClass : IPipelineComponent
{
// Status codes for pipeline components
private const Int32 StatusSuccess = 1; // success
private const Int32 StatusWarning = 2; // warning
private const Int32 StatusError = 3; // error
#region IPipelineComponent Members
void IPipelineComponent.EnableDesign(int fEnable){}
int IPipelineComponent.Execute(object pdispOrder, object pdispContext, int lFlags)
{
Int32 ReturnValue = StatusWarning;
// TODO: add code for the pipeline
IDictionary Order = (IDictionary)pdispOrder;
string ErrorMessage = "Something is wrong"
((ISimpleList)Order["_Basket_Errors").Add(ref ErrorMessage);
return ReturnValue;
}
#endregion
}
Very simple and to the point. Always return an error.
Now, since the return status is a warning, in the Order Review Page in the extensibility kit, you’ll always have a null Order. Your basket, however, will not have those error messages in its PurchaseErrors and BasketErrors properties.
Clearly, this is a bug (Which I submitted in Connect and waiting for an official fix)
But, there is a relatively simple solution. You can workaroud this issue by creating a simple operation sequence to copy those messages back to the order form like so:
public override void ExecuteUpdate(Microsoft.Commerce.Contracts.Messages.CommerceUpdateOperation updateOperation,
Microsoft.Commerce.Broker.OperationCacheDictionary operationCache,
Microsoft.Commerce.Contracts.Messages.CommerceUpdateOperationResponse response)
{
OrderGroup cachedCommerceServerOrderGroup = operationCache.GetCachedCommerceServerOrderGroup();
OrderForm defaultOrderForm = cachedCommerceServerOrderGroup.GetDefaultOrderForm();
ISimpleList BasketErrorList = defaultOrderForm["_Basket_Errors"] as ISimpleList;
ISimpleList PurchaseErrorList = defaultOrderForm["_Purchase_Errors"] as ISimpleList;
if (((BasketErrorList != null) && (BasketErrorList.Count != 0)))
{
if (BasketErrorList.Count > 0)
{
List<string> basketerrorstringList = new List<string>();
foreach (string error in BasketErrorList)
{
basketerrorstringList.Add(error);
}
foreach (var entity in response.CommerceEntities)
{
if (entity.ModelName == "Basket")
{
if (!entity.Properties.ContainsProperty("BasketErrors"))
{
entity.Properties.Add("BasketErrors", basketerrorstringList.ToArray());
}
else
{
entity.Properties["BasketErrors"] = basketerrorstringList.ToArray();
}
}
}
}
}
if (((PurchaseErrorList != null) && (PurchaseErrorList.Count != 0)))
{
if (PurchaseErrorList.Count > 0)
{
List<string> basketerrorstringList = new List<string>();
foreach (string error in PurchaseErrorList)
{
basketerrorstringList.Add(error);
}
foreach (var entity in response.CommerceEntities)
{
if (entity.ModelName == "Basket")
{
if (!entity.Properties.ContainsProperty("PurchaseErrors"))
{
entity.Properties.Add("PurchaseErrors", basketerrorstringList.ToArray());
}
else
{
entity.Properties["PurchaseErrors"] = basketerrorstringList.ToArray();
}
}
}
}
}
}
public override void ExecuteQuery(CommerceQueryOperation queryOperation,
Microsoft.Commerce.Broker.OperationCacheDictionary operationCache,
CommerceQueryOperationResponse response)
{
}
Now, add your component just before the basket committer operation in your Channelconfiguration.config file int Basket Update Message section.
Voila, your message are now available.
Tags: commerce server 2009