diff --git a/applications/order/config/OrderUiLabels.xml b/applications/order/config/OrderUiLabels.xml index 4fdf104090..af75e492ef 100644 --- a/applications/order/config/OrderUiLabels.xml +++ b/applications/order/config/OrderUiLabels.xml @@ -3018,6 +3018,10 @@ 内容 內容 + + Remove Promotion + Supprimer la promotion + Dále k závěrečnému přehledu objednávky Weiter zur abschließenden Bestellüberprüfung diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java index cbf8f75d52..7b5c7bf372 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java @@ -3150,6 +3150,21 @@ public class ShoppingCart implements Iterable, Serializable { this.productPromoUseInfoList.add(new ProductPromoUseInfo(productPromoId, productPromoCodeId, totalDiscountAmount, quantityLeftInActions)); } + public void removeProductPromoUse(String productPromoId) { + if (!productPromoId.isEmpty()) { + int index = -1; + for (ProductPromoUseInfo productPromoUseInfo : this.productPromoUseInfoList) { + if (productPromoId.equals(productPromoUseInfo.productPromoId)) { + index = this.productPromoUseInfoList.indexOf(productPromoUseInfo); + break; + } + } + if (index != -1) { + this.productPromoUseInfoList.remove(index); + } + } + } + public void clearProductPromoUseInfo() { // clear out info for general promo use this.productPromoUseInfoList.clear(); diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java index a4503a90cf..32a7479661 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java @@ -23,6 +23,7 @@ import java.math.MathContext; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Enumeration; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -53,6 +54,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.order.shoppingcart.ShoppingCart.ProductPromoUseInfo; import org.ofbiz.order.shoppingcart.product.ProductPromoWorker; import org.ofbiz.product.catalog.CatalogWorker; import org.ofbiz.product.config.ProductConfigWorker; @@ -96,6 +98,58 @@ public class ShoppingCartEvents { return "success"; } + public static String removePromotion(HttpServletRequest request,HttpServletResponse response) { + LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + ShoppingCart cart = getCartObject(request); + String promoCodeId = (String) request.getParameter("promoCode"); + String result = "error"; + + if (!promoCodeId.isEmpty()) { + cart.getProductPromoCodesEntered().clear(); + GenericValue productPromoCode = null; + try { + productPromoCode = dispatcher.getDelegator().findOne("ProductPromoCode", UtilMisc.toMap("productPromoCodeId", promoCodeId), false); + if (!productPromoCode.isEmpty()) { + String productPromoId = productPromoCode.getString("productPromoId"); + GenericValue productPromoAction = null; + Map productPromoActionMap = new HashMap(); + productPromoActionMap.put("productPromoId", productPromoId); + productPromoActionMap.put("productPromoRuleId", "01"); + productPromoActionMap.put("productPromoActionSeqId", "01"); + + productPromoAction = dispatcher.getDelegator().findOne("ProductPromoAction", productPromoActionMap, false); + if (!productPromoAction.isEmpty()) { + int index = cart.getAdjustmentPromoIndex(productPromoId); + /*Remove order adjustment*/ + if (index != -1) { + cart.removeAdjustment(index); + result = "success"; + } + + /*Remove product adjustment*/ + for(ShoppingCartItem checkItem : cart) { + List itemAdjustments = checkItem.getAdjustments(); + if (!itemAdjustments.isEmpty()) { + index = 0; + for (GenericValue adjustment : itemAdjustments ) { + if(adjustment.get("productPromoId").equals(productPromoId)) { + checkItem.getAdjustments().remove(index); + result = "success"; + } + index++; + } + } + } + cart.removeProductPromoUse(productPromoId); + } + } + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + } + } + return result; + } + public static String addItemGroup(HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = getCartObject(request); Map parameters = UtilHttp.getParameterMap(request); diff --git a/applications/order/webapp/ordermgr/WEB-INF/controller.xml b/applications/order/webapp/ordermgr/WEB-INF/controller.xml index 9756117624..d4ea756886 100644 --- a/applications/order/webapp/ordermgr/WEB-INF/controller.xml +++ b/applications/order/webapp/ordermgr/WEB-INF/controller.xml @@ -663,6 +663,12 @@ under the License. + + + + + + diff --git a/applications/order/webapp/ordermgr/entry/cart/promoUseDetailsInline.ftl b/applications/order/webapp/ordermgr/entry/cart/promoUseDetailsInline.ftl index b72c8619ca..0db1fcc699 100644 --- a/applications/order/webapp/ordermgr/entry/cart/promoUseDetailsInline.ftl +++ b/applications/order/webapp/ordermgr/entry/cart/promoUseDetailsInline.ftl @@ -27,6 +27,9 @@ under the License. ${uiLabelMap.OrderPromotion} ${uiLabelMap.CommonDetails} <#if productPromoUseInfo.productPromoCodeId?has_content> - ${uiLabelMap.OrderWithPromoCode} [${productPromoUseInfo.productPromoCodeId}] <#if (productPromoUseInfo.totalDiscountAmount != 0)> - ${uiLabelMap.CommonTotalValue} <@ofbizCurrency amount=(-1*productPromoUseInfo.totalDiscountAmount) isoCode=shoppingCart.getCurrency()/> + <#if productPromoUseInfo.productPromoCodeId?has_content> + ${uiLabelMap.OrderRemovePromotion} + <#if (productPromoUseInfo.quantityLeftInActions > 0)>
  • - Could be used for ${productPromoUseInfo.quantityLeftInActions} more discounted item<#if (productPromoUseInfo.quantityLeftInActions > 1)>s if added to your cart.
  • diff --git a/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml b/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml index c351a850a0..26da04eeac 100644 --- a/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml +++ b/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml @@ -321,6 +321,12 @@ under the License. + + + + + +