Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    Jun 2008
    Location
    Osprey, Florida
    Posts
    151
    Plugin Contributions
    14

    Default Getting/Displaying the Customer's State

    I was recently trying to get to display the customer's country attempting to integrate a Survey type script with ZenCart. With the help of Design75 I got it to work. See post 212016.

    I'm trying now to display the state. I'
    m using the code shown below:
    PHP Code:
            $state_query "select address_book_id, entry_firstname as firstname, entry_lastname as lastname,
                                     entry_company as company, entry_street_address as street_address,
                                     entry_suburb as suburb, entry_city as city, entry_postcode as postcode,
                                     entry_state as state, entry_zone_id as zone_id,
                                     entry_country_id as country_id
                              from " 
    TABLE_ADDRESS_BOOK "
                              WHERE customers_id = :customersID"
    ;
            
    $state_query $db->bindVars($state_query':customersID'$_SESSION['customer_id'], 'integer');
            
    $check_customer $db->Execute($state_query);
            
    $customer_state $check_customer->fields['state'];
            
    $state zen_output_string_protected($customer_state); 
    Interesting enough, if I replace 'state' with 'company', 'street_address' etc..., I get the proper information displayed but not so with state.

    I would really appreciate if anyone can tell me exactly what I am missing or doing wrong.

    Thanks

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Getting/Displaying the Customer's State

    If you look in the header_php.php for the login, you will see that the country id and zone id are set to:
    Code:
            $_SESSION['customer_country_id'] = $check_country->fields['entry_country_id'];
            $_SESSION['customer_zone_id'] = $check_country->fields['entry_zone_id'];
    You could use these to look up Country/State of a customer in the zones table ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Jun 2008
    Location
    Osprey, Florida
    Posts
    151
    Plugin Contributions
    14

    Default Re: Getting/Displaying the Customer's State

    Thanks so much!

  4. #4
    Join Date
    Jun 2008
    Location
    Osprey, Florida
    Posts
    151
    Plugin Contributions
    14

    Default Re: Getting/Displaying the Customer's State

    I'm still having issues with this. How exactly do you look up something in a table.

    Right now I have this:
    PHP Code:
        if ($_SESSION['customer_id']) {
            
    $name_query "SELECT customers_firstname, customers_lastname, customers_email_address FROM " TABLE_CUSTOMERS " WHERE customers_id = :customersID";

            
    $name_query $db->bindVars($name_query':customersID'$_SESSION['customer_id'], 'integer');
            
    $check_customer $db->Execute($name_query);
            
    $customer_email $check_customer->fields['customers_email_address'];
            
    $customer_name $check_customer->fields['customers_firstname'] . ' ' $check_customer->fields['customers_lastname'];



            
    $country_query "SELECT entry_country_id FROM " TABLE_ADDRESS_BOOK " WHERE customers_id = :customersID";
            
    $country_query $db->bindVars($country_query':customersID'$_SESSION['customer_id'], 'integer');
            
    $check_customer $db->Execute($country_query);
            
    $customer_country $check_customer->fields['entry_country_id'];
            
    $country zen_get_country_name($customer_country);



            
    $state_query "select address_book_id, entry_firstname as firstname, entry_lastname as lastname,
                                     entry_company as company, entry_street_address as street_address,
                                     entry_suburb as suburb, entry_city as city, entry_postcode as postcode,
                                     entry_state as state, entry_zone_id as zone_id,
                                     entry_country_id as country_id
                              from " 
    TABLE_ADDRESS_BOOK "
                              WHERE customers_id = :customersID"
    ;
            
    $state_query $db->bindVars($state_query':customersID'$_SESSION['customer_id'], 'integer');
            
    $check_customer $db->Execute($state_query);
        } 
    How do I add this:
    PHP Code:
            $_SESSION['customer_country_id'] = $check_country->fields['entry_country_id'];
            
    $_SESSION['customer_zone_id'] = $check_country->fields['entry_zone_id']; 

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,603
    Plugin Contributions
    88

    Default Re: Getting/Displaying the Customer's State

    Try something like the following
    Code:
    $state_code = '';
    $state_name = '';
    if (isset($_SESSION['customer_country_id']) && isset($_SESSION['customer_zone_id'])) {
      $state_info = $db->Execute("SELECT zone_code, zone_name FROM " . TABLE_ZONES . " WHERE zone_country_id = " . $_SESSION['customer_country_id'] . " AND zone_id = " . $_SESSION['customer_zone_id'] . " LIMIT 1");
      if (!$state_info->EOF) {
        $state_code = $state_info->fields['zone_code'];  // 2-character code
        $state_name = $state_info->fields['zone_name']; // Full name
      }
    }

  6. #6
    Join Date
    Jun 2008
    Location
    Osprey, Florida
    Posts
    151
    Plugin Contributions
    14

    Default Re: Getting/Displaying the Customer's State

    First of all, thanks for your help.

    Did that code work for you? I have tried a variety of different ways to make it work but nothing yet. Do you think I'm missing something in the account I created? I populated al the fields in the account creation page and the state is shown on my address book and shipping estimator but can't make this work. This is really kicking my fourth point of contact.

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,603
    Plugin Contributions
    88

    Default Re: Getting/Displaying the Customer's State

    Quote Originally Posted by ultimate_zc View Post
    First of all, thanks for your help.

    Did that code work for you? I have tried a variety of different ways to make it work but nothing yet. Do you think I'm missing something in the account I created? I populated al the fields in the account creation page and the state is shown on my address book and shipping estimator but can't make this work. This is really kicking my fourth point of contact.
    Yes, that code worked for me (given that a customer has signed in; that's when the $_SESSION variables are set). In which page (or pages) are you trying to use this code?

  8. #8
    Join Date
    Jun 2008
    Location
    Osprey, Florida
    Posts
    151
    Plugin Contributions
    14

    Default Re: Getting/Displaying the Customer's State

    Thanks again. I'm trying to display it on the checkout_success page.

  9. #9
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,603
    Plugin Contributions
    88

    Default Re: Getting/Displaying the Customer's State

    I placed that code fragment in /includes/modules/pages/checkout_success/header_php_test.php and the $state_code and $state_name variables reflected the state that's associated with the $_SESSION variables.

    What source file are you using to detect the state information?

  10. #10
    Join Date
    Jun 2008
    Location
    Osprey, Florida
    Posts
    151
    Plugin Contributions
    14

    Default Re: Getting/Displaying the Customer's State

    I added the code to an additional file that I'm working on. I just removed it in order to place it in /includes/modules/pages/checkout_success/header_php.php but it isn't showing.

    It must be something with the settings of my account, do you think? However, if I get the state in my account page and the shipping estimator, I assume that the code should display it... (killing me).

    Thanks again, I'll keep trying.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Getting/Displaying the Customer's Country
    By ultimate_zc in forum General Questions
    Replies: 7
    Last Post: 9 Feb 2014, 09:41 PM
  2. Can I change the State to just the State Code?
    By rbobzin in forum General Questions
    Replies: 0
    Last Post: 10 Jul 2008, 10:58 PM
  3. I want to add a button to my website so that the customer can state his amount ......
    By lrfowler in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 14 May 2008, 06:28 AM
  4. how do I rename the word "state" - asin the state dropdown on the checkout page?
    By SoftDux in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 4 Mar 2008, 07:19 PM
  5. Customer Reviews - displaying the name
    By ginginca in forum General Questions
    Replies: 1
    Last Post: 18 Feb 2007, 11:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR