Buy X Get Y - Maximum Discount Qty Issue


  • Default avatar
    jordan    
     11 years ago
    0

    I have a Buy X Get Y coupon set up and it works, but it seems to do some weird stuff when using a Maximum Discount Qty.

    Coupon Set Up:
    Buy 2 of a product and get 1 free of the same product.
    Maximum Discount Qty = 3


    Here's how the coupon behaves in different scenarios:

    Example 1: Add product to cart with quantity of 2. Coupon updates qty to 3 and gives a discount for 1 of the products.

    Example 2: Add product to cart with quantity of 4. Coupon updates qty to 6 and gives a discount for 2 of the products.

    Example 3: Add product to cart with quantity of 6. Coupon updates qty to 9 and gives a discount for 3 of the products.

    Example 4: Add product to cart with quantity of 7. Coupon updates qty to 9 and gives a discount for 3 of the products.

    Example 5: Add product to cart with quantity of 8. Coupon doesn't change the quantity and gives a discount for ONLY 2 of the products when it should be giving a discount for 3 of the products.

    Example 6: Add product to cart with quantity of 9. Coupon doesn't change the quantity and gives a discount for 3 of the products.

    Example 7: Add product to cart with ANY quantity above 9. Coupon doesn't change the quantity and gives a discount for 3 of the products.

    The real problem is Example 5. Can this be fixed?

    Also, it seems more logical to me for the coupon to always add 3 more to the quantity if the customer has entered a quantity of 6 or more. For example, if the customer adds a product with a quantity of 10 the coupon would update the quantity to 13 and give a discount for 3 of the products. Is this doable?

    I'm using AwoCoupon Pro 1.5.2 and Virtuemart 1.1.5

    Thanks!
  • Your avatar
    seyi    
     11 years ago
    0

    Hello,

    In www/administrator/components/com_awocoupon/helpers/vm_coupon.php, around line 1988 change
    <?php
        
    if(!empty($coupon_row->params->max_discount_qty) && $used_max_discount_qty>=$coupon_row->params->max_discount_qty) break 2;
    ?>

    to
    <?php
        
    if(!empty($coupon_row->params->max_discount_qty) && $used_max_discount_qty>=$coupon_row->params->max_discount_qty) break;
    ?>


    Please be aware this logic has changed in AwoCoupon 2. In 2, it assumes free products have been added to the cart already. Using your example:

    Add 2: coupon updates 3
    Add 3, no updates
    Add 4, no updates. It is seen as 2+1 within the cart, and only 1 buy x product
    Add 5, coupon adds 1. It is seen as 2+1 in the cart, and 2 buy x products, so the get y product is added
    Add 6, no updates
    and the cycle goes on

    For your suggestion, I dont think so as it would get into an infinite loop where it adds 3 products to the cart every time the coupon function is called.


  • Default avatar
    jordan    
     11 years ago
    0

    Thanks for the help. I made the suggested changes and that fixed the issue.

    I'm now running into another issue.

    Let's say I have a coupon set up as buy 3 get 1 free.

    I add 3 of that product to the shopping cart. Then use the coupon. It updates the cart to 4 of that product and gives a discount for 1 of them. I then empty the cart. I add 3 of that product again and the cart is updated to 7 of that product with a discount for 1 of them.

    What's going on here?

    Thanks!

  • Your avatar
    seyi    
     11 years ago
    0

    Hello,

    Found a fix:
    in the same file vm_coupon, around line 2071 is this:

    <?php
            
    if($is_update) {
                
    $d = array(
                        
    'quantity'=>$qty,
                        
    'product_id'=>$product_id,
                        
    'prod_id'=>$product_id,
                        
    'description'=>$description
                );
                
    $ok $ps_cart->update($d);
            }
    ?>


    Update it to this:
    <?php
            
    if($is_update) {
                global 
    $func;
                
    $func 'cartupdate';
                
    $d = array(
                        
    'quantity'=>$qty,
                        
    'product_id'=>$product_id,
                        
    'prod_id'=>$product_id,
                        
    'description'=>$description
                );
                
    $ok $ps_cart->update($d);
            }
    ?>
  • Default avatar
    jordan    
     11 years ago
    0

    When I make that change I get the following error when I try to use the coupon:

    Parse error: syntax error, unexpected T_CLASS, expecting T_FUNCTION in /home3/shatter/public_html/administrator/components/com_awocoupon/helpers/vm_coupon.php on line 4219

    In my vm_coupon.php file line 4219 is:

    class ps_coupon_remove {
  • Your avatar
    seyi    
     11 years ago
    0

    Hello,

    I have fixed the problem in the orignal post. You just need to add a closed bracket "}" right after this
    <?php
    $ok 
    $ps_cart->update($d);
    ?>