VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: razor7 on April 30, 2021, 19:50:18 PM

Title: Improvement: Set free shipping by calculating cart total after applied coupon
Post by: razor7 on April 30, 2021, 19:50:18 PM
Hi! As a client asked me to have free shipping for a certain value, we discover that free shipping calculation doesn't take into account if a cart coupon is applied, so for instance, if I set free shipping to $100 and the cart sales price is $120 I get free shipping, but if I apply a coupon lets say -$30, cart sales price is $90 and I still get free shipping, which in my client point of view, is too much discount.

To get that calculation done, I have modified my custom shipping plugin, and the weight_countries plugin this way (if there's a better way, feel free to reply)

Change function getCosts from this

...
...
function getCosts (VirtueMartCart $cart, $method, $cart_prices) {
            if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment)
...
...


To this

...
...
function getCosts (VirtueMartCart $cart, $method, $cart_prices) {
            if ($method->free_shipment && $cart_prices['salesPrice'] + $cart_prices['salesPriceCoupon'] >= $method->free_shipment) {
...
...
Title: Re: Improvement: Set free shipping by calculating cart total after applied coupon
Post by: pinochico on May 01, 2021, 10:04:08 AM
yep,

we hack core code for shipping more times:
- for packaging weight
- for stock info in absolute value
...

Maybe will be great add these calculation inside core, but if not we have to hack every time :)
Title: Re: Improvement: Set free shipping by calculating cart total after applied coupon
Post by: AH on May 02, 2021, 09:51:42 AM
This is very typical of one clients use of coupons vs another

Please note: I am not saying that your particular case is wrong - of course it is not for your client.

But:
Imagine another customer who uses their coupons as a means of offering a credit note:

In this instance it would be wrong not to offer free shipping when this coupon was applied

So the core would need more that a single line adjustment.

Coupons would need to be classified as considered for free shipping
And the shipment plugins would need to be able to handle such configurations


Title: Re: Improvement: Set free shipping by calculating cart total after applied coupon
Post by: pinochico on May 02, 2021, 10:59:41 AM
QuoteCoupons would need to be classified as considered for free shipping

yes, is this the right idea for feature request for VM DEV - creating coupon type as free shipping?

Maybe you can try awo coupon, if VM core you can't use for your idea.

Don't remember:
Virtuemart have very good basic code, but for every customers we have to change core code - every customers / every shop need little custom change.
And of course you can create your custom plugin or solutions, you don't have waiting for VM DEV (sometimes you can't waiting).

With this option you have to calclulate for every project :)
It is your project, not VM project :)