svn commit: r783369 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/order/ servicedef/ src/org/ofbiz/order/order/ src/org/ofbiz/order/shoppingcart/ src/org/ofbiz/order/shoppingcart/product/ webapp/ordermgr/order/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r783369 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/order/ servicedef/ src/org/ofbiz/order/order/ src/org/ofbiz/order/shoppingcart/ src/org/ofbiz/order/shoppingcart/product/ webapp/ordermgr/order/

ashish-18
Author: ashish
Date: Wed Jun 10 14:37:35 2009
New Revision: 783369

URL: http://svn.apache.org/viewvc?rev=783369&view=rev
Log:
Applied patch from jira issue OFBIZ-2527 (When editing items, Promotion Codes are getting deleted when we click Update Items.)
Thanks Ratnesh and Chirag for your contribution.

Modified:
    ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderSimpleMethods.xml
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
    ofbiz/trunk/applications/order/webapp/ordermgr/order/editorderitems.ftl

Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderSimpleMethods.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderSimpleMethods.xml?rev=783369&r1=783368&r2=783369&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderSimpleMethods.xml (original)
+++ ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderSimpleMethods.xml Wed Jun 10 14:37:35 2009
@@ -50,6 +50,13 @@
         <check-errors/>
         <entity-one entity-name="OrderAdjustment" value-field="lookedUpValue"/>
         <remove-value value-field="lookedUpValue"/>
+
+        <if-not-empty field="parameters.productPromoCodeId">
+            <entity-one entity-name="OrderProductPromoCode" value-field="lookedUpValue"/>
+            <if-not-empty field="lookedUpValue">
+                <remove-value value-field="lookedUpValue"/>
+            </if-not-empty>
+        </if-not-empty>
     </simple-method>
 
     <simple-method method-name="createOrderAdjustmentBilling" short-description="Create an OrderAdjustmentBilling">

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=783369&r1=783368&r2=783369&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Wed Jun 10 14:37:35 2009
@@ -133,6 +133,7 @@
         <attribute name="orderItemContactMechs" type="List" mode="IN" optional="true"/>
         <attribute name="orderItemPriceInfos" type="List" mode="IN" optional="true"/>
         <attribute name="orderProductPromoUses" type="List" mode="IN" optional="true"/>
+        <attribute name="orderProductPromoCodes" type="Set" mode="IN" optional="true"/>
         <attribute name="orderItemSurveyResponses" type="List" mode="IN" optional="true"/>
         <attribute name="trackingCodeOrders" type="List" mode="IN" optional="true"/>
         <attribute name="orderAdditionalPartyRoleMap" type="Map" mode="IN" optional="true"/>
@@ -198,6 +199,7 @@
         <description>Delete an order adjustment record</description>
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <attribute name="orderId" type="String" mode="IN" optional="false"/>  <!-- needed for resetGrandTotal seca -->
+        <attribute name="productPromoCodeId" type="String" mode="IN" optional="true"/>
     </service>
 
     <service name="createOrderAdjustmentBilling" engine="simple"

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=783369&r1=783368&r2=783369&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Wed Jun 10 14:37:35 2009
@@ -930,6 +930,19 @@
                 toBeStored.add(productPromoUse);
             }
         }
