Improvement: Set free shipping by calculating cart total after applied coupon

Started by razor7, April 30, 2021, 19:50:18 PM

Previous topic - Next topic

razor7

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) {
...
...
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

pinochico

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 :)
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

AH

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


Regards
A

Joomla 3.10.11
php 8.0

pinochico

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 :)
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products