Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-7263

Price rule created with product specific quantity condition not applied to the order when adding the product to cart with less quantity than mentioned in condition

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Trunk, Release Branch 16.11
    • Fix Version/s: Upcoming Release
    • Component/s: order
    • Labels:
      None

      Description

      Steps to regenerate the issue:
      1. Create a price rule.
      2. Add a condition, select input 'Quantity', operator 'Is' and add the value '2' or any quantity more than 1.
      3. Add an action, select action type 'Flat Amount Override' and add it's value.
      4. Create a sale order:
      i. Add product with quantity one to the order.
      ii. Update the quantity to 2 or to the value entered in condition for quantity in price rule.
      iii. Recalculate the order.

      Expected result: Unit price should override to the amount added in action.

      Actual result: It's not getting overridden to the amount added in action.

      1. OFBIZ-7263.patch
        0.9 kB
        Aditi Patidar

        Activity

        Hide
        aditi17 Aditi Patidar added a comment -

        Here are some findings on the issue:

        "updatePrice" method of "ShoppingCartItem" class run service "calculateProductPrice" which in turn executes the methods to match the price rule conditions on the cart item and if the conditions meet it executes corresponding actions mentioned in the price rule. But in the "updatePrice" it checks for the following condition before running "calculateProductPrice":

        	 public void updatePrice(LocalDispatcher dispatcher, ShoppingCart cart) throws CartItemModifyException {
        		// set basePrice using the calculateProductPrice service
        		if (_product != null && isModifiedPrice == false) {
        

        When we update the item added to cart and recalculate the order it executes method "modifyCart" of "ShoppingCartHelper" class where this line of code gets executed:

        if (item != null) {
            item.setBasePrice(quantity); // this is quantity because the parsed number variable is the same as quantity
            item.setDisplayPrice(quantity); // or the amount shown the cart items page won't be right
            item.setIsModifiedPrice(true); // flag as a modified price
        }   
        

        Here "item.setIsModifiedPrice(true)" set the flag "isModifiedPrice" "true" and the condition mentioned in "updatePrice" become false and the "calculateProductPrice" not gets executed. When I comment out the line

        	//item.setIsModifiedPrice(true);
        

        It works as expected and price rule gets apply. I am not sure what the purpose of this line of code "item.setIsModifiedPrice(true)" inside "modifyCart" because it contradict the condition written in "updatePrice".

        Show
        aditi17 Aditi Patidar added a comment - Here are some findings on the issue: "updatePrice" method of "ShoppingCartItem" class run service "calculateProductPrice" which in turn executes the methods to match the price rule conditions on the cart item and if the conditions meet it executes corresponding actions mentioned in the price rule. But in the "updatePrice" it checks for the following condition before running "calculateProductPrice": public void updatePrice(LocalDispatcher dispatcher, ShoppingCart cart) throws CartItemModifyException { // set basePrice using the calculateProductPrice service if (_product != null && isModifiedPrice == false ) { When we update the item added to cart and recalculate the order it executes method "modifyCart" of "ShoppingCartHelper" class where this line of code gets executed: if (item != null ) { item.setBasePrice(quantity); // this is quantity because the parsed number variable is the same as quantity item.setDisplayPrice(quantity); // or the amount shown the cart items page won't be right item.setIsModifiedPrice( true ); // flag as a modified price } Here "item.setIsModifiedPrice(true)" set the flag "isModifiedPrice" "true" and the condition mentioned in "updatePrice" become false and the "calculateProductPrice" not gets executed. When I comment out the line //item.setIsModifiedPrice( true ); It works as expected and price rule gets apply. I am not sure what the purpose of this line of code "item.setIsModifiedPrice(true)" inside "modifyCart" because it contradict the condition written in "updatePrice".
        Hide
        paul_foxworthy Paul Foxworthy added a comment -

        Hi Aditi,

        Good work, I think you've found a bug.

        Compare the code in ShoppingCartServices with the updateApprovedOrderItems method in OrderServices:

        https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java?r=1768192#to3712

        in particular, lines 3712 and 3740.

        If I understand the code correctly, isModified should say there has been human intervention to set a one-off price for this order that is different to the standard rules. Adjusting a quantity should not change the value of isModified.

        Can you create a patch for your change?

        Thanks

        Paul

        Show
        paul_foxworthy Paul Foxworthy added a comment - Hi Aditi, Good work, I think you've found a bug. Compare the code in ShoppingCartServices with the updateApprovedOrderItems method in OrderServices: https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java?r=1768192#to3712 in particular, lines 3712 and 3740. If I understand the code correctly, isModified should say there has been human intervention to set a one-off price for this order that is different to the standard rules. Adjusting a quantity should not change the value of isModified. Can you create a patch for your change? Thanks Paul
        Hide
        pandeypranay Pranay Pandey added a comment -

        Hi Aditi,

        Are you providing a patch for this change?

        Show
        pandeypranay Pranay Pandey added a comment - Hi Aditi, Are you providing a patch for this change?
        Hide
        aditi17 Aditi Patidar added a comment -

        Thanks Paul for the feedback. Incorporated the feedback in the attached patch.

        Show
        aditi17 Aditi Patidar added a comment - Thanks Paul for the feedback. Incorporated the feedback in the attached patch.
        Hide
        pandeypranay Pranay Pandey added a comment -

        Committed to trunk r1801269, R16.11 1801270.

        Thanks Aditi Patidar for reporting the issue and providing the patch. Thanks Paul Foxworthy for reviewing the issue and providing the research details.

        Show
        pandeypranay Pranay Pandey added a comment - Committed to trunk r1801269, R16.11 1801270. Thanks Aditi Patidar for reporting the issue and providing the patch. Thanks Paul Foxworthy for reviewing the issue and providing the research details.

          People

          • Assignee:
            pandeypranay Pranay Pandey
            Reporter:
            aditi17 Aditi Patidar
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development