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

Free Ground Shipping Mod

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 09-15-2007, 11:40 AM
 
joltedpixel joltedpixel is offline
 

Member
  
Join Date: Sep 2005
Posts: 25
 

Default Free Ground Shipping Mod

Hi All,

I made some tweaks and got it so when modifying the product you select the option for free ground shipping under the free shipping drop down. This then will display a specific shipping charge/zone that you setup.

I have posted it on my blog and I will work on moving it into this forum once I have some more time (hopefully later today).

Let me know your thoughts.

http://joltedlabs.com/software/x-cart/free-ground-shipping-mod

I have not fully tested this yet so feedback is welcomed. At the same time make sure you test this on a dev site.
__________________
4.1.9
Reply With Quote
  #2  
Old 09-15-2007, 11:45 AM
 
joltedpixel joltedpixel is offline
 

Member
  
Join Date: Sep 2005
Posts: 25
 

Default Re: Free Ground Shipping Mod

Free Ground Shipping Mod

The purpose of this mod is to allow people to create a zone that offers free shipping but still keep the existing prices for other shipping options. Currently x-cart has a free shipping option but once selected it will change the price of all shipping methods to zero.




READ THIS:

* This is not the easiest mod to install and should be done by an intermediate - advanced user. I will do my best to make it as simple as possible.
* I have only tested this with X-Cart 4.1.8 M
* This is not fully tested so please test it in a dev site first. We are not responsible for any damages.




Some Pre-Reqs before getting started:
1) Create a shipping zone
2) Create a shipping charge for that particular zone (free one) our is called ⌠Free USPS/UPS Ground Shipping■ and is set to zero dollars for the US (lower 48 states) zone we created earlier.
3) X-Cart 4.1.8 (only one tested so far)
4) Get the shipping charge ID number this can be found by viewing the source on the shipping charges page. You should get a two digit number or three digit number that will be in the value of the radio button for that shipping charge. Mine was 167 and you can see that in the code later.
5) I have this installed http://forum.x-cart.com/showthread.php?t=8901 (use post 59) Not sure if needed or not. I have not tested without it installed. Please let me know when you test.


Step 1
Add this to cart.php

Code:
///////////////////////// ///////// ADDED ///////// ///////////////////////// //// JoltedPixel.com //// ///////////////////////// $free_ground_id = ▒167'; // <<<< SET THIS TO MATCH SHIPPING ZONE ID # FOR FREE SHIPPING /////// Assigns Smart Variables $free_ground = true; foreach ($cart[▓products▓] as $product) { // Runs through all products in Cart if ($product[▓free_shipping▓] != ▒G▓){ // Counts $free_ground = false; } } /////// If there is no free ground shipping it finds the correct radio button to check if ($free_ground == false){ foreach ($shipping as $s) { if ($previous == $free_ground_id){ $free_ground_id_next = $s["shippingid"]; } $previous = $s["shippingid"]; } } /////// Assigns Smart Variables $smarty->assign("free_ground", $free_ground); $smarty->assign("free_ground_id", $free_ground_id); $smarty->assign("free_ground_id_next", $free_ground_id_next); ///////////////////////////// //// END ADDED SECTION ////// /////////////////////////////

Should go around line 450 and right after this chunk of code:

Code:
} else { $cart["delivery"] = ""; $cart["shippingid"] = 0; }


Step 2
Replace these two lines in skin1/modules/Fast_Lane_Checkout/shipping_methods.tpl

Code:
<td width="5"><input type="radio" id="shippingid{$s.shippingid}" name="shippingid" value="{$s.shippingid}"{if $s.shippingid eq $cart.shippingid} checked="checked"{/if}{if $allow_cod} onclick="javascript: display_cod({if $s.is_cod eq ▒Y▓}true{else}false{/if});"{/if} /></td> <td><label for="shippingid{$s.shippingid}">{$s.shipping|trademark:$insert_trademark}{if $s.shipping_time ne ""} - {$s.shipping_time}{/if}{if $config.Appearance.display_shipping_cost eq "Y" and ($login ne "" or $config.General.apply_default_country eq "Y" or $cart.shipping_cost gt 0)} ({include file="currency.tpl" value=$s.rate}){/if}</label></td>

