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)

joestern 07-02-2004 01:56 PM

Here you go...

Code:

Environment components info:
 Component Status 
X-Cart version 3.5.8   
X-Cart directory /var/www/html/cart   
PHP 4.1.2  details >>
MySQL server 3.23.58   
MySQL client 3.23.58   
Web server unknown 
Operation system Linux   
Perl 5.006001  details >>
XML parser (expat) found   
HTTPS modules
Net::SSLeay 1.23  active 
libCURL libcurl 7.8 (OpenSSL 0.9.6b) (ipv6 enabled)   
CURL executable curl 7.8 (i386-redhat-linux-gnu) libcurl 7.8 (OpenSSL 0.9.6b) (ipv6 enabled)   
OpenSSL executable OpenSSL 0.9.6b [engine] 9 Jul 2001   
HTTPS-cli executable not found 
Modules for the payment methods
VeriSign PayFlow Pro client /var/www/html/cart/payment/bin/pfpro L305   
PayBox client not found 
Saferpay client not found 
TrustCommerce (tclink.so) not found


adpboss 07-02-2004 02:30 PM

Quote:

Originally Posted by joestern
We are using FedEx rates, which were downloaded into x-cart.

It may be because Fedex doesn't actually query a server but looks up a rate sheet?

Just guessing here...

adpboss 07-02-2004 10:44 PM

Just tried on 3.5.9 with no success.

I'm using Canada Post RealTime Shipping here. :(

I expanded the text field to 6 digits (characters) in the php file and the template, but basically this doesn't work so good for me.

adpboss 07-04-2004 11:22 AM

Rackit,

I think I may have tracked down why this is not working for Fedex or Canada Post.

Mod_UPS calls for

Code:

$dst_country_code=$userinfo["s_country"];
$dst_city=$userinfo["s_city"];
$dst_zipcode=$userinfo["s_zipcode"];


Mod_CPC (Canada Post Corporation) requires

Code:

$cp_dest_country = $userinfo["s_country"];
$cp_dest_city = $userinfo["s_city"];
$cp_dest_zip = $userinfo["s_zipcode"];
$cp_dest_state = $userinfo["s_state"];


I believe that the Canada Post server validates the Postal code with the province (state).

Mod_Fedex asks for a whole bunch of stuff which is probably beyond keeping this estimator simple.

Code:

# do all these queries only if FedEx is present.
if ($FEDEX_FOUND) {

$supportHome=array('US'=>1,'CA'=>1);
$supportGrnd=array('US'=>1,'CA'=>1,'PR'=>1);

$ozip = $config["Company"]["location_zipcode"];
$dzip = $userinfo["s_zipcode"];
$s2res = ($supportHome[$userinfo["s_country"]] ? $params["param02"] : "false");
$ctyp = ($supportGrnd[$userinfo["s_country"]] ? $params["param00"] : "Express");
$isex = ($ctyp == "Express" ? true : false);
$isgr = ((($ctyp == "Ground" || $ctyp == "Both") && $s2res != "true") ? true : false);


So because I am concerned with Mod_CPC (Canada Post) I need to add the province (state) data to the information sent by the shipping estimator.

I can either

1. Let the customer choose there province from a drop down (in addition to the postal code entry)
2. Have the postal code look-up in PHP for the correct province (state) info.

Canadian Postal Codes work like this

Letter-Number-Letter<space>Number-Letter-Number

ie.
R7N 2G6
A1N 9D9
N7X 4J0

The first character a letter dictates which province the postal code is for. List for lookup in PHP purposes.

Newfoundland/Labrador - "A"
Nova Scotia - "B"
Prince Edward Island - "C"
New Brunswick - "E"
Quebec - "G", "H", "J"
Ontario - "K", "L", "M", "N", "P"
Manitoba - "R"
Saskatchewan - "S"
Alberta - "T"
British Columbia - "V"
Northwest and Nunavut Territories - "X"
Yukon Territory - "Y"

I could use some help and would be happy to donate or something. I can guarantee that an ENTIRE nation of X-Cart users would be very excited and grateful to have this mod. ;)

