Order Shipment Object Extension

We are extending the shipment object in the orders system to support additional properties.We have:

1. Inherited from the shipment class and extended the derived class

2. Modified the OrderObjectMappings.xml file

3. Extended the OrderPipelineMappings.xml file

4. Modified the web.config to point to the new type

5. Ran the OrderMapping.exe tool to generate a new SQL script and ran this script on the database

When creating a basket and populating the derived shipment object, we are able to see the extended properties without any problems.

Everything is working perfectly up to the point where the "Total" pipeline runs. When this pipeline runs it creates an instance of the derived class correctly, however, fails to reconstitute the extended properties - all base properties are reconstituted. It appears as though the pipeline does not call the protected constructor when instantiating the class. Instead, it is using the public constructor and sets the properties using the public setters. When this happens the derived shipment class is saved correctly, however, because the extended properties where never set, they are lost.

Is it necessary to customize the pipeline to manually set the extended properties for the derived shipment class?

As an FYI, we have extended the OrderForm, OrderAddress, and LineItems classes and have not run into this problem. And note this is not creating a custom shipment method, this is a custom Shipment class created and associated the OrderForm.Shipments collection.

Thanks!

[1611 byte] By [PaulWash] at [2008-1-9]
# 1

Dear Paul,

I have extended the Shipment Class before and did wen't into many problems until i have found the solution. There is a set of things that you need to do before your Shipment Extension works fine:

1- Make sure your Extended Shipment Class contains the following:

public ExtendedShipment(SerializationInfo info, StreamingContext context)
: base(info, context)
{
try
{
this.ShippingWeight = (string)info.GetValue("ShippingWeight", typeof(string));
}
catch (Exception ex)
{
throw new Exception("Commerce Server Extension Error : " + ex.Message);
}
}


/// <summary>
/// Get object method will be called by commmerce runtime when /// the object is getting serialized to store in database.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
try
{
base.GetObjectData(info, context);
info.AddValue("ShippingWeight", this.ShippingWeight);
}
catch (Exception)
{
throw new Exception("Commerce Server Extension Error : " + ex.Message);
}
}

2- Update OrderObjectMappings as follows:

1- <Table Name="Shipments">
<Columns>

...
<Column Name="ShippingWeight" DataType="nvarchar" Precision="4000" IsNullable="true" />

2- <Class Name="ExtendedShipment">

<Property Name="ShippingWeight">

</Property>

3- <CollectionRelationships>

<CollectionRelationship Name="OrderFormShipments" ParentClass="OrderForm" ParentProperty="Shipments" ChildClass="ExtendedShipment" />

<CollectionRelationship Name="ShipmentDiscountsShipping" ParentClass="ExtendedShipment" ParentProperty="ShippingDiscounts" ChildClass="ShippingDiscountRecord" />

4- <ClassTableMap Class="ExtendedShipment" Table="Shipments">

<PropertyMap Property="ShippingWeight" Column="ShippingWeight">

</PropertyMap>

3- Update OrderPipelineMappings as follows:

1- <Collection Name="Shipments" DictionaryKey="shipments" KeyType="SimpleList" ReferTo="ExtendedShipment" />

2- <Class Name="ExtendedShipment">

<Property Name="ShippingWeight" DictionaryKey="ShippingWeight">

</Property>

</Class>

4- Update Web.config as follows:

<orders ...

<Types>

<Type Key="Shipment" UserTypeName="ExtendedShipment" AssemblyType="Local" NameSpace="OrderExtensions" Assembly="CommerceServerExtensions"/>

5- Test your extended shipment class as follows:

foreach (ExtendedShipment shipment in order.OrderForms[OrderForm.DefaultOrderFormName].Shipments)

{

shipment.ShippingWeight= “X Kg”;

}

// Save Basket Changes

// RunTotal Pipeline

// Try to Load Shipments again and check the Shipping Weight Value

Have a good day.

Sami Haydamous

SamiHaydamous at 2007-10-2 > top of Msdn Tech,Commerce Server,Commerce Server 2007...
# 2
Thanks Sami. Unfortunately, I did all of this - I went through and validated each step again. Everything works fine until the Total Pipeline runs - the Basket pipeline works fine. I think I need to dump the order and peak inside of everything when the total pipeline runs - I have just used the standard tracing. Stay tuned...
PaulWash at 2007-10-2 > top of Msdn Tech,Commerce Server,Commerce Server 2007...