Wondering if anyone can tell me where/how Hybris is generating versionIDs for orders on amendment etc
Thanks
Wondering if anyone can tell me where/how Hybris is generating versionIDs for orders on amendment etc
Thanks
The Order VersionID is generated in the DefaultOrderHistoryService.createHistorySnapshot(OrderModel) using the KeyGenerator
The versionID is assigned to the order in case of order cancellation, return or replacement.
The full reference to the Service ; de.hybris.platform.orderhistory.impl.DefaultOrderHistoryService
The purpose of maintaining Order History and Order Versioning is to keep track of changes applied to the order which help customer service agents to look what actually happened to a particular order.
OrderHistoryEntry is used to store historical information of order processing. This will not create a new version of original order but can have a reference to an order state snapshot.
OrderHistoryEntryModel entry = modelService.create(OrderHistoryEntryModel.class);
entry.setTimestamp(new Date());
entry.setOrder(processedOrder);
entry.setDescription("fraud check manually passed");
entry.setEmployee( (EmployeeModel)userService.getCurrentUser() );
To keep the previous order state as historical information requires the creation a snapshot of the order before altering the order. This will create a new version of original order. Each snapshot will contain particular versionID.
OrderHistoryService historyService = ..
// create snapshot - not persisted yet !
OrderModel snapshot = historyService.createHistorySnapshot(processedOrder);
The service will produces a deep copy of the original order.
Now we can save this snapshot in OrderHistoryEntryModel as well.
entry.setPreviousOrderVersion(snapshot);
We need to manually persist snapshot
// persist snapshot manually - this is necessary due to historical reasons
historyService.saveHistorySnapshot(snapshot);
Since snapshot is also like order and resides in same table, to fetch all original order, you need to apply {versionID} IS NULL condition as well while fetching orders.