gpt4 book ai didi

atg - 如何在ATG中修改当前订单中一个commerceItem的数量?

转载 作者:行者123 更新时间:2023-12-04 04:35:54 29 4
gpt4 key购买 nike

我想使用 CartModifierFormHandler 修改当前订单中的 commerceItem 数量。

我已通过 catalogRefId & new quantity然后调用 CartModifierFormHandler.setOrderByCommerceIdsetOrder但它修改了除了我要修改的项目之外的所有项目的数量。有人能告诉我出了什么问题或怎么做吗?

最佳答案

如果您使用的是开箱即​​用的 setOrderByCommerceId方法(这绝对是要走的路,因为它已经处理了所有与事务相关的代码),那么您需要记住以下几点。
setOrderByCommerceId将调用 modifyOrderByCommerceId开箱即用 CartModifierFormHandler .这反过来调用 getQuantity

public long getQuantity(String pCatalogRefId, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws ServletException, IOException, NumberFormatException {
Object value = pRequest.getParameter(pCatalogRefId);
if (value != null) {
return Long.parseLong(value.toString());
}
return getQuantity();
}

所以从这个片段中应该清楚的是,除非你传递每个现有 commerceItem 的单独数量对于请求,您只需更新每个 commerceItem 的数量s 到相同的数量。

这是更新数量的简化版本:
public boolean handleUpdateItemQuantityToOrder(DynamoHttpServletRequest request, DynamoHttpServletResponse response) throws ServletException, IOException {
Order order = getOrder();

//Get All the Commerce Items on the Order
List<CommerceItem> commerceItems = order.getCommerceItems();
String currentSku = "";

// currentCommerceItem is the one that you passed from your JSP page
String currentId = getCurrentCommerceItem();

// Add all the existing commerce item quantities to the request
for (CommerceItem commerceItem : commerceItems) {
request.setParameter(commerceItem.getId(), commerceItem.getQuantity());
if (commerceItem.getId().equals(currentId)) {
currentSku = commerceItem.getCatalogRefId();
}
}

// the quantity element is from the JSP page. Set it to the Sku you want to change on the request.
request.setParameter(currentId, getQuantity());

// Set the new quantity for the commerce item being updated.
setCheckForChangedQuantity(true);

handleSetOrderByCommerceId(request, response); // Pass the order updates to a REAL ATG method so you don't have to write it yourself

return checkFormRedirect(getUpdateSuccessURL(), getUpdateErrorURL(), request, response);
}

希望这会有所帮助。

关于atg - 如何在ATG中修改当前订单中一个commerceItem的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19764325/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com