如何在Hybris中实现订单版本控制?

时间:2016-03-30 17:44:53

标签: e-commerce hybris

我在Hybris中有要求,因为用户将通过cron作业向SAP提交订单的任何订单,SAP正在处理订单并使用更新的订单号和其他详细信息更新回Hybris。我们想在Hybris中保留原始副本如何实现这一目标?

2 个答案:

答案 0 :(得分:2)

创建快照时Hybris创建订单的深层副本(创建所有子元素的副本),以区分快照和原始订单Hybris将版本ID和对原始版本的引用添加到快照( originalVersion,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 )

OrderHistoryService:

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);
}

答案 1 :(得分:0)

要创建订单版本控制,只需完成两个步骤:

  1. 创建新的OrderHistoryEntry

  2. 创建并附加快照。

  3. 更多详情为here