X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Free Ground Shipping Mod (https://forum.x-cart.com/showthread.php?t=33947)

joltedpixel 09-15-2007 11:40 AM

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.

joltedpixel 09-15-2007 11:45 AM

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.

jonc 10-04-2007 10:55 PM

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?

joltedpixel 10-05-2007 07:58 AM

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.

jonc 10-05-2007 02:45 PM

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!!!

hhiker 11-19-2007 11:12 AM

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!!!

hhiker 11-20-2007 08:17 AM

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.

pumpkins 12-06-2007 09:32 AM

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?

pumpkins 12-06-2007 09:37 AM

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.

rtraction 07-25-2008 11:01 AM

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.

nacredata 12-03-2008 11:42 AM

Re: Free Ground Shipping Mod
 
The following pair of simple hacks seem to work for me (4.1.11)

in /modules/Special_Offers/func.php around line 1330:
Code:

    # Part 2: Apply bonuses
    #
    $discount = 0.00;
    $_SESSION['ND_freeshipping'] = NULL;

    # Apply discount bonus
    foreach ($products as $pk=>$product) {

        if (@$product["deleted"]) continue; # for Advanced_Order_Management module

        if (!empty($apply_bonus[$pk])) {
            $bonus = $apply_bonus[$pk];

            if ($bonus['discount'] > 0.00) {
                if ($config["Taxes"]["display_taxed_order_totals"] =="Y")
                    $products[$pk]['saved_original_price'] = $products[$pk]['taxed_price'];
                else
                    $products[$pk]['saved_original_price'] = $products[$pk]['price'];
                $products[$pk]['price'] -= $bonus['discount'];
                $products[$pk]['special_price_used'] = true;
            }

            if ($bonus['free_shipping']) {
// NacreData L.L.C. info@nacredata.com
// Need to offer free shipping only on UPS ground, not on all delivery methods
// so rather than just mark it all free here, rather set a flag which we can
// check later (see /shipping/mod_UPS.php around line 551)

//                $products[$pk]['free_shipping'] = 'Y';
//                $products[$pk]['free_shipping_used'] = true;
                $_SESSION['ND_freeshipping'] = true;
            }           
        }
    }



in /shipping/mod_UPS.php around line 550:

Code:

// NacreData L.L.C. info@nacredata.com
// Need to offer free shipping only on UPS ground, not on all delivery methods
// so rather than just mark it all free in /modules/Special_Offers/func.php
// (around line 1353), rather set a flag there which we can check here

// is ground shipping ALWAYS methodid 1??  Appears to come from the database
// table xcart_shipping

                    if( isset( $_SESSION['ND_freeshipping'] ) && $subcode == 1 ) { $data = '0.00'; }
                    $_rate_data = array(
                        "methodid"=>$subcode,
                        "rate"=>$data,
                        "currency"=>$mod_UPS_currency,
                        "orig_rate"=>$orig_rate,
                        "warning"=>$RatedShipmentWarning,
                        "service_code"=>$sv["service_code"]
                    );


Also note something we discovered: it seems all items need to have a weight assigned to them. Items without a weight may not trigger a shipping recalculation.

murlyn28 01-10-2009 05:52 PM

Re: Free Ground Shipping Mod
 
Quote:

Originally Posted by nacredata
The following pair of simple hacks seem to work for me (4.1.11)

in /modules/Special_Offers/func.php around line 1330:

Also note something we discovered: it seems all items need to have a weight assigned to them. Items without a weight may not trigger a shipping recalculation.



I can't seem to get any International orders to pass the UPS address verification using this mod.

steewu 07-10-2009 03:44 PM

Re: Free Ground Shipping Mod
 
Is there a new version for 4.2.2... I'm having problem set it up...

RPS 11-03-2009 08:58 AM

Re: Free Ground Shipping Mod
 
nacredata,

I tried using your mod on 4.1.7 but wasn't able to get anywhere with it. Everything is added, but the price is still the same for all UPS options.

I verified within the database that the subcode is 1 for UPS Ground. Any suggestions?


All times are GMT -8. The time now is 08:57 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.