joestern 07-04-2004 07:28 PM

I'd also be delighted to donate for the time it takes to tinker the code to work with FedEx lookup!

adpboss 07-09-2004 08:38 PM

Is this dead, because I only need a little help with the PHP to add a Canadian Postal Province (state) drop down and have it submit with the postal code.

It's worth some money to me if anyone is listening...

rackit 07-09-2004 08:51 PM

which parts exactly do you need help with?

adpboss 07-09-2004 10:14 PM

IN my second to last post (before this one)i chronicled how Canada Post needs one more piece of info over UPS. I need the state.

I think the easiest way is to use a drop down.

I am good at Smarty but lousy at PHP. I have no idea how to get started.

adpboss 07-15-2004 10:20 PM

BUMP

doersam@hotmail.com 07-21-2004 11:08 PM

Can't get this modification to work in 3.5.10
 
I can't get the zip code calculation to show up in 3.5.10 Can anyone tell me exactly where in the cart_totals.tpl I should insert the code? Thank you very much.

vsgamingsupplies 08-03-2004 07:41 PM

Re: Pre-Login Shipping Calculator
 
Thanks. I'm really interested in ths mod but I have a problem. Any ideas on why this wouldn't work with 4.0? No errors. It just reloads the page without anything changed on the page.

wallachee 08-16-2004 06:19 PM

Anybody find the correct if statement for 3.5.10 for the cart_totals.tpl? I've scoured the files in 3.5.10, but I can't find the if statement responsible for determining if a customer is logged in or not...in other words, how do you put this into code in 3.5.10...

{if customer not logged in}

do this

{/if}

-Bradley

B00MER 08-17-2004 06:25 AM

Code:

{if $not_logged_message eq "1"}

instead of doing this why not just do:

Code:

{if $login} {else} (insert code) {/if}

For some reason you can't do {if !$login} or {if $login eq null} or {if $login eq false}

Just doesn't work in smarty so you have to do the above.

wallachee 08-17-2004 06:29 AM

Thanks again Boomer. I finally figured it out a simple way in 3.5.10... it is below...

{if $login eq ""}


All is well now. Many thanks.

-Bradley

doersam@hotmail.com 08-17-2004 06:58 AM

Can anyone post the COMLETE code modification for 3.5.10 -- Sorry, but I am a bit green at this. Thanks!

adpboss 08-17-2004 01:51 PM

PM DogByteMan. He's usually pretty helpful.

joestern 08-22-2004 06:32 PM

Here's a bit of an update--

I still do not think this mod works for 3.5.8, and if anyone has managed to get it working, please post what you did.

Originally, we tried to get to working using FedEx rates, but that clearly was a problem.

Now we are using real time UPS rates, and the mod still does not work. We have triple-checked that all code was entered correctly (would be happy to send files wherever, and also would be willing to pay someone to help get it to work).

Oddly, if we DO enter a default country/zip in the general settings, X-cart DOES produce the shipping cost pre-login.

One question I have: our site does not require a login (anonymous checkout is permitted). I notice this is different from rack-it's site. Does this matter? I don't think it should because the code is relying on the default zipcode setting, but I'm not sure.

Any help would be greatly appreciated!

joestern 08-25-2004 08:19 AM

Another bit of info that may mean something here: we use HTTPS for the entire checkout process - all cart screens. I noticed that rackit doesn't use a secure server until the final checkout page. Could this be a source of problems here? Is it possible that my cart page never thinks it got zip_code data? Is there any simple code I could add as a test to just "echo" the zip_code that should have been entered?

Also: still will to pay to get this working . . .

adpboss 08-25-2004 09:28 AM

There are a half dozen X- users who will pay for this. No one is listening. That really sucks. What happened to all of the capitalist developers?

B00MER 08-25-2004 10:19 AM

