如何在新创建的 CartModel 中添加购物车条目?
How to add cart entries in newly-created CartModel?
我使用以下代码创建了一个购物车并在此 CartModel 中添加了一个 cartEntry:
final CartModel cartModel = cartFactory.createCart() ;
OrderEntryModel orderEntryModel = new OrderEntryModel();
List<AbstractOrderEntryModel> entryModel = new ArrayList<>();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
orderEntryModel.setProduct(product);
entryModel.add(orderEntryModel);
cartModel.setEntries(entryModel);
cartModel.setUser(userService.getCurrentUser());
cartService.setSessionCart(cartModel);
当我尝试从会话中获取此购物车、应用此购物车并将此购物车传递给下一个另一个 OOTB 方法时,出现以下异常:
DefultAbstractOrderEntryPreparer@1090ef7e]: unexpected preparer error: null] with root cause
java.lang.NullPointerException
at de.hybris.platform.order.interceptors.DefaultAbstractOrderEntryPreparer.onPrepare(DefaultAbstractOrderEntryPreparer.java:97)
调试后,我知道出现此问题是因为我添加订单条目的方式与我们在正常结账流程中使用的方式不同(第一个代码块,倒数第三行)。
那么,是否有任何 OOTB 方法或任何其他方法来创建 orderEntry 并将其添加到新创建的购物车?
我检查了在结账流程中创建的普通购物车,并没有发生这个问题。所以,我得出的结论是,这是由于第一个代码块中的以下代码造成的:
OrderEntryModel orderEntryModel = new OrderEntryModel();
List<AbstractOrderEntryModel> entryModel = new ArrayList<>();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
orderEntryModel.setProduct(product);
entryModel.add(orderEntryModel);
cartModel.setEntries(entryModel);
有一个名为 cartService 的标准服务,作为 addNewEntry 方法。
final CartModel cartModel = cartFactory.createCart();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
getCartService().addNewEntry(cartModel, product, 1, null);
cartModel.setUser(userService.getCurrentUser());
cartService.setSessionCart(cartModel);
我使用以下代码创建了一个购物车并在此 CartModel 中添加了一个 cartEntry:
final CartModel cartModel = cartFactory.createCart() ;
OrderEntryModel orderEntryModel = new OrderEntryModel();
List<AbstractOrderEntryModel> entryModel = new ArrayList<>();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
orderEntryModel.setProduct(product);
entryModel.add(orderEntryModel);
cartModel.setEntries(entryModel);
cartModel.setUser(userService.getCurrentUser());
cartService.setSessionCart(cartModel);
当我尝试从会话中获取此购物车、应用此购物车并将此购物车传递给下一个另一个 OOTB 方法时,出现以下异常:
DefultAbstractOrderEntryPreparer@1090ef7e]: unexpected preparer error: null] with root cause
java.lang.NullPointerException
at de.hybris.platform.order.interceptors.DefaultAbstractOrderEntryPreparer.onPrepare(DefaultAbstractOrderEntryPreparer.java:97)
调试后,我知道出现此问题是因为我添加订单条目的方式与我们在正常结账流程中使用的方式不同(第一个代码块,倒数第三行)。
那么,是否有任何 OOTB 方法或任何其他方法来创建 orderEntry 并将其添加到新创建的购物车?
我检查了在结账流程中创建的普通购物车,并没有发生这个问题。所以,我得出的结论是,这是由于第一个代码块中的以下代码造成的:
OrderEntryModel orderEntryModel = new OrderEntryModel();
List<AbstractOrderEntryModel> entryModel = new ArrayList<>();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
orderEntryModel.setProduct(product);
entryModel.add(orderEntryModel);
cartModel.setEntries(entryModel);
有一个名为 cartService 的标准服务,作为 addNewEntry 方法。
final CartModel cartModel = cartFactory.createCart();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
getCartService().addNewEntry(cartModel, product, 1, null);
cartModel.setUser(userService.getCurrentUser());
cartService.setSessionCart(cartModel);