Coupon still there when item deleted


  • Default avatar
    MAD King    
     13 years ago
    0

    Hello,

    I updated to the last free VM version. When I add a item in the cart, use a coupon and delete the item from the cart, the coupon is still there.
    If I add a new item to the cart I don't have to insert the code again. Shouldn't the code get deleted/removed too as long no item is in the cart?

    Thank you
  • Your avatar
    seyi    
     13 years ago
    0

    Good point. There are 2 reasons this does not work, at least from what I tested:
    1) Virtuemart does not call the coupon check for deleting the last item. It does call it if the item deleted is not the last item in the cart, but not if deleting the item will empty the cart.
    2) the coupon code does not check for an empty cart. That I can fix but its not so useful if it is never being called anyway

    So the best way is a direct hack into Virtuemart if you really want
    in www/administrator/components/com_virtuemart/classes/ps_cart.php, inside function delete, right after this line:
    <?php
    ps_cart
    ::saveCart();
    ?>


    you could add this
    <?php
    if(empty($_SESSION['cart']['idx'])) {
        
    // initialize coupon
        
    unset(    $_SESSION['coupon_id'],
                
    $_SESSION['coupon_discount'],
                
    $_SESSION['coupon_redeemed'],
                
    $_SESSION['coupon_code'],
                
    $_SESSION['coupon_type']
            );
        return;
    }
    ?>


    This should achieve the behavior you want.
  • Default avatar
    MAD King    
     13 years ago
    0

    Thank you very much
  • Default avatar
    chase1    
     12 years ago
    0

    i hate to bump this old thread but i am having the same problem in VM 1.1.9. this code you suggested doesn't seem to be right for me.

    i am not a php pro, so take that as it may haha

    you say after

    <?php
    ps_cart
    ::saveCart();
    ?>


    add the code in the second box but i dont see where I have a php start or end tag in the ps_cart.php file except in the very beginning and end.

    for me, around line 460 i have this

        $temp["idx"] = $j;
            $_SESSION['cart'] = $temp;
            ps_cart::saveCart();

            return $deleted;
        }
        
        /**
         * deletes a given product_id from the saved cart


    thank you in advance for any help.
    -Chase
  • Your avatar
    seyi    
     12 years ago
    0

    Hello Chase,

    Ignore the , You want to place that code right after ps_cart::saveCart(); So taking your code, it should look like this:

    <?php
        $temp
    ["idx"] = $j;
        
    $_SESSION['cart'] = $temp;
        
    ps_cart::saveCart();
        if(empty(
    $_SESSION['cart']['idx'])) {
            
    // initialize coupon
            
    unset(    $_SESSION['coupon_id'],
                
    $_SESSION['coupon_discount'],
                
    $_SESSION['coupon_redeemed'],
                
    $_SESSION['coupon_code'],
                
    $_SESSION['coupon_type']
            );
            return;
        }
        return 
    $deleted;
    }
    ?>