如何在 Hybris 中实现订单版本控制?
How to implement order versioning in Hybris?
我在 Hybris 中有要求,因为当用户下订单时,我们通过 cron 作业向 SAP 提交订单,SAP 正在处理订单并使用更新的订单号和其他详细信息更新回 Hybris。我们想在 Hybris 中保留原始副本如何实现?
创建快照时,Hybris 创建订单的深层副本(创建所有子元素的副本),以区分快照和原始订单,Hybris 添加版本 ID 和对原始版本的引用到快照(原始版本,versionId)。从原始订单您可以看到订单历史选项卡中所有快照的列表。
从 HMC 您将看到所有重复的订单,但从用户的角度来看,您将仅看到原始版本,因为客户帐户 DAO 仅加载没有版本 ID '{" + OrderModel.VERSIONID + "} IS NULL 的订单'
使用 Groovy 的示例:
import de.hybris.platform.orderhistory.OrderHistoryService
import de.hybris.platform.servicelayer.search.FlexibleSearchService
import de.hybris.platform.store.services.BaseStoreService
import de.hybris.platform.core.model.order.OrderModel
import de.hybris.platform.core.model.user.UserModel
import de.hybris.platform.orderhistory.model.OrderHistoryEntryModel
import de.hybris.platform.servicelayer.model.ModelService
import de.hybris.platform.servicelayer.user.UserService
import java.util.Collection
import java.util.Iterator
import de.hybris.platform.store.BaseStoreModel
import de.hybris.platform.commerceservices.customer.dao.CustomerAccountDao
BaseStoreService bss = spring.getBean("baseStoreService")
UserService us = spring.getBean("userService")
FlexibleSearchService fss = spring.getBean("flexibleSearchService")
OrderHistoryService ohs =spring.getBean("orderHistoryService")
ModelService ms = spring.getBean("modelService")
CustomerAccountDao cad = spring.getBean("customerAccountDao")
BaseStoreModel baseStore = bss.getBaseStoreForUid("electronics")
UserModel user = userService.getUserForUID("customerUID")
Collection<OrderModel> orders = user.getOrders()
OrderModel order = cad.findOrderByCodeAndStore("orderCode", baseStore)
OrderModel orderSnap = ohs.createHistorySnapshot(order)
OrderHistoryEntryModel entry = modelService.create(OrderHistoryEntryModel.class)
entry.setTimestamp(new Date())
entry.setOrder(order)
entry.setDescription("Took a snap")
entry.setPreviousOrderVersion(orderSnap)
ohs.saveHistorySnapshot(orderSnap)
modelService.saveAll( order, entry, orderSnap )
订单历史服务:
public abstract interface OrderHistoryService
{
public abstract OrderModel createHistorySnapshot(OrderModel paramOrderModel);
public abstract void saveHistorySnapshot(OrderModel paramOrderModel);
public abstract Collection<OrderModel> getHistorySnapshots(OrderModel paramOrderModel);
public abstract Collection<OrderHistoryEntryModel> getHistoryEntries(OrderModel paramOrderModel, Date paramDate1, Date paramDate2);
public abstract Collection<String> getHistoryEntriesDescriptions(OrderModel paramOrderModel, Date paramDate1, Date paramDate2);
public abstract Collection<OrderHistoryEntryModel> getHistoryEntries(OrderModel paramOrderModel, EmployeeModel paramEmployeeModel);
public abstract Collection<OrderHistoryEntryModel> getHistoryEntries(UserModel paramUserModel, Date paramDate1, Date paramDate2);
}
为了创建订单版本控制,只需完成两个步骤:
正在创建一个新的 OrderHistoryEntry
创建并附加快照。
更多详情是here
我在 Hybris 中有要求,因为当用户下订单时,我们通过 cron 作业向 SAP 提交订单,SAP 正在处理订单并使用更新的订单号和其他详细信息更新回 Hybris。我们想在 Hybris 中保留原始副本如何实现?
创建快照时,Hybris 创建订单的深层副本(创建所有子元素的副本),以区分快照和原始订单,Hybris 添加版本 ID 和对原始版本的引用到快照(原始版本,versionId)。从原始订单您可以看到订单历史选项卡中所有快照的列表。
从 HMC 您将看到所有重复的订单,但从用户的角度来看,您将仅看到原始版本,因为客户帐户 DAO 仅加载没有版本 ID '{" + OrderModel.VERSIONID + "} IS NULL 的订单'
使用 Groovy 的示例:
import de.hybris.platform.orderhistory.OrderHistoryService
import de.hybris.platform.servicelayer.search.FlexibleSearchService
import de.hybris.platform.store.services.BaseStoreService
import de.hybris.platform.core.model.order.OrderModel
import de.hybris.platform.core.model.user.UserModel
import de.hybris.platform.orderhistory.model.OrderHistoryEntryModel
import de.hybris.platform.servicelayer.model.ModelService
import de.hybris.platform.servicelayer.user.UserService
import java.util.Collection
import java.util.Iterator
import de.hybris.platform.store.BaseStoreModel
import de.hybris.platform.commerceservices.customer.dao.CustomerAccountDao
BaseStoreService bss = spring.getBean("baseStoreService")
UserService us = spring.getBean("userService")
FlexibleSearchService fss = spring.getBean("flexibleSearchService")
OrderHistoryService ohs =spring.getBean("orderHistoryService")
ModelService ms = spring.getBean("modelService")
CustomerAccountDao cad = spring.getBean("customerAccountDao")
BaseStoreModel baseStore = bss.getBaseStoreForUid("electronics")
UserModel user = userService.getUserForUID("customerUID")
Collection<OrderModel> orders = user.getOrders()
OrderModel order = cad.findOrderByCodeAndStore("orderCode", baseStore)
OrderModel orderSnap = ohs.createHistorySnapshot(order)
OrderHistoryEntryModel entry = modelService.create(OrderHistoryEntryModel.class)
entry.setTimestamp(new Date())
entry.setOrder(order)
entry.setDescription("Took a snap")
entry.setPreviousOrderVersion(orderSnap)
ohs.saveHistorySnapshot(orderSnap)
modelService.saveAll( order, entry, orderSnap )
订单历史服务:
public abstract interface OrderHistoryService
{
public abstract OrderModel createHistorySnapshot(OrderModel paramOrderModel);
public abstract void saveHistorySnapshot(OrderModel paramOrderModel);
public abstract Collection<OrderModel> getHistorySnapshots(OrderModel paramOrderModel);
public abstract Collection<OrderHistoryEntryModel> getHistoryEntries(OrderModel paramOrderModel, Date paramDate1, Date paramDate2);
public abstract Collection<String> getHistoryEntriesDescriptions(OrderModel paramOrderModel, Date paramDate1, Date paramDate2);
public abstract Collection<OrderHistoryEntryModel> getHistoryEntries(OrderModel paramOrderModel, EmployeeModel paramEmployeeModel);
public abstract Collection<OrderHistoryEntryModel> getHistoryEntries(UserModel paramUserModel, Date paramDate1, Date paramDate2);
}
为了创建订单版本控制,只需完成两个步骤:
正在创建一个新的 OrderHistoryEntry
创建并附加快照。
更多详情是here