Personally I think the best method to take with this is just to add a zipcode input field on the product details page and view cart or checkout. I know there is a section of code in cart.php that passes the default information specified in the admin to the shipping routines to calculate a shipping cost before login/register.

anyhow, hth. :wink:

B00MER 08-25-2004 10:25 AM

btw, try this and it should fix the issue for 3.5.8+: open up top.inc.php

find:

Code:

if (!in_array($__key, array("HTTP_GET_VARS","HTTP_POST_VARS","HTTP_SERVER_VARS","HTTP_ENV_VARS","HTTP_COOKIE_VARS","HTTP_POST_FILES","__key","__val")))
to:
Code:

if (!in_array($__key, array("HTTP_GET_VARS","HTTP_POST_VARS","HTTP_SERVER_VARS","HTTP_ENV_VARS","HTTP_COOKIE_VARS","HTTP_POST_FILES","__key","__val","_GET","_POST","_SERVER")))

I just noticed this mod uses _GET globals which was capped in 3.5.8+ for security reasons. Although it breaks quite a few mods. hth. ;)

joestern 08-25-2004 04:15 PM

Thanks very much for the input. This did something, but it did not seem to do the trick. Before the change, we would input a zip code and the screen would refresh, but the shipping would not calculate. Instead, the "Enter your Zip code" input box would remain. Also, after we enter a zip code, the shipping drop down box disappears, and the follow shows up "To calculate shipping costs, please proceed to step one of checkout. anonymous."

Now, after Boomer's suggested change, X-cart seems to get the zip-code entry (because it gives the "To change your zip code click here" option), but it does not calculate shipping. Also, once you have entered a zip code, the "To change your zip code" option is dead--it does not actually work.

Our troubleshooting shows:
X-Cart IS getting the zip code (it is changing zipcode_estimate)
X-Cart IS setting "default country" to "Y"

Any thoughts?
Thanks!

adubas 08-28-2004 06:54 AM

Will this work with v4.0.3 ?

inksticks 09-01-2004 05:21 AM

pre-login shipping calculator
 
I would really appreciate it if someone could post a pre-login shipping calculator mod for version 4.0.3. I would also like to request that their would be a country drop down menu in addition to the zip/postal code box so that international customers could also figure their shipping costs. Thank you for the assistance.

jburdi 09-04-2004 12:17 AM

i dunno if anyone else is having this problem, but for some reason when I use this to calculate shipping, it adds NY state sales tax, no matter what zip I put in. the spot that says "Tax" still says n/a, but tax is figured into the order total. i dont want take to be figured out at all unless they are logged in.

i am using 3.5.6, any information would be helpful, thanks.

nbsp 09-15-2004 10:23 PM

I feel this is a very important mod and would like to thank the contributors.

Can anyone confirm that this work with x-cart 4.0.3 and FedEx?

(I assume I am using Net::SSLeay since the Admin Summary states that one as active.)

inksticks 09-22-2004 02:52 AM

pre-login shipping calculator
 
I would really appreciate knowing if someone is having success developing a pre-login shipping calculator for version 4.0.4. I want it to work internationally which would require 2 fields: zip code and country. Zip code could not be limited to 5 digits or only numbers or it would not work for Canada. Please let me know what the possibilities are of getting this. Thanks!

B00MER 09-22-2004 05:46 AM

Zipcode would really only work with a live shipper like UPS or Fedex. I'm testing this mod on a 3.5.11 setup and using just a zipcode with zone shipping charges won't do anything because x-cart has to know the country and state in order to apply you to the proper zone.

I agree the zipcode mask should be greater than 5 for other country zip codes. But I think allowing the user to choose their country/state should give them the most accurate shipping quote.

I'll let you know what I find.

BCSE 09-23-2004 10:36 AM

I just installed this on a 4.0.4 version today. Here's the code I used:

In cart.php After:
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("payment_cc_fields");
x_session_register("current_carrier");


Insert:
Code:

x_session_register("zipcode_estimate");

