VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: betterlead on November 21, 2015, 22:07:42 PM

Title: Free shipping limit, calculated after discount coupon is added
Post by: betterlead on November 21, 2015, 22:07:42 PM
Hi, I'm not sure if this matter has been discussed in this forum before, but anyway, I'll give it a go:


I have set the free shipping limit to a certain sum. Let's say it's 500 SEK.
I have a lot of campaigns running with different rebates.
Now,,, I'd like the free shipping limit to be calculated on the total after any discount coupon has been used by the shopper.

Example: Customer buys for a total of 501 SEK - this gives her or him free shipping. Then the coupon is added and let's assume the total is now 400,80 SEK after a 20% rebate. Still the buyer gets free shipping. To sum up, I don't want the rebate to affect other than the goods bought.
Title: Re: Free shipping limit, calculated efter discount coupon is added
Post by: GJC Web Design on November 21, 2015, 22:13:11 PM
So it would seem either the shipping isn't recalculated after applying the coupon or the shipping plug isn't using the discounted total..

what shipping method and coupon ext. do u use?
Title: Re: Free shipping limit, calculated efter discount coupon is added
Post by: betterlead on November 21, 2015, 22:24:27 PM
Standard built in VM coupon plugin, I recon. Shipment methods are four different but they are kind of standard... One, the main is a "Unity" shipment for all orders up to an amount of, actually 498 SEK. One is Collect at warehouse. One is free delivery in our city and the last one is one for international shipping with an extra 90 SEK. (Up to 1 kg.)

All four are: "By weight, ZIP and countries. weight_countries

Is that information enough, or am I not getting it?

Cheers & Thanks for helping.

Btw, big misstake, I forgot to mention the website's address,,, https://livingstudio.se


Title: Re: Free shipping limit, calculated efter discount coupon is added
Post by: GJC Web Design on November 21, 2015, 23:00:30 PM
OK .. so all standard...

if u switch on VM debug it will give a good amount of info on what the plugin is using for the free calc

its chk conditions uses the $cart_prices['salesPrice']...   

If i get time tomorrow will check if this is with/without coupon
Title: Re: Free shipping limit, calculated efter discount coupon is added
Post by: betterlead on November 21, 2015, 23:20:16 PM
Thanks GJC.
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: betterlead on November 23, 2015, 22:54:00 PM
Any ideas, yet?
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: Milbo on November 27, 2015, 14:26:05 PM
Can be done only with an extra option, I think.
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: hegbi on December 02, 2015, 11:05:33 AM
Hi betterlead
for VM2 you have a similar thread here, maybe it will help you...
http://forum.virtuemart.net/index.php?topic=108951.0 (http://forum.virtuemart.net/index.php?topic=108951.0)

and for me this worked (J2.5 / VM 2.6.18)
in /plugins/vmshipment/weight_countries/weight_countries.php
changed line
if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {

with

//if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {
if ($cart->couponCode) {
    $amount = $cart_prices['salesPriceWithDiscount'];
} else {
    $amount = $cart_prices['salesPrice'];
}

if ($method->free_shipment && $amount >= $method->free_shipment) {
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: betterlead on December 02, 2015, 15:28:25 PM
Thanks, I'll see if that might work in ver 3.
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: mark R on June 28, 2016, 18:06:34 PM
Did you manager to get this working in VM3?

I have entered the above code but this does not solve the issue, I am using Awocoupon if that makes a difference.

Any help would be much appreciated.

Manrk
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: betterlead on June 28, 2016, 18:39:20 PM
Hi mark R

Sorry, I think I gave this one up.
So, let's bump this thread! :)

Any ideas, anybody?
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: mark R on July 01, 2016, 10:43:08 AM
Not sure if this is right, as I am not a coder, but it appears to work.

Just needs some more testing, and a smarter eye then mine to have a quick look over it (as I may have missed something)

/plugins/vmshipment/weight_countries/weight_countries.php
        /**
         * @param VirtueMartCart $cart
         * @param                $method
         * @param                $cart_prices
         * @return int
         */
        function getCosts (VirtueMartCart $cart, $method, $cart_prices) {

                //if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {
        if ($cart->couponCode) {
                $amount = $cart_prices['salesPrice'] - $method->free_shipment;
                } else {
                $amount = $cart_prices['salesPrice'];
                        }
                if ($method->free_shipment && $amount >= $method->free_shipment) {
                        return 0.0;
                } else {
                        return $method->shipment_cost + $method->package_fee;
                }
        }


Any input / testing would be very appreciated.

Many thanks
Mark
Title: Re: Free shipping limit, calculated after discount coupon is added
Post by: mark R on July 29, 2016, 14:35:04 PM
Amended code appears to be working correctly, (shipping is calculated on total order and coupon value, if coupon is entered.)


       /**
         * @param VirtueMartCart $cart
         * @param                $method
         * @param                $cart_prices
         * @return int
         */
        function getCosts (VirtueMartCart $cart, $method, $cart_prices) {

                //if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {
        if ($cart->couponCode) {
                $amount = $cart_prices['salesPrice'] + $cart->pricesUnformatted['salesPriceCoupon'];
                } else {
                $amount = $cart_prices['salesPrice'];
                        }
                if ($method->free_shipment && $amount >= $method->free_shipment) {
                        return 0.0;
                } else {
                        return $method->shipment_cost + $method->package_fee;
                }
        }


I now have an issue that although the above works the ajax update when applying the coupon does not update the order details with the new shipping but it does update the shipping selection area? (I am using VP Onepage checkout).
If I click on the shipping method (not changing anything) it updates the order detail??

Any ideas?

Many thanks
Mark