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)
-   -   Pre-Login Shipping Calculator (https://forum.x-cart.com/showthread.php?t=6927)

rackit 03-30-2004 03:39 PM

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.

adpboss 03-30-2004 05:25 PM

Tried to get something like this built, but the developer came up short.

Would be a handy item to have, but first we need shipping by Postal Code up here in CANADA. X-Cart are you listening?

jeeya 03-30-2004 09:26 PM

all I wish for is to offer free shipping based on certain states or countries.

adpboss 03-30-2004 10:02 PM

Raxitpatel,

You can already so this. I checked your site and the rates look like you are not using the USPS realtime shipping. All of your shipping is manual.

Just put the states or countries you want to have free shipping in their own individual zones. Then create new "Free Shipping" methods and link them to the zones in the Shipping charges page.

I hope this makes sense. I am really tired. I'll check back tomorrow.

rackit 04-02-2004 04:51 PM

Ok, I figured out a way to do this, but I need a little bit of help. If anyone knows how to set up session variables, it would great if you could help me out. It works the way I have it right now, but I would like the shopping cart to remember the person's zip code through the first step of checkout or if the person goes to shop around a bit more and then goes back to the cart.

edit: Nevermind!

I figured out the session variable thing. I'll try to have it done and posted in an hour or so, but it's friday night and I have better things to do. (oddly :))

rackit 04-04-2004 09:54 PM

It's up and running now. Check it out www.rack-it.com

My code is sloppy right now so I'm cleaning it up. I'll post it when it's nice and neat.

adpboss 04-06-2004 07:16 AM

Rackit,

Please post that, it's awesome.

rackit 04-06-2004 07:16 PM

Edit: moved the code to the first post.

GM 05-27-2004 11:52 AM

Looks good.... just one problem, I'm from Canada and I buy most of my big ticket items on the web. My postal code is P0H 1A0... doesn't work.
I'm more of an American at heart really, I've travelled through the U.S. more than I have Canada and I buy a lot from the States. I know every single person we've had running our country has been an idiot who can't speak right or has some wierd 8O deformation but the rest of us up here are really o.k. (and we're better at hockey and your beer is for little girls :roll: ), so you Southern Boys are gonna' have to allow for Canadian purchases. I don't blame you for wanting to shut us out because of the people running this place but give the rest of us a break. :D

[UPDATE] I guess I have to eat my words regarding hockey :oops: but at least I can wash them down with real beer :lol:

adpboss 05-27-2004 08:07 PM

Most shipping calculators that are built into sites do not allow for international postal code lookup.

I will test integration of this into the Canada Post Sell Online module built into 3.5.x and report back if I can get lookup for Canadian business to Canadian addresses working.

All you need to do is add a note under the text box for postal code, indicating that non US customers click HERE for a pop up rate box.

DogByteMan 05-27-2004 09:23 PM

removed

DogByteMan 05-28-2004 05:10 AM

Anyone know the variables in 3.4.x that match those of this mod?

rackit 05-28-2004 08:10 AM

DogByteMan, unfortunately, I've never used 3.4.x so I'm not sure how to work it. If you send me a copy of your cart.php, I might be able to figure it out.

DogByteMan 05-28-2004 01:12 PM

It appears that the variable in this line of code is wrong for 3.4.x

{if $not_logged_message eq "1"}

Anybody know what this should be for 3.4.x in cart_totals.tpl

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}


rackit 05-28-2004 01:38 PM

OK, it looks to me like 3.4.x doesn't have the equivalent of that variable, so we'll have to make one. Try adding this somewhere near the top of cart.php.

Code:


if(!$login){
      $smarty->assign("not_logged_message","1");
}
else{
      $smarty->assign("not_logged_message","0");
}


And, as always, BACK UP! :)

DogByteMan 05-28-2004 02:14 PM

That Did It! =D> \:D/


THANK YOU!!!!

DogByteMan 05-28-2004 02:39 PM

OK, first off a big THANK YOU to rackit for this mod!

rackit's mod for 3.4.x

In Langages under Add New Entry enter the following

lbl_calculate Calculate Calculate


In edit templates - buttons/

create new file calculate.tpl


Open calculate.tpl and insert this code

Code:

<font class=FormButton>{$lng.lbl_calculate} <img { include file="buttons/go_image.tpl" }></font>


In customer/cart.php

Just Below This Code

Code:

#
# $Id: cart.php,v 1.153.2.8 2003/09/10 06:14:10 svowl Exp $
#
# This script implements shopping cart facility
#

require "../smarty.php";
require "../config.php";
@include "./https.php";
require "./auth.php";

//include "./nocookie_warning.php";


Add This Code

Code:

if(!$login){
      $smarty->assign("not_logged_message","1");
}
else{
      $smarty->assign("not_logged_message","0");
}

x_session_register("cart");
x_session_register("intershipper_rates");
x_session_register("intershipper_recalc");
x_session_unregister("secure_oid");
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");
      }


Replacing or Deleting This Existing Code Which Is Already Included In The Above Code

Code:

x_session_register("cart");
x_session_register("intershipper_rates");
x_session_register("intershipper_recalc");
x_session_unregister("secure_oid");



In customer/main/cart_totals.tpl

Right Below This Code

Code:

<TR>
<TD nowrap><font class=FormButton>{$lng.lbl_order_total}:</font></TD>
<TD>[img]{$ImagesDir}/null.gif[/img]
</TD>
<TD nowrap align=right><font class=ProductPriceSmall>{include file="currency.tpl" value=$cart.total_cost}</font></TD>
<TD nowrap align=right>{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$cart.total_cost}</TD>
</TABLE>


ADD This Code

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>
{if $js_enabled}
{include file="buttons/calculate.tpl"}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_calculate}
{/if}

{else}


Click here to change your zip code

{/if}
{/if}



Your Done!

Again a HUGE THANK YOU to rackit! =D>[/code]

rackit 05-28-2004 07:30 PM

\:D/

DogByteMan 05-29-2004 07:17 AM

My post above has been edited to reflect a more consistent look and feel of the X-Cart

donna8284 05-31-2004 01:09 PM

Has anyone gotten this to work on v3.5.8 yet? I had it working on 3.5.1 but have recently upgraded and can not get it to work again. Thanks!!

kumar 05-31-2004 02:19 PM

Anyone get this to work on version 3.3.5?

kumar 06-05-2004 08:28 PM

I am willing to pay if anyone can make this work with 3.3.5!

Please let me know!

rackit 06-05-2004 11:20 PM

Quote:

Originally Posted by kumar
I am willing to pay if anyone can make this work with 3.3.5!

Please let me know!


LOL. I'll help you do it for free, but I'll have to see your cart.php and cart_totals.tpl files. Send me a message with them and I'll see what I can do.

DogByteMan 06-06-2004 08:01 AM

rackit is a true X-Cart community member =D>

kumar 06-06-2004 08:40 AM

Rackit,

I just sent you the code.

Please let me know if you can help!

Thanks a bunch!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!

Quote:

Originally Posted by rackit
Quote:

Originally Posted by kumar
I am willing to pay if anyone can make this work with 3.3.5!

Please let me know!


LOL. I'll help you do it for free, but I'll have to see your cart.php and cart_totals.tpl files. Send me a message with them and I'll see what I can do.


donna8284 06-09-2004 09:38 PM

Anything for v3.5.8 yet? Thanks!!

rackit 06-09-2004 10:11 PM

Kumar, I took a look at the code and I don't see a way to make it work. If I had access to all the functions, I might be able to make it work, but it would probably require a lot of changes. Sorry.



Donna, the original version was for 3.5.5, so I would imagine this works on 3.5.8.

longhorn180 06-10-2004 04:07 AM

I've got version 3.4.14 and put in the code as stated above, but I get this error right below the form:Warning: Smarty error: unable to read template resource: "buttons/calculate.tpl" in /home/username/store-www/xcart/Smarty-2.5.0/Smarty.class.php on line 1042. I was wondering if anyone else is getting this error and if it is easily fixed. This is a great little mod and I would love to be able to use it.



--------------------------------------------------------------------------------

joestern 07-01-2004 08:27 AM

Rack-it--Your site looks great!

Unfortunately, I cannot get this to work in 3.5.8 either. I have the code in, the line and box appears in the cart, but when you enter the zip-code, the shipping stays at "N/A" and is not calculated.

Any thoughts?

rackit 07-01-2004 02:19 PM

If you send me your cart.php and cart_totals.tpl files, I can give it a try.

joestern 07-01-2004 02:23 PM

I would love to send you the files; I may be a moron, but can this be done via PM or can you PM me your email address?

rackit 07-01-2004 02:57 PM

you can copy and paste your code into the message or you can send an e-mail to greg@rack-it.com

rackit 07-01-2004 03:44 PM

modfied code
 
Hi,

I took a look at your cart.php and it looks exactly like mine. The only thing I can think off is that you maybe a slight error in adding the code. It might be easier if you send me your modified version of cart.php with my code in it.

Greg

DogByteMan 07-01-2004 07:13 PM

Quote:

Originally Posted by joestern
Rack-it--Your site looks great!

Unfortunately, I cannot get this to work in 3.5.8 either. I have the code in, the line and box appears in the cart, but when you enter the zip-code, the shipping stays at "N/A" and is not calculated.

Any thoughts?


If your using Net::SSLeay, make sure you enter

/usr/bin/perl

as the full path to perl in the General Settings and see if that helps.

If not, try libCURL to see if that makes it work.

I had to change to libCURL to make it work originally, but once I entered the full path to perl i was able to switch back to Net::SSLeay.

joestern 07-02-2004 12:10 PM

I am using Net::SSLeay, and I just added the /usr/bin/perl, but I still have the same result: I enter in a zip and the result shows "n/a"...it doesn't calculate. Any other ideas?

I hugely appreciate the help.

rackit 07-02-2004 12:26 PM

I can't figure out why it isn't working in 3.5.8. Joe, have you tried setting up the default zip code in the settings? If so, does it work for you?

adpboss 07-02-2004 12:38 PM

Are you using real-time shipping?

joestern 07-02-2004 12:46 PM

We are using FedEx rates, which were downloaded into x-cart.

When we turn on the default zip code and check the "When a customer isn't logged in, it is presumed that he is from a default country" box, the shipping rates are displayed properly.

When we turn that option off and use the rack-it mod, it does not calculate shipping after entering a zip code.

We have not changed to libCurl, because we had some major problems with it and authorize.net.

Thanks for the help--I'm dying to get this to work!

DogByteMan 07-02-2004 01:43 PM

I'm afraid my experience is with UPS realtime shipping, but I can't see why it would not work for FedEx also.

DogByteMan 07-02-2004 01:47 PM

Give Us Your Environment Info located in summary


All times are GMT -8. The time now is 12:33 PM.

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