with
Code:
{* ADDED JoltedPixel.com *} {if $s.shippingid == $free_ground_id} {if $free_ground} <td width="5"><input type="radio" id="shippingid{$s.shippingid}" name="shippingid" value="{$s.shippingid}"{if $s.shippingid eq $cart.shippingid} checked="checked"{/if}{if $allow_cod} onclick="javascript: display_cod({if $s.is_cod eq ▒Y▓}true{else}false{/if});"{/if} /></td> <td style="color:#007700; font-weight: bold; text-size: 11px;"><label for="shippingid{$s.shippingid}">{$s.shipping|trademark:$insert_trademark}{if $s.shipping_time ne ""} - {$s.shipping_time}{/if}{if $config.Appearance.display_shipping_cost eq "Y" and ($login ne "" or $config.General.apply_default_country eq "Y" or $cart.shipping_cost gt 0)} ({include file="currency.tpl" value=$s.rate}){/if}</label></td> {/if} {else} <td width="5"><input type="radio" id="shippingid{$s.shippingid}" name="shippingid" value="{$s.shippingid}"{if $s.shippingid eq $free_ground_id_next} checked="checked"{/if}{if $allow_cod} onclick="javascript: display_cod({if $s.is_cod eq ▒Y▓}true{else}false{/if});"{/if} /></td> <td><label for="shippingid{$s.shippingid}">{$s.shipping|trademark:$insert_trademark}{if $s.shipping_time ne ""} - {$s.shipping_time}{/if}{if $config.Appearance.display_shipping_cost eq "Y" and ($login ne "" or $config.General.apply_default_country eq "Y" or $cart.shipping_cost gt 0)} ({include file="currency.tpl" value=$s.rate}){/if}</label></td> {/if} {* END JoltedPixel.com *}

Step 3
Add this line in skin1/main/product_details.tpl (Around line 300)

Code:
<option value=▓G'{if $product.free_shipping eq ▒G▓} selected="selected"{/if}>Free Ground Shipping</option>


The whole chunk should look like this:

Code:
<select name="free_shipping"> <option value=▓G'{if $product.free_shipping eq ▒G▓} selected="selected"{/if}>Free Ground Shipping</option> <option value=▓N'{if $product.free_shipping eq ▒N▓} selected="selected"{/if}>{$lng.lbl_no}</option> <option value=▓Y'{if $product.free_shipping eq ▒Y▓} selected="selected"{/if}>{$lng.lbl_yes}</option> </select>



Technical Notes:
1) In order for the free shipping to show in the shipping methods all products in the cart must be set to ⌠Free Ground Shipping■. The conditions of the shipping zone and charge field must also be met.
2) Currently if a customer adds any products that are not free ground shipping they will void any products that are free ground shipping. So if you have a large item that is free ground shipping and adds something small but not free ground shipping they will ground shipping on both.
__________________
4.1.9
Reply With Quote
  #3  
Old 10-04-2007, 10:55 PM
  jonc's Avatar 
jonc jonc is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 53
 

Default Re: Free Ground Shipping Mod

I think that this is exactly what I am looking for. any reason that you think that this would not work with Special Offers - Free Shipping?
__________________
jonc
X-Cart Gold 4.1.10 - http://www.hypnoskates.com
X-Cart Gold 4.1.10 - http://tryten.com/shop/
X-Cart Gold 4.1.10 - http://www.bluecurl.ca/shop/
Reply With Quote
  #4  
Old 10-05-2007, 07:58 AM
 
joltedpixel joltedpixel is offline
 

Member
  
Join Date: Sep 2005
Posts: 25
 

Default Re: Free Ground Shipping Mod

Hmmm I can't see it not working with special offers. I didn't touch anything specific to that. I would recommend just trying it out. It simply works off a zone shipping Id.

Give it a shot. Backup your files first and let me know how you make out.

Good luck.
__________________
4.1.9
Reply With Quote
  #5  
