Basket (ICommerceEntity) vs. Microsoft.Commerce.Runime.Orders.Basket-Collection of common programming errors

Gadi-

As you’ve correctly inferred, the OrderGroup and OrderForm objects are part of the CS2007 Microsoft.CommerceServer.Runtime namespace, and have not been migrated over to the CS2009 Microsoft.Commerce.Portal.Common namespace.  My best advice is to avoid assuming that the API refresh maintains 1-to-1 fidelity between 07 and 09– in practical use, most applications did not leverage more than one OrderGroup or OrderForm per basket, so the CS09 API tried to make this a little simpler by not even providing that option.  Additionally, the entity model in CS09 tries to push developers toward more strongly-typed objects instead of the confusing string,object dictionary model that was more common in Commerce Server 2007. 

As a general rule, I would recommend sticking as close to the CS09 API as possible (as Ravi points out, that should make it easier to do future upgrades) unless there is something that functionally cannot be accomplished with the 09 API.

The CS09 entities are quite flexibile when you start working with them; here are some general tips:

1) Crack open your MetadataDefinitions.xml file and do a search for CommerceEntity name=”Basket”.  Interestingly enough, you’ll notice that this object actually maps up to the Microsoft.CommerceServer.Runtime.Orders.OrderForm object.  (Somewhat counterintuitive, I know!), also, take a look at the PropertyMappings – there should be 1 for each property on your Microsoft.Commerce.Portal.Common.Basket object, as well as the corresponding property on your OrderForm object.  For example, Basket.UserId is the same thing as OrderForm[“SoldToId”].

2) If you need to add new properties to the Basket object: –a) change the database (Same as CS2007) –b) change the OrderObjectMapping.xml (same as CS2007) –c) change the OrderPipelineMapping.xml (same as CS2007)

–d) update your MetadataDefinition.xml to include the new property

Once the new property is defined in the MetadataDefinition.xml file, Commerce Server is smart enough to populate that object on the CommerceEntity’s internal dictionary, so you can either access it via the item indexer on the CommerceEntity, or you can inherit from the Basket class and create a property on your new class which strongly-types and wraps the new property.