if($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");

      if($count != 5){  //checking for 5 digits
          $zipcode_estimate = "";}
      if($mode=="checkout")
              func_header_location("cart.php?mode=checkout");
      else       
        func_header_location("cart.php");
}
if($zipcode_estimate != "")
{
      $config["General"]["apply_default_country"] = "Y";
      $config["General"]["default_zipcode"] = $zipcode_estimate;
      $smarty->assign("estimate","NO");
}


Then in skin1/customer/main/cart_totals.tpl Before:
Code:

{if $not_logged_message eq "1"}{$lng.txt_order_total_msg}{/if}

Add:
Code:

{* BCSE Begin *}
{if $login}
{else}
        {if $estimate ne "NO"}
           
Enter your zip code to calculate shipping charges.

                <input type=TEXT name='zip_estimate' size=5 maxlength=5>
                {include file="buttons/button.tpl" button_title="Calculate Shipping" href="javascript: document.cartform.submit()"  js_to_href="Y"}
               
          {else}

Click here to change your zip code

          {/if}
         


{/if}
{* BCSE End *}


Hope this helps! Thanks for the original code rackit!

Carrie

inksticks 09-23-2004 02:21 PM

Thank you
 
Thank you for the post for 4.0.4 It works great! Any chance of modifying the code a little so that we could get a country field in there and so that international customers could use it. The zip code field would also have to be expanded to accept more that just 5 characters and would need to accept letters as well as numbers since some countries zip codes, like Canada for example, use alfa/numeric codes. I would really appreciate such a modification.

inksticks 09-23-2004 03:12 PM

Shipping: n/a
 
One thing I noticed is that even though the prices are listed and are calculated in the total, the shipping line on the cart page says shipping: n/a How could I get the actual shipping price to be listed instead of n/a.

Also in my particular case I offer free shipping over $50 and when free shipping is selected all the prices of the other delivery methods disappear. However, if a different shipping method is selected all the rates reappear in the 'Delivery method' drop down box. I would appreciate any ideas of how to resolve these issues. Thanks so much everyone for the mod.

BCSE 09-23-2004 03:42 PM

On the 4.0.4 version I put this on the shipping is calculated in the drop down and in the shipping line. There isn't any n/a showing up on the site I have this on. Make sure "When a customer isn't logged in, it is presumed that he is from the default country.:" is not checked in the admin general settings.

HTH!

Carrie

adpboss 09-23-2004 04:14 PM

Carrie,

If you can get the 4.0.4 mod to work for Canada Post & UPS simultaneously (Canadian 6 character postal codes),
I will love you even more than I love you now. Like that is even possible! ;)

[-o<

If money makes the wheels turn faster, PM me.

BCSE 09-23-2004 08:29 PM

Try this adpboss. ;) I have this working in 4.0.4 for US and Canada realtime shipping. I tested this for FedEx only as I don't have USPS account or UPS account.

In cart.php After:
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("payment_cc_fields");
x_session_register("current_carrier");


Insert:
Code:

# BCSE

x_session_register("zipcode_estimate");
x_session_register("default_country_estimate");

if($zip_estimate == "clear")
{
      $zipcode_estimate = "";
      func_header_location("cart.php");
}
 
if(!empty($zip_estimate))
{
      $zipcode_estimate = $zip_estimate;
     
      $default_country_estimate= $country_estimate;
   
    if($country_estimate == "US")
    {
              $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 = "";
             
    }
        if($country_estimate == "CA" && strlen($zipcode_estimate)!=6)
                $zipcode_estimate= "";
     
      if($mode=="checkout")
        func_header_location("cart.php?mode=checkout");
      else     
        func_header_location("cart.php");
}
if($zipcode_estimate != "")
{
        $config["General"]["default_country"] = $default_country_estimate;
      $config["General"]["apply_default_country"] = "Y";
   
      $config["General"]["default_zipcode"] = $zipcode_estimate;
     
   
      $smarty->assign("estimate","NO");
}

# BCSE


Then in skin1/customer/main/cart_totals.tpl Before:
Code:

{if $not_logged_message eq "1"}{$lng.txt_order_total_msg}{/if}


Insert:
Code:

{* BCSE Begin *}
{if $login}
{else}
  {if $estimate ne "NO"}
       
Enter your zip/postal code to calculate shipping charges.

        <select name='country_estimate'>
        <option value="US">United States
        <option value="CA">Canada
        </select>
       

      <input type=TEXT name='zip_estimate' size=6 maxlength=6>
      {include file="buttons/button.tpl" button_title="Calculate Shipping" href="javascript: document.cartform.submit()"  js_to_href="Y"}
     
      {else}

Click here to change your zip code

    {/if}
   


{/if}
{* BCSE End *}


You owe me a beer if this works adpboss ;)

Carrie

adpboss 09-24-2004 05:34 AM

Will test today. Cheers.

inksticks 09-24-2004 01:39 PM

Problem half resolved
 
Quote:

Originally Posted by BCSE
On the 4.0.4 version I put this on the shipping is calculated in the drop down and in the shipping line. There isn't any n/a showing up on the site I have this on. Make sure "When a customer isn't logged in, it is presumed that he is from the default country.:" is not checked in the admin general settings.

HTH!

Carrie


"When a customer isn't logged in, it is presumed that he is from the default country.:" was not checked. So that wasn't the problem. I restored my skin1/customer/main/cart_totals.tpl and then re-applied the mod it is working correctly now except that when my free shipping option is selected the n/a comes back. If someone has an idea how to make it put 0.00 instead of n/a it would be appreciated. Thank you.

adpboss 09-24-2004 02:05 PM

Couldn't you do something in the tpl like if

Code:

{if $order.shipping_cost eq "0.00"}
N/A
{else}
{$order.shipping_cost}
{/if}


I just made up the shipping cost varible, I am not sure what it is.

adpboss 09-25-2004 01:16 PM

Carrie,

Works like a charm with Canada Post. I don't have UPS setup yet, but will test again when that happens.

Only one small issue I get this error when I first view the cart

Quote:

Canada Post Realtime shipping rate calculation service returned the following error:
XML parsing error.
Sorry, there are no available shipping methods for your location.:
anonymous
Modify

But I think that if I move your code above the cart totals then I can comment out the error text once I figure out what is triggering the error display.

I owe you beer. Only problem is, I am in Canada. I am investigating if I can ship booze cross border. Otherwise I may just have to PP you enough for some drinks!

Alternately you could just come pay me a visit, because everyone knows, CANADIAN BEER ROX!

EDIT

Just found that it errors with US Zip codes being fed into Canada Post system, but for my purpose it is a non-issue. 98% of my customers are Canadian anyway.

Quote:

Canada Post Realtime shipping rate calculation service returned the following error:
Destination Postal Code/State Name/ Country is illegal.
Sorry, there are no available shipping methods for your location.:
anonymous
Modify

BCSE 09-25-2004 05:48 PM

adpboss,

Great! Glad it works! \:D/

Don't worry about the beer. You'll just have to look me up though if you end up in Ohio so we can go have a drink. ;)

Carrie

inksticks 09-26-2004 08:32 AM

free shipping problem
 
Quote:

Originally Posted by adpboss
Couldn't you do something in the tpl like if

Code:

{if $order.shipping_cost eq "0.00"}
N/A
{else}
{$order.shipping_cost}
{/if}


I just made up the shipping cost varible, I am not sure what it is.


Thanks for the tip but this is the opposite of what I want. When the shipping amount equals 0.00 the cart already shows n/a for the shipping price. I would like it show 0.00 instead. For some reason either the tpl or the cart.php is causing it to do this. However, the biggest problem is that when the free shipping is selected all of the prices for the other shipping methods disappear too. The customer has to select a shipping method that costs something in order for the prices to show. When a customer is logged in this problem does not exist. Any help solving this problem would be appreciated.


All times are GMT -8. The time now is 04:58 AM.

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