OFBiz
  1. OFBiz
  2. OFBIZ-1560

Promotion rule for quantity discount not working

    Details

    • Type: Bug Bug
    • Status: Patch Available
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: SVN 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

        Activity

        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).
        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.
        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...
        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
        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 ?
        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.
        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

          People

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

            Dates

            • Created:
              Updated:

              Development