View Single Post
  #268  
Old 04-17-2008, 08:38 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Pre-Login Shipping Calculator

I think I figured it out, seems to work. Needs more testing though. Please report back so we can get this work the best way possible. Changes are in red. X-Cart 4.1.8 without fast lane checkout.

1. in your cart.php

# 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";
$trusted_post_variables = array("state_estimate");

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 length
$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_country"] = "US";
$config["General"]["apply_default_state"] = "Y";
$config["General"]["default_state"] = $state_estimate;
$config["General"]["default_zipcode"] = $zipcode_estimate;
$userinfo["s_country"] = "US";
$userinfo["s_state"] = $state_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_state"] = $state_estimate;
$config["General"]["default_zipcode"] = $zipcode_estimate;
$userinfo["s_country"] = "CA";
$userinfo["s_state"] = $state_estimate;
$userinfo["s_zipcode"] = $zipcode_estimate;
$smarty->assign("estimate","NO");
}

}
# prelogin calculator end

2. in your cart_totals.tpl

{* BEGIN Shipping Estimate *}
{if $login eq ""}
{if $estimate ne "NO"}
<table width="100%">
<tr>
<td>
{$lng.lbl_shipping_estimate}:
</td>
<td>
<input type="text" name="zip_estimate" size="8" maxlength="6" />
{include file="main/states.tpl" states=$states name="state_estimate" default=$userinfo.s_state default_country=$userinfo.s_country}
</td>
<td>
{include file="buttons/submit.tpl" button_title="Estimate" style="button" href="javascript: document.cartform.submit();"}
</td>
</tr>
</table>
{else}

<p style="margin-top: 5px; font-size: 10px;">
{$lng.txt_estimate_shipping_charge}<br />
{$lng.lbl_shipping_change}: <a href="cart.php?zip_estimate=clear">{$userinfo.s_zi pcode}</a>
</p>
{/if}
{else}
<p style="margin-top: 5px; font-size: 10px;">
{$lng.txt_logged_shipping_charge}
</p>
{/if}
{* END Shipping Estimate *}

I didn't bother to fix the interface so the boxes might not line up. And one glitch I see - nothing prevents customer from inserting for instance zip code for FL and state NE which will probably end up returning wrong rates.
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote