Monday, February 11, 2008

Commerce Server 2007 - Extending the PurchaseOrder

The purchase order table in CS 2007 comes with a limited default storage columns.
What if you want to add new columns to this table that would be used to hmmm...
lets say query the PO table. the answer is simple: Extend the PurchaseOrder !

Here is how I have dunit.

1. Extend the PurchaseOrder class (lets call it ExtendedPurchaseOrder and define the property that you would like to store in the Commerce Server PurchaseOrders table in the transactions database.

2. Add the new columns to the following section of OrderObjectMappings.xml

<Table Name="PurchaseOrders">

3. Change the name of the class from PurchaseOrder to ExtendedPurchaseOrder in the following section

<Class Name="PurchaseOrder">

4. Add the new class property to table column mapping in the following section of the same xml:

<ClassTableMap Class="ExtendedPurchaseOrder" Table="PurchaseOrders">

5. Add the following section to the web.config file in the CommerceServer/Types section

<Type Key="PurchaseOrder" UserTypeName="EtxendedPurchaseOrder" AssemblyType="Local" NameSpace="YourClassLibraryNameSpace" Assembly="YourClassLibrary"/>

6. Create a new folder; say c:\temp and copy web.config, OrderObjectMappings.xml, YourClassLibrary.dll and the OrderMappings.exe to this folder. You should be able to find the OrderMappings.exe in the C:\Program Files\Microsoft Commerce Server 2007\Tools folder.

7. Open a Command window and run the following script to generate the SQL for Commerce server Transactions database.

OrderMappings -w web.config

8. You should a file OrdersStorage.sql being generate if the above command ran successfully.

9. Execute the SQL script in the OrdersStorage.sql file on the Commerce server transactions database after you have made the necessary schema change to the PurchaseOrders table.

10. Now you are ready to programatically insert custom data into the PurchaseOrders table.

11. I have inserted the Order Confirmation Number into the PurchaseOrders using the following code

ExtendedPurchaseOrder PO = (ExtendedPurchaseOrder ) this.Basket.SaveToReceipt();
PO.ConfirmationNumber = 100001;
PO.ListenerStatus = 1;
PO.Save("Site");

References:
1. MSDN Online

1 comments:

Anonymous said...

thanks caveman, you have expained the whole topic in a simple and easy to understand steps and very useful.
If you have time also add appropriate pipeline changes so that completes the whole process for some one who also using pipelines.