OFBiz
  1. OFBiz
  2. OFBIZ-1560

Promotion rule for quantity discount not working

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: Trunk
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Firefox 2.0, Ubuntu 7.10

      Description

      Promotion rule for quantity discount does not work properly. For example if the X product in shopping cart has Qty >= Y, apply Z% discount to all the quantities in the shopping cart.

      I have created the following action to achieve the above:
      X Product for Y% discount - Can get the discounted price but this promotion applies to every item i.e. it does not consider the minimum quantity limit.

      If I create the following condition:
      X quantity of Product - It does apply the minimum quantity condition but applies discount to the item above X.

      1. OFBIZ-1560.patch
        4 kB
        Jennifer Weston
      2. OFBIZ-1560.patch
        9 kB
        Jennifer Weston
      3. OFBIZ-1560.patch
        3 kB
        Daniel Riquelme

        Issue Links

          Activity

          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Patch Available Patch Available
          1458d 7h 7m 1 Jacques Le Roux 01/Jan/12 20:59
          Patch Available Patch Available In Progress In Progress
          1108d 21h 2m 1 Jacques Le Roux 14/Jan/15 18:02
          In Progress In Progress Closed Closed
          8d 2h 54m 1 Jacques Le Roux 22/Jan/15 20:56
          Jacques Le Roux made changes -
          Link This issue relates to OFBIZ-6032 [ OFBIZ-6032 ]
          Jacques Le Roux made changes -
          Status In Progress [ 3 ] Closed [ 6 ]
          Resolution Won't Fix [ 2 ]
          Hide
          Jacques Le Roux added a comment -

          Hi Daniel,

          I know you are possibly no longer interested in this, but this was a good question, so here is my answer: X means all possible products in the cart (with same id).

          For the remarks below I ordered 10 "WG-5569" products with your implementation and 11 with the current one.

          I have finally decided to not apply your patch. Because I found a regressive bug: if you use "Order Percent Discount" you get a lot of unrelated promotions. BTW same issue for "Order Percent Flat". This works well with the current implementation, where you have to take into account that only the "Is Greater Than" operator is always used, see my comment above on how to define the action rule.

          I will change the UI to explain what the current implentation really does: it always and only uses the "Is Greater Than" operator. WIth this information in the UI people should not be confused. Anyway with this operator you can easily do a "Is Greater Than or Equal to" operator by changing the "condition value". For instance if you want a break at 10 put 9 in the condition value, etc.

          I noted also that when using "Gift with purchase", it's weird in both cases: if you ask for 1 product you get 8 :/

          I will close this issue, if someone wants to improve to allow using the other operators then another issue should be created. But I believe it's usable as is because the other operators don't make much sense (if any) with this rule condition. IMO, Only the "Is Greater Than" and Is Greater Than or Equal to" operators make sense with "X Quantities of Product".

          Show
          Jacques Le Roux added a comment - Hi Daniel, I know you are possibly no longer interested in this, but this was a good question, so here is my answer: X means all possible products in the cart (with same id). For the remarks below I ordered 10 "WG-5569" products with your implementation and 11 with the current one. I have finally decided to not apply your patch. Because I found a regressive bug: if you use "Order Percent Discount" you get a lot of unrelated promotions. BTW same issue for "Order Percent Flat". This works well with the current implementation, where you have to take into account that only the "Is Greater Than" operator is always used, see my comment above on how to define the action rule. I will change the UI to explain what the current implentation really does: it always and only uses the "Is Greater Than" operator . WIth this information in the UI people should not be confused. Anyway with this operator you can easily do a "Is Greater Than or Equal to" operator by changing the "condition value". For instance if you want a break at 10 put 9 in the condition value, etc. I noted also that when using "Gift with purchase", it's weird in both cases: if you ask for 1 product you get 8 :/ I will close this issue, if someone wants to improve to allow using the other operators then another issue should be created. But I believe it's usable as is because the other operators don't make much sense (if any) with this rule condition. IMO, Only the "Is Greater Than" and Is Greater Than or Equal to" operators make sense with "X Quantities of Product".
          Jacques Le Roux made changes -
          Status Patch Available [ 10002 ] In Progress [ 3 ]
          Hide
          Daniel Riquelme added a comment -

          Thank you Jacques. I'm still curious about the correct interpretation of 'X Quantity for Y %'. Do you think the X means all possible products in the cart (with same id), or only the products that are left over after the condition is applied (benefactor items).

          Show
          Daniel Riquelme added a comment - Thank you Jacques. I'm still curious about the correct interpretation of 'X Quantity for Y %'. Do you think the X means all possible products in the cart (with same id), or only the products that are left over after the condition is applied (benefactor items).
          Daniel Riquelme made changes -
          Attachment OFBIZ-1560.patch [ 12535583 ]
          Hide
          Daniel Riquelme added a comment -

          Updated Patch to fix the user entered comparator not being considered by the system.

          Show
          Daniel Riquelme added a comment - Updated Patch to fix the user entered comparator not being considered by the system.
          Hide
          Jacques Le Roux added a comment -

          Thanks for your review and test Daniel,

          I will try to have a new look following yours soon...

          Show
          Jacques Le Roux added a comment - Thanks for your review and test Daniel, I will try to have a new look following yours soon...
          Hide
          Daniel Riquelme added a comment - - edited

          I revised this against revision 1357015 (last one to date) and the status is as follows,

          1) The error regarding the condition in which the system don´t use the user entered operator remains the same. The code reflects this clearly.

          2) The first patch in this post does fixes that specific error.

          3) When applying the condition "X Quantities Product" and action "X Quantity for Y %" the system do not apply the discount to all the items matching the condition. In fact what happens is that the items matching the condition, the qualifier items, are excluded from the action effect. The system will only apply the action to the number of items that are benefactors to the action, i.e. the X items that remain in the cart that match the condition when the qualifier items are removed.

          So, what I don't know and haven't found in the wiki or the mailing lists is what is the exact definition of "X Quantity for Y %", if the definition is apply a discount to all items in the cart matching the condition, then this issue is a bug and must be corrected.
          If the definition is apply the discount to at least X benefactor items then this is not a bug.
          If the latter is correct then there is no way to achieve the required promotion unless a custom service is used.

          Show
          Daniel Riquelme added a comment - - edited I revised this against revision 1357015 (last one to date) and the status is as follows, 1) The error regarding the condition in which the system don´t use the user entered operator remains the same. The code reflects this clearly. 2) The first patch in this post does fixes that specific error. 3) When applying the condition "X Quantities Product" and action "X Quantity for Y %" the system do not apply the discount to all the items matching the condition. In fact what happens is that the items matching the condition, the qualifier items, are excluded from the action effect. The system will only apply the action to the number of items that are benefactors to the action, i.e. the X items that remain in the cart that match the condition when the qualifier items are removed. So, what I don't know and haven't found in the wiki or the mailing lists is what is the exact definition of "X Quantity for Y %", if the definition is apply a discount to all items in the cart matching the condition, then this issue is a bug and must be corrected. If the definition is apply the discount to at least X benefactor items then this is not a bug. If the latter is correct then there is no way to achieve the required promotion unless a custom service is used.
          Jacques Le Roux made changes -
          Status Open [ 1 ] Patch Available [ 10002 ]
          Hide
          BJ Freeman added a comment -

          Ping

          Show
          BJ Freeman added a comment - Ping
          Hide
          Jacques Le Roux added a comment -

          ping...

          Show
          Jacques Le Roux added a comment - ping...
          Gavin made changes -
          Workflow jira [ 12420228 ] OFbiz Workflow [ 12506634 ]
          Hide
          Raj Saini added a comment -

          Hi Jacques,

          Sorry, I could not get the time so far. I will work on it during this week and update you.

          Thanks

          Show
          Raj Saini added a comment - Hi Jacques, Sorry, I could not get the time so far. I will work on it during this week and update you. Thanks
          Hide
          Jacques Le Roux added a comment -

          Hi Raj,

          Did you have a chance to look at Jennifer's patch ?

          Thanks

          Show
          Jacques Le Roux added a comment - Hi Raj, Did you have a chance to look at Jennifer's patch ? Thanks
          Jennifer Weston made changes -
          Attachment OFBIZ-1560.patch [ 12422695 ]
          Hide
          Jennifer Weston added a comment -

          The reason that I posted the patch was that I thought I had solved a similar problem. My scenario is a bit more complex, but there are similarties to Raj's problem. Unfortunately, the original patch will not address Raj's issue. A revised patch included does.

          The problem that got me started on this was that I need a quantity price breaks for an item. For example, we have a product that is regularly $99.00. If you put 5 to 9 of them in your cart, they should priced as $85.00 per item. If you put 10 or more in your cart, they should be $70.00 per item.

          After reading about promos and doing some debugging, I found that the quantity condition was always treated as a minimum. This works well for Raj's scenario, but not mine. It was also confusing as a user. I changed the code to respect the user defined comparator. In the process, I noticed that there is some interesting behavior regarding how conditions set candidate product quantities. This affects how the rules will be applied. The condition will set the minimum quantity to satisfy the condition as candidate. I wrongly thought that consuming all candidates in the condition would be sufficient to deal with the application of the rule actions.

          After doing some more debugging, I can now use X Quantity for Y Price which works a lot like X Quantity for Y %. The reason it was failing to apply to all items was the rule application will apply the action for quantity specified (1 if not filled in). Then it re-tests all of the rule condition(s). This means that once it has applied the action(s) beyond the number that will satisfy the condition, it stops.

          I've uploaded a new patch that will retry the rule actions until it stops changing the cart.

          Show
          Jennifer Weston added a comment - The reason that I posted the patch was that I thought I had solved a similar problem. My scenario is a bit more complex, but there are similarties to Raj's problem. Unfortunately, the original patch will not address Raj's issue. A revised patch included does. The problem that got me started on this was that I need a quantity price breaks for an item. For example, we have a product that is regularly $99.00. If you put 5 to 9 of them in your cart, they should priced as $85.00 per item. If you put 10 or more in your cart, they should be $70.00 per item. After reading about promos and doing some debugging, I found that the quantity condition was always treated as a minimum. This works well for Raj's scenario, but not mine. It was also confusing as a user. I changed the code to respect the user defined comparator. In the process, I noticed that there is some interesting behavior regarding how conditions set candidate product quantities. This affects how the rules will be applied. The condition will set the minimum quantity to satisfy the condition as candidate. I wrongly thought that consuming all candidates in the condition would be sufficient to deal with the application of the rule actions. After doing some more debugging, I can now use X Quantity for Y Price which works a lot like X Quantity for Y %. The reason it was failing to apply to all items was the rule application will apply the action for quantity specified (1 if not filled in). Then it re-tests all of the rule condition(s). This means that once it has applied the action(s) beyond the number that will satisfy the condition, it stops. I've uploaded a new patch that will retry the rule actions until it stops changing the cart.
          Hide
          Jacques Le Roux added a comment -

          Hi Raj,

          Yes please do and comment as I'm not sure that I did the same as you. Also could you test Jennifer patch ?

          Thanks

          Show
          Jacques Le Roux added a comment - Hi Raj, Yes please do and comment as I'm not sure that I did the same as you. Also could you test Jennifer patch ? Thanks
          Hide
          Raj Saini added a comment -

          Hi Jacques,

          I did not looked at the latest code as I had used some work around. I would be glad to test again if you want me to.

          Show
          Raj Saini added a comment - Hi Jacques, I did not looked at the latest code as I had used some work around. I would be glad to test again if you want me to.
          Hide
          Jacques Le Roux added a comment -

          Ha, also I noticed something that makes me wonder :

          WG-5569 - Tiny Chrome Widget : 14  48,00 $US      -10,00 $US      662,00 $US      
          Sous-total:                                                       662,00 $US      
          Ajustement - Promotion Détails:                                   -67,20 $US      
          Total du panier:                                                  594,80 $US
          

          The 10% off promo on all the order is still applied to 14*48 = 672, despite than the real order total is really 662 ! Is that normal ? Seems weird to me...

          Show
          Jacques Le Roux added a comment - Ha, also I noticed something that makes me wonder : WG-5569 - Tiny Chrome Widget : 14 48,00 $US -10,00 $US 662,00 $US Sous-total: 662,00 $US Ajustement - Promotion Détails: -67,20 $US Total du panier: 594,80 $US The 10% off promo on all the order is still applied to 14*48 = 672, despite than the real order total is really 662 ! Is that normal ? Seems weird to me...
          Hide
          Jacques Le Roux added a comment -

          Hi Raj, Jennifer,

          I had a look tonight and here are some remarks.

          I did not apply Jennifer's patch yet. What I did was setting a promotion as described Raj :

          I used as condition "X Quantities Product" Is Greater Than or Equal is <Qty = 10>
          and Conditions Products: include WG-5569 - Tiny Chrome Widget

          as action "X Product for Y Discount" <Amount = 10>
          and Actions Products: Tiny Chrome Widget [WG-5569] - Include

          And here are the results I got :
          The promo is not applied until I put more than 10 (despite Greater Than or Equal is <Qty = 10>), when I put at least 11 WG-5569, I get a US$ 10 promo. If you put one more product you still get only the US$ 10 promo, etc.

          I also tried to apply the same conditions with the actions
          as action "X Product for Y Discount" <qty = 10> <Amount = 10>
          and Actions Products: Tiny Chrome Widget [WG-5569] - Include

          It works as you get US$ 10 promo for each product you buy after the tenth. eleventh : US$ 10 promo, twelfth : US$ 20 promo, etc.

          Also Jennifer, was the change you did fixing the issue Raj reported or was it for another reason ?

          Show
          Jacques Le Roux added a comment - Hi Raj, Jennifer, I had a look tonight and here are some remarks. I did not apply Jennifer's patch yet. What I did was setting a promotion as described Raj : I used as condition "X Quantities Product" Is Greater Than or Equal is <Qty = 10> and Conditions Products: include WG-5569 - Tiny Chrome Widget as action "X Product for Y Discount" <Amount = 10> and Actions Products: Tiny Chrome Widget [WG-5569] - Include And here are the results I got : The promo is not applied until I put more than 10 (despite Greater Than or Equal is <Qty = 10>), when I put at least 11 WG-5569, I get a US$ 10 promo. If you put one more product you still get only the US$ 10 promo, etc. I also tried to apply the same conditions with the actions as action "X Product for Y Discount" <qty = 10> <Amount = 10> and Actions Products: Tiny Chrome Widget [WG-5569] - Include It works as you get US$ 10 promo for each product you buy after the tenth. eleventh : US$ 10 promo, twelfth : US$ 20 promo, etc. Also Jennifer, was the change you did fixing the issue Raj reported or was it for another reason ?
          Jennifer Weston made changes -
          Attachment OFBIZ-1560.patch [ 12421868 ]
          Hide
          Jennifer Weston added a comment -

          As of svn revision 824272, the quantity condition for promos are treated as a minimum requirement (i.e. greater than or equal to) instead of respecting the user-set comparator. The enclosed patch alters the logic to respect the user-set comparator for quantity.

          Show
          Jennifer Weston added a comment - As of svn revision 824272, the quantity condition for promos are treated as a minimum requirement (i.e. greater than or equal to) instead of respecting the user-set comparator. The enclosed patch alters the logic to respect the user-set comparator for quantity.
          Jacques Le Roux made changes -
          Assignee Jacques Le Roux [ jacques.le.roux ]
          Hide
          Raj Saini added a comment -

          Hi Jacques,

          It mean to apply the Z% discount to all the quantities of the X product.

          Let me explain a bit what I wanted to achieve. Let us say we want to offer a quantity discount if a customer buys minimum five number of product X. If customer buys just four numbers we don't want to give this discount. And the discount is Z% of the product price. This was not working when I tested it (almost one year back). The problem was the price % discount was applied irrespective of the number of items in the cart. For example if a customer buys just one number of the product X, Z% discount was offered.

          For condition I used "X Quantities Product" Is Greater Than or Equal is <Qty (e.g.10)>

          For Action I used "X Product for Y Discount" <Amount (e.g. 10)>

          Thanks

          Show
          Raj Saini added a comment - Hi Jacques, It mean to apply the Z% discount to all the quantities of the X product. Let me explain a bit what I wanted to achieve. Let us say we want to offer a quantity discount if a customer buys minimum five number of product X. If customer buys just four numbers we don't want to give this discount. And the discount is Z% of the product price. This was not working when I tested it (almost one year back). The problem was the price % discount was applied irrespective of the number of items in the cart. For example if a customer buys just one number of the product X, Z% discount was offered. For condition I used "X Quantities Product" Is Greater Than or Equal is <Qty (e.g.10)> For Action I used "X Product for Y Discount" <Amount (e.g. 10)> Thanks
          Hide
          Jacques Le Roux added a comment -

          Hi Raj,

          Your example is

          if the X product in shopping cart has Qty >= Y, apply Z% discount to all the quantities in the shopping cart.

          Does this really means
          "apply Z% discount to all the quantities in the shopping cart."
          or only
          "apply Z% discount to all the quantities of the product X" ?

          Which operator did you use in the condition ?

          For the action, why not using "Order percent discount" (if you really want to have "Z% discount to all the quantities in the shopping cart.". But I suppose you are looking for something else)

          In other words, can you elaborate a bit more

          • what you are looking for,
          • how did you try to achieve it
          • what did you expect as results
          • and what you really got

          Thanks

          Show
          Jacques Le Roux added a comment - Hi Raj, Your example is if the X product in shopping cart has Qty >= Y, apply Z% discount to all the quantities in the shopping cart. Does this really means "apply Z% discount to all the quantities in the shopping cart." or only "apply Z% discount to all the quantities of the product X" ? Which operator did you use in the condition ? For the action, why not using "Order percent discount" (if you really want to have "Z% discount to all the quantities in the shopping cart.". But I suppose you are looking for something else) In other words, can you elaborate a bit more what you are looking for, how did you try to achieve it what did you expect as results and what you really got Thanks
          Jacques Le Roux made changes -
          Field Original Value New Value
          Summary Promotion rule for quanity discount not working Promotion rule for quantity discount not working
          Component/s product [ 12311155 ]
          Raj Saini created issue -

            People

            • Assignee:
              Jacques Le Roux
              Reporter:
              Raj Saini
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development