Coupon not calculating properly


  • Your avatar
    seyi    
     6 years ago
    0

    Hi All,

    When I purchase on my website without any coupon it works and calculates perfectly, but when I use a coupon it goes wrong... very wrong.

    I have a simple 10% off coupon (as per screen1.jpg) and my configuration as per screen2.jpg.

    At checkout a product inc tax costs €3.99 (tax 0.69 @21%) - perfect as per Grab-1.jpg

    Enter Code and hit submit and what should be a reduction of 0.40 (10%) to €3.59 turns to €3.51 ? - (see grab-3.jpg)

    Flat rate shipping of €1.40 is added and when I get to the last checkout screen it's correct - see grab-5.jpg

    When it goes to paypal it's the wrong total again - see grab-6.jpg

    Help...

    images at http://www.3rdcastle.com/awocoupon.zip

    Any help appreciated..

  • Your avatar
    seyi    
     6 years ago
    0

    please view this blog post:
    http://awodev.com/blog/virtuemart-coupon-error-discount-before-tax
  • Default avatar
    jacqueline6    
     6 years ago
    0

    Hi,

    Thnk you for your quick answer. Just as I hit send I saw your blog.

    Thanks again
  • Default avatar
    john71    
     6 years ago
    0

    When I say no to discount before tax/shipping in VM1.1.5 there is the correct discount but it calculates the tax wrong?

    When I say yes to discount before tax/shipping in VM1.1.5 there is no discount at all when using a coupon...?

    Anyone see this before?

    Kind regards, John
  • Your avatar
    seyi    
     6 years ago
    0

    I have not seen that exact scenerio. Have you been manually editing some files to try to fix this? If so, it might be worth it to reload the original file. For vm1.1.5, these are the findings on this bug. Its a little different than 1.1.4 because they Virtuemart, but failed:
    http://awodev.com/forum/awocoupon/help-section/coupon-does-not-work-correclty
  • Default avatar
    john71    
     6 years ago
    0

    Hello Seyi,

    1. We use iDEAL payment method in The Netherlands, maybe this has some influence. You say: reload the original file.... which file name? Then I can check any differences.

    2. When I say no to discount before tax/shipping in VM1.1.5 there is the correct discount but it calculates the tax wrong? It calculates the tax over the subtotal instead of total (- discount)?

    Thanx, John
  • Your avatar
    seyi    
     6 years ago
    0

    the file that is likely causing incorrect calculations in your basket is
    www/administrator/components/com_virtuemart/html/basket.php

    I would start by getting a fresh copy of that file and work from there. I do not think you will see anyt tax problems for after that for disable discount before tax/shipping.

    If you do reload the file, be sure to go to Awocoupon pro dashboard->installation check and reinstall the codes.
  • Your avatar
    seyi    
     6 years ago
    0

    I just wrote a blog on this problem, the tax showing incorrectly after entering a coupon until you go to checkout
    http://awodev.com/blog/virtuemart-coupon-tax-error-initial-basket
  • Default avatar
    jacqueline6    
     6 years ago
    0

    My current paypal php code implements your fix code works but does not populate paypal with any details:

    ---------------------------------------------------------------------------------------------------------------------------------------------------
    <?php
    $db1 
    = new ps_DB();
    $q "SELECT country_2_code FROM #__vm_country WHERE country_3_code='".$user->country."' ORDER BY country_2_code ASC";
    $db1->query($q);

    $url "https://www.paypal.com/cgi-bin/webscr";
    $tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
    $discount_total $db->f("coupon_discount") + $db->f("order_discount");

    $post_variables = Array(
    "cmd" => "_ext-enter",
    "redirect_cmd" => "_xclick",
    "upload" => "1",
    "business" => PAYPAL_EMAIL,
    "receiver_email" => PAYPAL_EMAIL,
    "item_name" => $VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').": "$db->f("order_id"),
    "order_id" => $db->f("order_id"),
    "invoice" => $db->f("order_number"),
    //"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
    "amount" => round$db->f("order_total")-$db->f("order_shipping"), 2),
    "shipping" => sprintf("%.2f"$db->f("order_shipping")),
    "currency_code" => $_SESSION['vendor_currency'],

    "address_override" => "1",
    "first_name" => $dbbt->f('first_name'),
    "last_name" => $dbbt->f('last_name'),
    "address1" => $dbbt->f('address_1'),
    "address2" => $dbbt->f('address_2'),
    "zip" => $dbbt->f('zip'),
    "city" => $dbbt->f('city'),
    "state" => $dbbt->f('state'),
    "country" => $db1->f('country_2_code'),
    "email" => $dbbt->f('user_email'),
    "night_phone_b" => $dbbt->f('phone_1'),
    "cpp_header_image" => $vendor_image_url,

    "return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
    "notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
    "cancel_return" => SECUREURL ."index.php",
    "undefined_quantity" => "0",

    "test_ipn" => PAYPAL_DEBUG,
    "pal" => "NRUBJXESJTY24",
    "no_shipping" => "1",
    "no_note" => "1"
    );
    if( 
    $page == "checkout.thankyou" ) {
    $query_string "?";
    foreach( 
    $post_variables as $name => $value ) {
    $query_string .= $name"=" urlencode($value) ."&";
    }
    vmRedirect$url $query_string );
    } else {
    echo 
    '';
    echo 
    '';

    foreach( 
    $post_variables as $name => $value ) {
    echo 
    '';
    }
    echo 
    '';

    }
    ?>

    ---------------------------------------------------------------------------------------------------------------------------------------------------

    My new paypal code that populates paypal with the details, implements your fix but still has the discount error

    ---------------------------------------------------------------------------------------------------------------------------------------------------
    <?php
     
    $url 
    "https://www.paypal.com/cgi-bin/webscr";
    $order_id $db->f("order_id");
    $tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
    $discount_total $db->f("coupon_discount") + $db->f("order_discount"); 
     
    // Query for Order Items
    $dboi = new ps_DB;
    $q_oi "SELECT * FROM #__vm_order_item ";
    $q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
    $dboi->query($q_oi);
    $row_num $dboi->num_rows();
     
    //Getting Cart Items
    $auth $_SESSION['auth'];
    $cart $_SESSION['cart'];
    $t_quantity 0;
    $disc_perItem 0;
    $i=1;
     
    // Query to get User Info
    $dbb = new ps_DB;
    $q "SELECT * FROM #__vm_user_info ";
    $q .= "WHERE user_id ='".$my->id."' ";
    $dbb->setQuery($q);
    $dbb->query();
     
    //logic for applying discounts to multiple items
    $discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");
     
    while(
    $dboi->next_record()) {
      
    $t_quantity $t_quantity intval($dboi->f("product_quantity"));
    }
    $dboi null;
    $dboi = new ps_DB;
    $dboi->query($q_oi);
    if(
    $t_quantity 0)
    {
      if(
    $discount_totalCP 0) {
        
    $disc_perItem round($discount_totalCP $t_quantity2);
      }
      else {
        
    $disc_perItem 0;
      }
    }
    else {
      
    $disc_perItem 0;
    }
     
    //query to optain product attributes
    while($dboi->next_record()) {
      
    $prod_attrib $dboi->f("product_attribute");
      
    $supp_var['item_name_' $i] = strip_tags($VM_LANG->_('PHPSHOP_ORDER_LIST_ID') . " " $db->f("order_id").": "$dboi->f("order_item_name"));
      if(
    $prod_attrib ''){
        
    $attributes_array explode('
    '
    ,$prod_attrib);
        
    $v 0;
        
    $z 1;
        foreach ( 
    $attributes_array as $attributes_value){
          
    $attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
     
          
    $supp_var['on' $z '_' $i] = $attrib_name;
     
          
    $attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
     
          
    $supp_var['os' $z '_' $i] = $attrib_sel;
     
          
    $v++;
     
          
    $z++;
     
          unset(
    $attributes_value);
     
        }
     
      }
     
     
     
      
    $supp_var['item_number_' $i] = $dboi->f("order_item_sku");
     
      
    $supp_var['quantity_' $i] = $dboi->f("product_quantity");
     
      
    $supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
     
      
    $i++;
     
    }
     
     
     
     
     
    //Query used to find whether to use Bill Address or Ship to address
     
    $dboui = new ps_DB;
     
    $q_oui "SELECT * FROM #__vm_order_user_info ";
     
    $q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
     
    $dboui->query($q_oui);
     
     
     
     
     
      
    $first_name $dboui->f("first_name");
     
      
    $last_name $dboui->f("last_name");
     
      
    $address1 $dboui->f("address_1");
     
      
    $address2 $dboui->f("address_2");
     
      
    $city $dboui->f("city");
     
      
    $state $dboui->f("state");
     
      
    $address_country $dboui->f("country_2_code");
     
      
    $zip $dboui->f("zip");
     
      
    $H_PhoneNumber $dboui->f("phone_1");
     
     
     
     
     
    // Builds array for the form
     
    $post_variables = Array(
     
    "charset" => "utf8",
     
    "cmd" => "_cart",
     
    "upload" => "1",
     
    "page_style" => "paypal",
     
    "business" => PAYPAL_EMAIL,
     
    "currency_code" => $_SESSION['vendor_currency'],
     
    //"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
    "amount" => round$db->f("order_total")-$db->f("order_shipping"), 2),

    "handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
     
    "tax" => $tax_total,
     
    "tax_cart" => $tax_total,
     
    "invoice" => $db->f("order_number"),
     
    "image_url" => $vendor_image_url,
     
    "return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
     
    "notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
     
    "cancel_return" => SECUREURL ."index.php",
     
    "no_shipping" => "1",
     
    "no_note" => "1",
     
    "email" => $dbb->f("user_email"),
     
    "address_override" => "1",//change this to 0 if you have - Paypal does not allow your country of residence to ship to the country you wish to - errors
     
    "first_name" => $first_name,
     
    "last_name" => $last_name,
     
    "address1" => $address1,
     
    "address2" => $address2,
     
    "city" => $city,
     
    "state" => $state,
     
    "country" => $address_country,
     
    "zip" => $zip,
     
    "night_phone_b" => $H_PhoneNumber
     
    );
     
    //add and send the new variables
     
    if( $page == "checkout.thankyou" ) {
     
      
    $query_string "?";
     
     
     
      foreach( 
    $post_variables as $name => $value ) {
     
        
    $query_string .= $name"=" urlencode($value) ."&";
     
      }
     
     
     
      if(
    is_array($supp_var) && count($supp_var)) {
     
        foreach(
    $supp_var as $name => $value) {
     
          
    $query_string .= $name"=" urlencode($value) ."&";
     
        }
     
      }
     
     
     
      
    vmRedirect$url $query_string );
     

     
    else {
     
      echo 
    '';
     
     
     
      foreach( 
    $post_variables as $name => $value ) {
     
        echo 
    '';
     
      }
     
     
     
      if(
    is_array($supp_var) && count($supp_var)) {
     
        foreach(
    $supp_var as $name => $value) {
     
          echo 
    '';
     
        }
     
      }
     
      echo 
    '';
     
    //Change the above image url for different languages and countries
     
      
    echo '';
     
    }
     
    ?>


    ---------------------------------------------------------------------------------------------------------------------------------------------------

    This is what the last page in virtuemart displays:

    subtotal 4.99
    discount -50
    --------
    4.49 (inc 21% tax of €0.78)

    ShippingShipping and handling €1.40
    Total €5.89 EUR

    And this is what displays in Paypal..

    Item total €3.62
    Tax €0.78
    Shipping and handling €1.40
    Total €5.80 EUR

    I would be grateful of any assistance
  • Your avatar
    seyi    
     6 years ago
    0

    I do not understand where the 3.62 item price comes from. Is there just one item in the cart? I see the discount is 50, so the orginal price of the item is 54.99?
  • Your avatar
    seyi    
     6 years ago
    0

    ok, your discount appears to be 0.5, which makes sense. I think the item total you are seeing is the product price (with no tax) - the discount (with tax).

    Original Product price no tax = 4.99/1.21 = 4.12
    Discount with tax = 0.50
    ===> which leads to 4.12 - 0.50 = 3.62

    So somehow, you will need to find the tax rate, and take out the tax from the discount. This can be hardcoded if you dont expect it to change i guess. So if hardcoded, this

    <?php
    $supp_var
    ['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2); 
    ?>


    should be
    <?php
    $supp_var
    ['amount_' $i] = round(($dboi->f("product_item_price") - ($disc_perItem/1.21)),2); 
    ?>



  • Default avatar
    jacqueline6    
     6 years ago
    0

    Works a charm - thank you so much