Old 10-05-2007, 02:45 PM
  jonc's Avatar 
jonc jonc is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 53
 

Default Re: Free Ground Shipping Mod

I installed, exactly as listed above (MAKE SURE YOU CHECK THE QUOTES WHEN COPYING OUT OF THIS FORUM!!!), and then changed the following code from 'Y' to 'G' in /modules/Special_Offers/func.php and it worked!!!!!
Code:
if ($bonus['free_shipping']) { $products[$pk]['free_shipping'] = 'G'; $products[$pk]['free_shipping_used'] = true; }

Thanks so much for this wonderful tidbit of code!!!
__________________
jonc
X-Cart Gold 4.1.10 - http://www.hypnoskates.com
X-Cart Gold 4.1.10 - http://tryten.com/shop/
X-Cart Gold 4.1.10 - http://www.bluecurl.ca/shop/
Reply With Quote
  #6  
Old 11-19-2007, 11:12 AM
 
hhiker hhiker is offline
 

eXpert
  
Join Date: May 2007
Posts: 231
 

Default Re: Free Ground Shipping Mod

So can I use this with calculated shipping and set all UPS ground for say orders over $100 to ship free but all other methods will still calculate? I would hate for a customer to select free overnight service!

Thanks!!!
__________________
-
-
Versions: 4.1.10 and 4.3.0 (see post for which cart)

"Until man duplicates a blade of grass, nature can laugh at his so-called scientific knowledge." - Thomas Edison

"Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it is the only thing that ever has." - Margaret Mead (1901-197 quoted in John M. RIchardson, ed. Making it Happen, 1982

"Water is the best of all things." - Pindar (c. 522 BC - c. 438 BC), Olympian Odes
Reply With Quote
  #7  
Old 11-20-2007, 08:17 AM
 
hhiker hhiker is offline
 

eXpert
  
Join Date: May 2007
Posts: 231
 

Default Re: Free Ground Shipping Mod

Well, step 2 of this does not work since we are using calculated shipping. You can not define shipping charges for zones if you use calculated shipping.

I am going to see what I can figure out for a work around to this... Don't count on anything though.
__________________
-
-
Versions: 4.1.10 and 4.3.0 (see post for which cart)

"Until man duplicates a blade of grass, nature can laugh at his so-called scientific knowledge." - Thomas Edison

"Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it is the only thing that ever has." - Margaret Mead (1901-197 quoted in John M. RIchardson, ed. Making it Happen, 1982

"Water is the best of all things." - Pindar (c. 522 BC - c. 438 BC), Olympian Odes
Reply With Quote
  #8  
Old 12-06-2007, 09:32 AM
 
pumpkins pumpkins is offline
 

Advanced Member
  
Join Date: Jul 2007
Posts: 56
 

Default Re: Free Ground Shipping Mod

I've implemented the mod, however, whenever a non-free ground item is in the shopping cart, I will get an error on top of the page at the "your cart" page. The error says:

Quote:
Warning: Invalid argument supplied for foreach() in /xxx/xxx/xxx/cart.php on line 491

Line 491 is a line in the mod:

Quote:
foreach ($shipping as $s) {

Everything still seems to work (maybe), but the error is really annoying.

Any suggestion?
__________________
X-Cart Gold Version 4.1.8
Reply With Quote
  #9  
Old 12-06-2007, 09:37 AM
 
pumpkins pumpkins is offline
 

Advanced Member
  
Join Date: Jul 2007
Posts: 56
 

Default Re: Free Ground Shipping Mod

I am using calculated shipping too, but you can still use this mod. Just go to "shipping methods" and add a new shipping method first.

In my case, I added one call "Free Ground (for specified items only)".

Then go to "shipping charges" and follow the rest of the steps described in the original post.
__________________
X-Cart Gold Version 4.1.8
Reply With Quote
  #10  
Old 07-25-2008, 11:01 AM
 
rtraction rtraction is offline
 

Newbie
  
Join Date: Mar 2008
Posts: 8
 

Default Re: Free Ground Shipping Mod

Tried the above solutions, but they didn't quite do it. We needed to use the Special Offers module to allow free ground shipping in a particular zone on purchases above a certain amount.

We added a function to /shipping/shipping.php

PHP Code:
//rtraction njs - calculate free shipping
function func_free_shipping()
{
    global 
$userinfo$cart$customer_available_offers$sql_tbl//rtraction njs - added for checking cart

//check offers
func_check_new_offers();

    
$free_shipping false;
    
$min_purch 0;
    
$zonenum 0;
    
$zonefield "";
    
$now time();    
    
$zonematch false;
    
$ship_bonus false;

    
$cart_subtotal $cart["subtotal"];
    
$zonestate $userinfo["s_country"] . "_" $userinfo["s_state"];

    foreach (
$customer_available_offers as $offer_num)
    {
        
$this_offer func_get_offer($offer_num);
        
$offer_cond func_offer_get_conditions($offer_num"");
        
$offer_bonus func_offer_get_bonuses($offer_num"");
        
        
//check to make sure offer is active
        
if ($now $this_offer["offer_start"] && $now $this_offer["offer_end"] && $this_offer["offer_avail"] == "Y")
        {
            foreach (
$offer_cond as $offer_item)
            {
                if (
$offer_item["condition_type"] == "T" && $offer_item["avail"] == "Y")
                {
                    
//free shipping discount
                    
$min_purch $offer_item["amount_min"];
                }
                elseif (
$offer_item["condition_type"] == "Z")
                {
                    
//rtraction njs - zone is assigned to special
                    
if ($offer_item["params"][0]["param_id"] != "")
                    {
                        
$zonenum $offer_item["params"][0]["param_id"];
                        
                        
$zonefield func_query_first_cell("SELECT field FROM $sql_tbl[zone_element] WHERE zoneid=$zonenum AND field='$zonestate'");
                        if (
$zonefield != "")
                        {
                            
$zonematch true;
                        }
                    }
                }
            }
            foreach (
$offer_bonus as $offer_item)
            {
                if (
$offer_item["bonus_type"] == "S" && $offer_item["avail"] == "Y")
                {
                    
//free shipping discount
                    
$ship_bonus true;
                }
            }
            
        }
    }
    
    if (
$customer_available_offers != null && $ship_bonus == true && $cart_subtotal $min_purch && ($zonematch == true || $zonenum == 0))
    {
        
$free_shipping true;
    }
    
    return 
$free_shipping;


Then in our shipping module, we need to call the function and evaluate it. This project is using FedEx, but the same logic would work for others.

/shipping/mod_FEDEX_direct.php:

After:

PHP Code:
if (!empty($carrier_codes) && is_array($carrier_codes)) { 

Add:

PHP Code:
$free_shipping func_free_shipping(); 

After:

PHP Code:
$estimated_rate func_array_path($parsed$type."/ENTRY/$k/ESTIMATEDCHARGES/DISCOUNTEDCHARGES/NETCHARGE/0/#"); 


Add:

PHP Code:
//rtraction njs - store handling in separate variable
$handling_rate func_array_path($parsed$type."/ENTRY/$k/ESTIMATEDCHARGES/VARIABLEHANDLING/VARIABLEHANDLINGCHARGE/0/#");
if (
$handling_rate 0)
{
   
$estimated_rate func_array_path($parsed$type."/ENTRY/$k/ESTIMATEDCHARGES/VARIABLEHANDLING/TOTALCUSTOMERCHARGE/0/#");
}
                            
//rtraction njs - free ground shipping on valid orders 
$current_service func_array_path($parsed$type."/ENTRY/$k/SERVICE/0/#");
if (
$current_service == "FEDEXGROUND" && $free_shipping == true)
{
   if (
$handling_rate 0)
   {
      
$estimated_rate $handling_rate;
   } else {
      
$estimated_rate 0;
   }


We found that X-Cart wasn't using the handling charge that FedEx was returning. This was added to the total shipping charge.
__________________
Xcart v4.1.9 [unix]
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:30 PM.

   

 
X-Cart forums © 2001-2020