Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

FREE SHIPPING mod based on order total.

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 08-25-2004, 03:33 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default FREE SHIPPING mod based on order total.

Here's a quick and easy mod to let you give free shipping based on an order subtotal. First you'll need to add a variable to the xcart_config table of your xcart database. Using something like PHPMyadmin, take one of the existing Shipping config fields and just duplicate it. Change the values to be:

name: free_shipping_threshold
comment: FREE SHIPPING THRESHOLD
Give free shipping on orders with subtotal greater than this value. Set to 0 to disable
value: 0
category: Shipping
orderby: 4
type: text
defvalue: 0

Save the new row to your database. That will give you a nice config option in your shipping admin menu, so you can easily change the order subtotal required to get free shipping discounts.

Now open your include/func.php file and modify your func_caluculate_single() function. Search for the code that handle the free shipping coupon...
Code:
if (!empty($coupon_type) and $coupon_type == "free_ship") { # # Apply discount coupon 'Free shipping' # if (($single_mode) or ($provider_for == $discount_coupon_data["provider"])) $coupon_discount = $shipping_cost; $shipping_cost = 0; }

and add this bit of code directly below that code
Code:
//added by brett to offer free shipping if the free shipping threshold has been met if ($config["Shipping"]["free_shipping_threshold"] > 0 && $subtotal >= $config["Shipping"]["free_shipping_threshold"]){ //$coupon_discount = $shipping_cost; (commented out..see last post for explanation) $shipping_cost = 0; }

Now to use this mod, just log in as an admin and open your general settings page and select "shipping options" from the pulldown menu. Then find the new value you set up for the free_shipping_threshold and enter a value greater than 0 to activate the module. This will give free shipping for orders that have subtotals greater than the threshold you set. It also sets the customer's discount equal to whatever your shipping cost would have been and displays it the same way a free shipping coupon would be displayed. This has the added benefit that it should save the discount value in your store's order stats, just like all the other discounts (although no coupon code will ever be set). This code is only tested on v3.5.7, but should work with most of the 3.5.x branch. I have no idea what the 4.0 branch looks like, so I can't help anyone with that version yet. Also, i just realized that this code will interfere if a user tries to use a discount coupon. A fix for that would probably be to just change the above code from
Code:
//disregard this part of the code, just comment out these lines //$coupon_discount = $shipping_cost;
to
Code:
//disregard this part of the post...just comment out the $coupon_discount line //$coupon_discount += $shipping_cost;

Since coupons have theoretically been applied already, this will just add the shipping charge to whatever the existing discount value is.

ENJOY!

UPDATE: I have modified the code above by commenting out the $coupon_discount lines because it interfered with the normal coupon discount display in order receipts. Otherwise, the code is fine.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #2  
Old 08-25-2004, 04:30 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default An even better version

Okay, if you want this free shipping to work only with the shipping method you specify, here's what to do. Follow the previous post instructions for editing your database. Then add another new field to the database the same way, but this time call it "free_shipping_allowed_method" and enter in the same values, but give it an appropriate description. Then use the following code in your func_caluculate_single() function instead of adding the code snippet in my last post:
Code:
//added by brett to offer free shipping if the free shipping threshold has been met if ($config["Shipping"]["free_shipping_threshold"] > 0 && $subtotal >= $config["Shipping"]["free_shipping_threshold"] && $config['Shipping']['free_shipping_allowed_method'] == $shipping_id){ //$coupon_discount += $shipping_cost; $shipping_cost = 0; }
This will work just like my previous post, except now you can specify the shippingid of whichever shipping method you want this to work with. You can only specify a single shipping method if you choose to do it this way, but I figure most people will only want to offer UPS Ground for free anyway. If you wanted to have it apply to multiple shipping methods, it would be trivial to modify the code so that you could apply free shipping to a comma separated list of shipping ids instead of just a single shipping id. To find the shippingid of a specific shipping method, just look in your xcart_shipping table of your xcart database. Find the shipping ID of your preferred free shipping method and enter it in the "general options--->shipping options" admin page along with your free shipping threshold.

UPDATE: I have modified the code above by commenting out the $coupon_discount lines because it interfered with the normal coupon discount display in order receipts. Otherwise, the code is fine.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #3  
Old 08-25-2004, 04:56 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default another fix

I'm adding some more fixes as I get a better idea of how the coupon code works. It seems that after you make the above modifications, you cannot enter a coupon code once the free shipping discount has kicked in. To remedy that, I had to modify the skindir/customer/main/cart.tpl file. The very last part of the template file is the only part we need to change. So change this:
Code:
{if $cart.coupon_discount == 0 && $products != ""} {if $active_modules.Discount_Coupons ne ""} {include file="modules/Discount_Coupons/add_coupon.tpl} {/if} {/if}
To this:
Code:
{*if $cart.coupon_discount == 0 && $products != ""*} {if $active_modules.Discount_Coupons ne ""} {include file="modules/Discount_Coupons/add_coupon.tpl} {/if} {*/if*}

I just commented out the IF statement that encloses the coupon entry form. That keep the coupon entry form from being hidden once there is already a discount being used (which happens when the free shipping discount is automatically applied). I'm not sure why the templates were designed to hide the coupon form in the first place. If you enter multiple discount coupons, it only figures in the last one entered, so there doesn't seem to be any danger of customers entering the same code multiple times and getting additional discounts. The only problem I see remaining is that if you use an actual "free shipping" coupon type, it will kill the automatic free shipping discount and hides the discount display in your cart total, but I guess that's by design. It would be nicer if free shipping coupons displayed the free shipping as a discount the same way the other coupons do. Maybe I'll fix that in a later post.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #4  
Old 08-26-2004, 01:31 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default Final fix for this mod...

After some testing, I've determined that it's not a good idea to add the free shipping cost to the discounts because it screws up the order receipts and makes it look like the customer is being overcharged because it shows up as a discount in the receipt, but the order total doesn't reflect the discount because we're simply not charging shipping, so nothing needs to be subtracted when it isn't added in the first place. That sounds confusing, so I've modified my post above and commented out the addition of the shipping charges to the discounts, so free shipping will no longer show as a discount. Aside from that it seems to work great for me.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #5  
Old 08-27-2004, 09:29 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Great mod. For what version please?
Reply With Quote
  #6  
Old 08-28-2004, 10:21 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default Version info

This mod is working on X-Cart Pro 3.5.7, but would probably work for most of the 3.5.x branch. Not sure about earlier versions though.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #7  
Old 09-02-2004, 06:24 PM
 
nbsp nbsp is offline
 

Member
  
Join Date: Aug 2004
Posts: 12
 

Default

Does anyone know if this "free shipping mod based on order total" mod will work with X-Cart version 4.0.3?
Reply With Quote
  #8  
Old 09-03-2004, 10:03 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default

I don't think it will work exactly as posted, but if you can find the right functions in the new version, you could probably apply this mod pretty easily with minor tweaking. Since I haven't looked at the 4.x code yet, I couldn't tell you where to look.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #9  
Old 10-06-2004, 04:10 PM
 
jcaisse jcaisse is offline
 

Member
  
Join Date: Feb 2004
Posts: 21
 

Default you are a genious

Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you... Thank you...
__________________
Long time fan, not running any sites at the moment...
Reply With Quote
  #10  
Old 11-02-2004, 01:21 AM
 
plh plh is offline
 

Senior Member
  
Join Date: May 2004
Posts: 102
 

Default

Seems to have problem working in 3.4.14. Anyone with success for this mod under 3.4.xx ?

Seems to be conflicting with real-time UPS rates.

Philippe
__________________
X-Cart 4.4.3
- Happily EWD Hosted -
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:03 PM.

   

 
X-Cart forums © 2001-2020