We had a requirement to migrate the orders from XC 9.0 to 9.3. With XC 9.0, the shared environments database has two tables related to the order. One for the order entities & the other table for the orders list.Whereas with the XC 9.3, there are 3 tables in the shared environment related to the order.When an order is created in sitecore 9.3 there are 3 rows created in OrdersEntities & OrdersEntity tables in the SharedEnvironments database. Two entries for index and one for the order entity. The actual order entity lives in the OrdersEntity table.
To migrate orders from XC 9.0 to XC 9.3, the following steps need to be performed.
Get XC 9.0 order raw entities
First we need to get the list of orders using orders API. We can get the raw json for an order entity using the “GetRawEntity” api call.
For the orders with “InProcess” status we need to get the raw json for the “Cart” entity
To get the cart json, we can use the “temporary cart” component from the order json. This component has the entity id of the cart as “EntityTarget” property. We can use this entity id with the “GetRawEntity” api call to get the cart raw json.
For the orders with other statuses we need to get the raw json for the “Sales Activity” entity.
To get the sales activity json, we can use the “Sales Activity” element from the order json. The sales activity has an entity reference element of type “Sitecore.Commerce.Core.EntityReference”. This element has the entity id of the sales activity as “EntityTarget” property. We can use this entity id with the “GetRawEntity” api call to get the sales activity raw json.
Modify XC 9.0 order raw entities
Using an order from XC 9.3 as reference modify the orders from 9.0. “UniqueId” has been added to the standard 9.3 order, sales activity & cart jsons when compared to the 9.0 order. For the “EntityTarget” on the 9.3 sales activity json “EntityTargetUniqueId” has been added.After modifying the entities based on these changes, they are now ready to be imported to XC 9.3
Migrate Modified order raw entities
For XC 9.3, depending on the entity that we need to migrate we have multiple tables that we need to insert a record. These are the tables & the values that we need for the order & related entities along with the standard values (ex: artifactId, entityVersion etc) depending on the table structure:
Order:
Table | Values |
[sitecore_commerce_storage].[OrdersEntities] | Order uniqueId & Order Id |
[sitecore_commerce_storage].[OrdersEntity] | Order uniqueId & the Order raw json |
[sitecore_commerce_storage].[OrdersLists] | Memberships(ex: List-InProcess-ByDate) & OrderId |
Cart:
Table | Values |
[sitecore_commerce_storage].[CommerceEntities] | Cart uniqueId & CartId |
[sitecore_commerce_storage].[CommerceEntity] | Cart uniqueId & the Cart raw json |
Sales Activity:
Table | Values |
[sitecore_commerce_storage].[OrdersEntities] | SalesActivity uniqueId & SalesActivity Id |
[sitecore_commerce_storage].[OrdersEntity] | SalesActivity uniqueId & the SalesActivity raw json |
[sitecore_commerce_storage].[OrdersLists] | Memberships(ex: List-InProcess-ByDate) & SalesActivity Id |