Coupon discount has taxes included


  • Default avatar
    nicolas4    
     10 years ago
    0

    Hello there !

    I have an old config : VM 1.1.9, Joomla 1.5.26, and the 2.3.1 pro AWO Coupons.

    Found a post that *seems* related to me, config is not the same : https://awodev.com/forum/awocoupon/help-section/coupon-discount-amount-incorrect

    Here my situation:

    I am using a parent coupon (2 coupons), one that gives 20% off and one that gives 100% on specific product. So with 2 products in cart :

    Product A = 4$ (20% off)
    Product B = 25$ (100% off)
    Total = 29$
    Discount = 0.80$ + 25$ = 25.80$
    Total = 3.20$

    Works great so far.

    We calculate tax based on shipping location. When the user choose a shipping method, a cost of 8$ is added tax and 10% is added for that location, so the cart SHOULD become :

    Total 3.20$
    Shipping 8.00$
    Tax = 10% of (3.2 + 8) = 1.12$
    Total = 12,32

    But AWO COUPON changes the discount to 25.80$ + 10% = 28.38$ and the cart is now :

    Total = 0,62$
    Shipping = 8.00
    Tax = 10% of (0.62$ + 8$) = 0.86$
    Total = 9.48$

    I am using "substract discount before tax" of course.

    What's your suggestion?

    Best !
  • Your avatar
    seyi    
     10 years ago
    0

    Hello,

    Ok, I was able to reproduce this, here is the fix.

    First make sure in Virtuemart configuratioh you have "ubtract payment discount before tax/shipping?" checked. And in AwoCoupon->configuration you have "calculate the discount before tax" set to yes.

    Need to make a modification. In the file
    www/administrator/components/com_awocoupon/helpers/estore/virtuemart1/couponhandler.php, around line 120 is this:

    <?php
            $_SESSION
    ['coupon_redeemed'] = true;
            
    $_SESSION['coupon_id'] = $session_array['coupon_id'];
            
    $_SESSION['coupon_code'] = $session_array['coupon_code'];
            
    //$_SESSION['coupon_discount'] = $this->is_discount_before_tax ? $product_discount_notax: $product_discount;
            
    $_SESSION['coupon_discount'] = $session_array['product_discount'] + $session_array['shipping_discount'] ;
            
    $_SESSION['coupon_type'] = 'gift'// always call cleanup function
    ?>


    Change it to this:

    <?php
            $coupon_discount_total 
    0;
            foreach(
    $session_array['processed_coupons'] as $coupon) {
                
    $coupon_discount_total += $coupon['is_discount_before_tax']==1
                        
    $coupon['product_discount_notax'] + $coupon['shipping_discount_notax']
                        : 
    $coupon['product_discount'] + $coupon['shipping_discount']
                ;
            }
            
            
    $_SESSION['coupon_redeemed'] = true;
            
    $_SESSION['coupon_id'] = $session_array['coupon_id'];
            
    $_SESSION['coupon_code'] = $session_array['coupon_code'];
            
    //$_SESSION['coupon_discount'] = $this->is_discount_before_tax ? $product_discount_notax: $product_discount;
            
    $_SESSION['coupon_discount'] = $coupon_discount_total ;
            
    $_SESSION['coupon_type'] = 'gift'// always call cleanup function
    ?>


    That should fix the issue
  • Default avatar
    nicolas4    
     10 years ago
    0

    Seyi,

    You're simply the best ! A big thanks for the best service on the Internet !
    Nicolas
  • Your avatar
    seyi    
     10 years ago
    0

    :) You are welcome.
  • Default avatar
    nicolas4    
     10 years ago
    0

    Seyi,

    Can you please give me a quick advise? Please look at these 2 pictures.

    1. Cart without shipping, with parent coupon applying "all that can be applied", description above. https://drive.google.com/file/d/0B3JHnWnMtsGaQ204b3dVZGFqbG8/edit?usp=sharing

    2. Cart with shipping, with parent coupon, taxes are calculated. https://drive.google.com/file/d/0B3JHnWnMtsGaYzFqNThfS1dyR00/edit?usp=sharing

    My question is : I am right to say that the problem here is VM and not AWO?

    I hear you : did you check "calculate discount before taxes"? Yes : https://drive.google.com/file/d/0B3JHnWnMtsGaVVFrNmd4cGNGVzg/edit?usp=sharing

    Thanks.
  • Your avatar
    seyi    
     10 years ago
    0

    Ok, looking at your configuration, you have 2 extra fields, TPSD and TVQ. I assume these are equivalent to Taxes (TPS) and TVQ in checkout. These are customized fields, so I cannot account for those.

    If you submit the order, do the totals change?


    I believe there is an error in
    www/administrator/components/com_virtuemart/html/ro_basket.php
    where the discount tax is not correctly accounted for

    Search for this:
    <?php
            
    if( PSHOP_COUPONS_ENABLE=='1' && @$_SESSION['coupon_redeemed']==true ) {
                
    $total -= $_SESSION['coupon_discount'];
    ?>


    Its is in 2 places, but you only care to modify the one inside
    <?php
        
    if ( PAYMENT_DISCOUNT_BEFORE == '1') {
    ?>


    You would then modify it to
    <?php
            
    if( PSHOP_COUPONS_ENABLE=='1' && @$_SESSION['coupon_redeemed']==true ) {
                
    $total -= $_SESSION['coupon_discount'];
                
    $total -= ($_SESSION['coupon_discount'] * $my_taxrate);
    ?>


  • Default avatar
    nicolas4    
     10 years ago
    0

    Thanks for your help and advices Seyi, most appreciated.
    Nicolas