View Single Post
  #157  
Old 02-07-2006, 09:08 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default Shipping Estimator for US and Canada

I've modified the original code to take Canada into consideration and allow both US and CA zipcodes to be utilized.

Edit Cart.php locate:
Code:
$intershipper_recalc = "Y";

BEFORE this add:
Code:
# prelogin calculator start # modified by cart-lab.com to allow US and CA zipcodes x_session_register("zipcode_estimate"); $trusted_post_variables = array("zip_estimate"); require $xcart_dir."/include/states.php"; if($HTTP_GET_VARS['zip_estimate'] == "clear"){ $zipcode_estimate = ""; func_header_location("cart.php"); } if(!empty($zip_estimate)){ $zipcode_estimate = $zip_estimate; #$count = substr_count($zipcode_estimate,"0") + substr_count($zipcode_estimate,"1") + substr_count($zipcode_estimate,"2") + substr_count($zipcode_estimate,"3") + substr_count($zipcode_estimate,"4") + substr_count($zipcode_estimate,"5") + substr_count($zipcode_estimate,"6") + substr_count($zipcode_estimate,"7") + substr_count($zipcode_estimate,"8") + substr_count($zipcode_estimate,"9"); $count = strlen($zipcode_estimate); if($count < 4){ //checking for 5 digits $zipcode_estimate = "";} func_header_location("cart.php"); } if($zipcode_estimate != ""){ $count = strlen($zipcode_estimate); if($count == 5) { $config["General"]["apply_default_country"] = "Y"; $config["General"]["default_zipcode"] = $zipcode_estimate; $userinfo["s_zipcode"] = $zipcode_estimate; $smarty->assign("estimate","NO"); } else { $config["General"]["apply_default_country"] = "Y"; $config["General"]["default_country"] = "CA"; $config["General"]["default_zipcode"] = $zipcode_estimate; $userinfo["s_country"] = "CA"; $userinfo["s_zipcode"] = $zipcode_estimate; $smarty->assign("estimate","NO"); } } # prelogin calculator end

Now onto the .tpl, edit skin1/customer/main/cart_totals.tpl and locate:
Code:
<input type=hidden name=paymentid value="{$smarty.get.paymentid|escape:"html"}">

BEFORE this line add:

Code:
{* Shipping Estimate *} {*{if $not_logged_message eq "1"}{$lng.txt_order_total_msg}{/if}*} {if $login eq ""} {if $estimate ne "NO"} Enter your zip code to estimate shipping charges: <input type=TEXT name='zip_estimate' size=6 maxlength=6> {*{include file="main/states.tpl" states=$states name="s_state" default=$userinfo.s_state default_country=$userinfo.s_country}*} <input type=image alt="Calculate Shipping" src="{$ImagesDir}/go.gif" border=0 align=absmiddle name=btnCalculate> {else} Click here to change your zip code: {$userinfo.s_zipcode} {/if} {/if} {* END Shipping Estimate *}

Note the original commented code that will need to be replaced as well:
Code:
{*{if $not_logged_message eq "1"}{$lng.txt_order_total_msg}{/if}*}

Anyhow, I figured I would contribute this extension to an already much needed mod X-Cart should have by default if you ask me
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote