Minimum/maxmimum order amount for shipping not taking into account the coupon code


  • Default avatar
    david19    
     5 months ago  last edited 5 months ago
    0

    Hello!

    The problem is that when you have a shipping created via standart virtuemart weight_shipping plugin with for example minimum order amount 10$ and maximum order amount 20$ and if you get products in total 10$, apply coupon code with 50% discount - virtuemart is still calculating as the order amount was between 10$ and 20$, so it does not take the coupon code into account.

    I've found seyi's solution in this blog: link , but it does not work until i changed the "empty" to "!empty" in this row of code:

    if ( function_exists'AC' ) && empty($cart_prices['salesPriceCoupon'] ) ) {

    After changing empty to !empty - its calculcating correctly shipping ranges and coupon discount is taken into account. But when i press "Confirm order" button it show me and error: "COM_VIRTUEMART_CART_NO_SHIPPINGRATE": "No shipping rate could be selected, you may not have entered your address or the vendor/shipment does not support your location".

    I searched this error code and the only file its been using in is /components/com_onepage/overrides/cart_override.php, yes, i'm using One Page Checkout rupostel component too.

    Ill try to find the solution by myself, will be grateful for your help. Thanks!


  • Your avatar
    seyi    
     5 months ago
    0

    Hello,

    What versions of virtuemart and awocoupon are you using?

    If you temporarily disable onepage checkout, does it work?

  • Default avatar
    david19    
     5 months ago
    0

    Thank you for reply!

    After disabling OnePage Checkout it still cant confirm the order. It redirect me to "please choose shipping", then "please select payment type", then it redirect back to order confirmation and to selecting shipping -> payment and so on. Nevertheless, the calculations of shipping price are still correct after changing the code as u suggested (but with !empty instead of empty), even with OPC being disabled. So the main problem now is that virtuemart does not let to confirm the order with code changing in weight_countires plugin, something is wrong with it, i am trying to figure out how to solve the problem. I think giving customer discount and free shipping at the same time is a bit too much, so i need the coupon discount to be taken into account, while shipping price is calculated.

    My awocoupon version is 3.6.0.3 and virtuemart 3.0.6.4.

  • Your avatar
    seyi    
     5 months ago
    0

    In awocoupon > installation check, do you have everything installed?
  • Default avatar
    david19    
     5 months ago
    0

    You mean this plugins?

    Yes, they are all installed and active.

    System - AwoCoupon
    VMCoupon - AwoCoupon
    VMPayment - AwoCoupon
    VmShipment - Awocoupon Free Gift Certificates
    Needed in some cases File: www/administrator/components/com_virtuemart/helpers/calculationh.php
  • Your avatar
    seyi    
     4 months ago
    0

    Hello,

    Ok, just to make sure, since that shipping option cannot be selected, is there another shipping option within 0 and 10 that is selected after the coupon is used?

    Also, in that change you made to weight_countries.php file, change this line from
    <?php
    if ( function_exists'AC' ) && ! empty($cart_prices['salesPriceCoupon'] ) ) {
    ?>

    To this and see if it helps:
    <?php
    if ( function_exists'AC' ) ) {
    ?>

  • Default avatar
    david19    
     4 months ago  last edited 4 months ago
    0

    I have 5 shipping rules in virutemart:

    1) Inside city - maximum order sum 1399 - delivery price: 200

    2) Inside city - minimum order sum 1400 - delivery price: 0

    3) Outside city - maximum order sum 1399 - delivery price: 350

    4) Outside city - minimum order sum 1400 - delivery price: 200

    5) Pickup from point of delivery - no minimum no maximum order sum - delivery price: 0

    When i changed

    if ( function_exists'AC' ) && ! empty($cart_prices['salesPriceCoupon'] ) ) {

    to

    if ( function_exists'AC' ) ) {

    It seemed to work, orders are now confirming correctly, shipping is calculated with coupon codes taking into account, i was almost happy, but... :(

    Now there is a glitch / bug i dont now how it even makes sense. \

    When i clear browser cache, go to site, add goods worth 1400 - it shows me "Inside city 0" shipping method, everything is fine. Then i apply 5% coupon code that gives 70 amount of discount. Order sum becomes 1400-70=1330 - it shows me "Inside city 200", everything is fine. Now i remove coupon code from cart (it is removing with ajax, without reloading page, but even after reloading the page) - and it still shows me "Inside city 200" although order sum is back to 1400 and it must show "Inside city 0" again :( So without coupon code when i add more products so order sum becomes 1480 - it shows "Inside city 0".

    I mean now it is somehow "remembering" that coupon code discount and always taking it into account even if coupon code is already removed from cart, it "remembers" that coupon code gives 5% and is taking that into account while calculating shipping methods. In other words, it needs order sum be 1400 + 5% to let me free shipping Inside city, i dont know how is it even possible, it does not make sense :(

    Nevertheless, when i change code back to 

    if ( function_exists'AC' ) && ! empty($cart_prices['salesPriceCoupon'] ) ) {

     it is still calculating correctly, when order sum is 1400, i add 5% discount - it shows me inside city 200, when i remove coupon code - it shows me Inside city 0, so in this case it does not "remember" the applied coupon code, calculation is good, but as i said before, order just can not be confirmed with changing price shipping method. But, for example, if i choose "Pickup from point of delivery" that does not have minimum or maximum order sum - order confirm successfully, so the issue is with changing-price shipping methods.

  • Your avatar
    seyi    
     4 months ago
    0

    Seems like might be a caching issue. Try this again:
    if ( function_exists'AC' ) ) {

    And then in the same file find the line:
    <?php
                
    return $result[$hash];
    ?>

    And comment it out, so it does not cache the conditions
    <?php
                
    //return $result[$hash];
    ?>

  • Default avatar
    david19    
     4 months ago  last edited 4 months ago
    0

    Sorry for long reply!

    So i changed it back to

    if ( function_exists'AC' ) ) {

    and commented line that was above this

    return $result[$hash];

    Its still taking coupon into account when i remove it. I think the issue is that OnePageCheckout is calling its ajax function "Onepage.removeCoupon()" on remove coupon button and we cant expect how is it working 


    So i added print_r($cart_prices); in the section where $orderamount_cond, to see with what we are working. The array $cart_prices appeared in shops cart. There were many elements, like

    [basePrice] => 1400 [basePriceWithTax] => 0 [discountedPriceWithoutTax] => 1400 [salesPrice] => 1400 [taxAmount] => 0 

     and so on. I notices an interesting element of array:

    [billTotal] =>

    In this array element, order total after coupon was applied is stored. So i just changed all code back in weight_countries.php and just changed line

    $orderamount_cond = $this->testRange($cart_prices['salesPrice'],$method,'orderamount_start','orderamount_stop','order amount');

    to

    $orderamount_cond = $this->testRange($cart_prices['billTotal'],$method,'orderamount_start','orderamount_stop','order amount');

    And now it seems to work everything good! I add goods worth 1400 - inside city 0, add coupon that gives 5% discount - inside city 200. Remove coupon - inside city 0 is back, orders are confirming correctly!

    But now the question is, was that good solution or not? I tested adding 3 different products, worth 1400, then removing one of them, then adding coupon, then adding products and removing coupon, all tests passed succesfully, seems everything working correctly. But i dont know much about virtuemart storing its variables in cart array and, maybe billTotal cannot be used because an error will occur in future? What are the underlying potential problems using "billTotal" in orderamount testRange function instead of "salesPrice"?

  • Your avatar
    seyi    
     4 months ago
    0

    Hello,

    If that works then great.  I believe billTotal is not always set when that function is called using a normal virtuemart cart.  It might be the case that the one page checkout you are using is setting it before it is called so this would be a valid option if that is the case.
  • Default avatar
    david19    
     2 months ago
    0

    Update.

    Hello, so as you mentioned, billTotal is not always set when function is called. It cause problem that send to testRange function 0 amount. It shows correct shipping methods in the cart, but it fails confirming order with the same error, because you choose one shipping method, that returns FALSE for $orderamount_cond and checkout fail.

    Function checkConditions recieving var $cart_prices, and i believe somewhere in the code it is sending to that variable cart_prices with no billTotal formed.

    The same thing happen with your initial solution to the problem in the conition:

    if ( function_exists'AC' ) && ! empty($cart_prices['salesPriceCoupon'] ) ) {

    Same as with billTotal, salesPriceCoupon is not always set in this function, thats why in some cases the condition is not working and sending to testRange function wrong order total.

    I just removed // && ! empty($cart_prices['salesPriceCoupon'] ) // condition and leave only // if ( function_exists( 'AC' ) ) // and now it seems to work in all cases.

    I cant say this solution will work for everyone, im using OnePageCheckout component, Awocoupon component and maybe this is unique for me, nevertheless i just wanted to share it with people, maybe this will help them.