View Single Post
  #1  
Old 03-30-2004, 03:39 PM
 
rackit rackit is offline
 

Advanced Member
  
Join Date: Jan 2004
Posts: 31
 

Default Pre-Login Shipping Calculator

It would great if users could fill in their zip code and receive an estimate on their shipping cost based on the items currently in their cart. I know that some customers don't want to fill in all their contact information to find out the shipping charge. Does anyone else think this would be a good addition?

Edit: Here's my solution..

This works using a lot of methods already built into X-Cart. All that was required was manipulating them to do what I wanted. There's an option in General Settings that allows you to presume a customer is from a default country when not logged in. When this option is enabled, shipping charges are calculated automatically as items are added to the cart. What this modification does is enable this option when a user enters his/her zip code and changes the default zip code to what was entered.

To start off, the option "When a customer isn't logged in, it is presumed that he is from a default country." must be UNCHECKED (disabled). Secondly, replace this code in cart.php:

Code:
x_session_register("cart"); x_session_register("intershipper_rates"); x_session_register("intershipper_recalc"); x_session_unregister("secure_oid"); x_session_register("extended_userinfo"); x_session_register("anonymous_checkout");

with this code:

Code:
x_session_register("cart"); x_session_register("intershipper_rates"); x_session_register("intershipper_recalc"); x_session_unregister("secure_oid"); x_session_register("extended_userinfo"); x_session_register("anonymous_checkout"); x_session_register("zipcode_estimate"); if($HTTP_GET_VARS['zip_estimate'] == "clear"){ $zipcode_estimate = ""; func_header_location("cart.php"); } if(!empty($HTTP_POST_VARS['zip_estimate'])){ $zipcode_estimate = $_POST['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"); if($count != 5){ //checking for 5 digits $zipcode_estimate = "";} func_header_location("cart.php"); } if($zipcode_estimate != ""){ $config["General"]["apply_default_country"] = "Y"; $config["General"]["default_zipcode"] = $zipcode_estimate; $smarty->assign("estimate","NO"); }


The last thing to do is add the the input box in a template. cart_total.tpl seems like an obvious place for me. This is the code I put in my template:

Code:
{if $not_logged_message eq "1"} {if $estimate ne "NO"} Enter your zip code to calculate shipping charges. <input type=TEXT name='zip_estimate' size=5 maxlength=5> <input type=image alt="Calculate Shipping" src="../skin1/images/calculate.gif" border=0 align=middle name=btnCalculate > {else} Click here to change your zip code {/if} {/if}

You can check it out in action at www.rack-it.com. A quick warning, if you add any product made by Yakima on my site that is over $50, the shipping will be free and this mod won't do anything.
Reply With Quote