+        
+        // store the orderProductPromoCodes
+        Set orderProductPromoCodes = (Set) context.get("orderProductPromoCodes");
+        if (UtilValidate.isNotEmpty(orderProductPromoCodes)) {
+            GenericValue orderProductPromoCode = delegator.makeValue("OrderProductPromoCode");
+            Iterator orderProductPromoCodeIter = orderProductPromoCodes.iterator();
+            while (orderProductPromoCodeIter.hasNext()) {
+                orderProductPromoCode.clear();
+                orderProductPromoCode.set("orderId", orderId);
+                orderProductPromoCode.set("productPromoCodeId", orderProductPromoCodeIter.next());
+                toBeStored.add(orderProductPromoCode);
+            }
+        }
 
         /* DEJ20050529 the OLD way, where a single party had all roles... no longer doing things this way...
         // define the roles for the order
@@ -3556,9 +3569,6 @@
             }
         }
 
-        // run promotions to handle all changes in the cart
-        ProductPromoWorker.doPromotions(cart, dispatcher);
-
         // save all the updated information
         try {
             saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, UtilMisc.toMap("itemReasonMap", itemReasonMap, "itemCommentMap", itemCommentMap));
@@ -3566,6 +3576,9 @@
             return ServiceUtil.returnError(e.getMessage());
         }
 
+        // run promotions to handle all changes in the cart
+        ProductPromoWorker.doPromotions(cart, dispatcher);
+        
         // log an order note
         try {
             dispatcher.runSync("createOrderNote", UtilMisc.<String, Object>toMap("orderId", orderId, "note", "Updated order.", "internalNote", "Y", "userLogin", userLogin));

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=783369&r1=783368&r2=783369&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Wed Jun 10 14:37:35 2009
@@ -3948,6 +3948,7 @@
         result.put("orderTerms", this.getOrderTerms());
         result.put("orderItemPriceInfos", this.makeAllOrderItemPriceInfos());
         result.put("orderProductPromoUses", this.makeProductPromoUses());
+        result.put("orderProductPromoCodes", this.getProductPromoCodesEntered());
 
         result.put("orderAttributes", this.makeAllOrderAttributes());
         result.put("orderItemAttributes", this.makeAllOrderItemAttributes());

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java?rev=783369&r1=783368&r2=783369&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java Wed Jun 10 14:37:35 2009
@@ -379,6 +379,15 @@
                         // check if promo code required
                         if (requireCode) {
                             Set enteredCodes = cart.getProductPromoCodesEntered();
+                            // Check whether any promotion code is applied on order.
+                            if (cart.getOrderId() != null) {
+                                List orderproductPromoCodes =  delegator.findList("OrderProductPromoCode", EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, cart.getOrderId()), null, null, null, false);
+                                Iterator orderproductPromoCodesItr = UtilMisc.toIterator(orderproductPromoCodes);
+                                while (orderproductPromoCodesItr != null && orderproductPromoCodesItr.hasNext()) {
+                                    GenericValue orderproductPromoCode = (GenericValue) orderproductPromoCodesItr.next();
+                                    enteredCodes.add(orderproductPromoCode.getString("productPromoCodeId"));
+                                }
+                            }
                             if (enteredCodes.size() > 0) {
                                 // get all promo codes entered, do a query with an IN condition to see if any of those are related
                                 EntityCondition codeCondition = EntityCondition.makeCondition(EntityCondition.makeCondition("productPromoId", EntityOperator.EQUALS, productPromoId), EntityOperator.AND, EntityCondition.makeCondition("productPromoCodeId", EntityOperator.IN, enteredCodes));

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/order/editorderitems.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/editorderitems.ftl?rev=783369&r1=783368&r2=783369&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/order/editorderitems.ftl (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/order/editorderitems.ftl Wed Jun 10 14:37:35 2009
@@ -275,6 +275,20 @@
             <#assign adjustmentType = orderHeaderAdjustment.getRelatedOne("OrderAdjustmentType")>
             <#assign adjustmentAmount = Static["org.ofbiz.order.order.OrderReadHelper"].calcOrderAdjustment(orderHeaderAdjustment, orderSubTotal)>
             <#assign orderAdjustmentId = orderHeaderAdjustment.get("orderAdjustmentId")>
+            <#assign productPromoCodeId = ''>
+            <#if adjustmentType.get("orderAdjustmentTypeId") == "PROMOTION_ADJUSTMENT" && orderHeaderAdjustment.get("productPromoId")?has_content>
+                <#assign productPromo = orderHeaderAdjustment.getRelatedOne("ProductPromo")>
+                <#assign productPromoCodes = delegator.findByAnd("ProductPromoCode", {"productPromoId":productPromo.productPromoId})>
+                <#assign orderProductPromoCode = ''>
+                <#list productPromoCodes as productPromoCode>
+                    <#if !(orderProductPromoCode?has_content)>
+                        <#assign orderProductPromoCode = delegator.findOne("OrderProductPromoCode", {"productPromoCodeId":productPromoCode.productPromoCodeId, "orderId":orderHeaderAdjustment.orderId}, false)?if_exists>
+                    </#if>
+                </#list>
+                <#if orderProductPromoCode?has_content>
+                    <#assign productPromoCodeId = orderProductPromoCode.get("productPromoCodeId")>
+                </#if>
+            </#if>
             <#if adjustmentAmount != 0>
                 <form name="updateOrderAdjustmentForm${orderAdjustmentId}" method="post" action="<@ofbizUrl>updateOrderAdjustment</@ofbizUrl>">
                     <input type="hidden" name="orderAdjustmentId" value="${orderAdjustmentId?if_exists}"/>
@@ -306,6 +320,9 @@
                 <form name="deleteOrderAdjustment${orderAdjustmentId}" method="post" action="<@ofbizUrl>deleteOrderAdjustment</@ofbizUrl>">
                     <input type="hidden" name="orderAdjustmentId" value="${orderAdjustmentId?if_exists}"/>
                     <input type="hidden" name="orderId" value="${orderId?if_exists}"/>
+                    <#if adjustmentType.get("orderAdjustmentTypeId") == "PROMOTION_ADJUSTMENT">
+                        <input type="hidden" name="productPromoCodeId" value="${productPromoCodeId?if_exists}"/>
+                    </#if>
                 </form>
             </#if>
         </#list>