Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2011
    Location
    Georgia
    Posts
    18
    Plugin Contributions
    0

    Default Replace states name with state abbreviation on admin orders

    I need the States name to display on the ZC admin orders instead of the entire States name. Currently it is display like this.

    JOHN DOE
    123 ANY ST
    ANYTOWN, Florida 34238
    United States

    I need it to display like this.

    JOHN DOE
    123 ANY ST
    ANYTOWN, FL 34238
    United States

    I have found the file public_html/zad/includes/functions/general.php with "Description : Function to retrieve the state/province code (as in FL for Florida etc)" but I don't know how to make it happen here.

    ////////////////////////////////////////////////////////////////////////////////////////////////
    //
    // Function : zen_get_zone_code
    //
    // Arguments : country_id country code string
    // zone_id state/province zone_id
    // default_zone default string if zone==0
    //
    // Return : state_prov_code s tate/province code
    //
    // Description : Function to retrieve the state/province code (as in FL for Florida etc)
    //
    ////////////////////////////////////////////////////////////////////////////////////////////////
    function zen_get_zone_code($country_id, $zone_id, $default_zone) {
    global $db;
    $zone_query = "select zone_code
    from " . TABLE_ZONES . "
    where zone_country_id = '" . (int)$country_id . "'
    and zone_id = '" . (int)$zone_id . "'";

    $zone = $db->Execute($zone_query);

    if ($zone->RecordCount() > 0) {
    return $zone->fields['zone_code'];
    } else {
    return $default_zone;
    }
    }

  2. #2
    Join Date
    Mar 2011
    Location
    Georgia
    Posts
    18
    Plugin Contributions
    0

    Default Re: Replace states name with state abbreviation on admin orders

    Am I asking too much here? I feel sure there is someone among the Zen Cart gurus that can tell me what to change in the general.php file to make this happen or at least why I cannot make it happen.

  3. #3
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Replace states name with state abbreviation on admin orders

    Quote Originally Posted by firebug View Post
    I need the States name to display on the ZC admin orders instead of the entire States name. Currently it is display like this.

    JOHN DOE
    123 ANY ST
    ANYTOWN, Florida 34238
    United States

    I need it to display like this.

    JOHN DOE
    123 ANY ST
    ANYTOWN, FL 34238
    United States

    I have found the file public_html/zad/includes/functions/general.php with "Description : Function to retrieve the state/province code (as in FL for Florida etc)" but I don't know how to make it happen here.

    ////////////////////////////////////////////////////////////////////////////////////////////////
    //
    // Function : zen_get_zone_code
    //
    // Arguments : country_id country code string
    // zone_id state/province zone_id
    // default_zone default string if zone==0
    //
    // Return : state_prov_code s tate/province code
    //
    // Description : Function to retrieve the state/province code (as in FL for Florida etc)
    //
    ////////////////////////////////////////////////////////////////////////////////////////////////
    function zen_get_zone_code($country_id, $zone_id, $default_zone) {
    global $db;
    $zone_query = "select zone_code
    from " . TABLE_ZONES . "
    where zone_country_id = '" . (int)$country_id . "'
    and zone_id = '" . (int)$zone_id . "'";

    $zone = $db->Execute($zone_query);

    if ($zone->RecordCount() > 0) {
    return $zone->fields['zone_code'];
    } else {
    return $default_zone;
    }
    }
    If I understand correctly you want the state abbreviation of the state your cart is in (the admin's address) to be displayed. I thought this information was taken from the address entered in the my Cart (or My Store) field on the admin panel, configuration menu. As such, the "wrong" information is filled in there and should be changed to FL instead of Florida.

    Otherwise you would want to track down the variables that put Florida onto the page(s) in question and where they pull Florida (or whatever states name) replace with the code that returns the state's abbreviation.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Sep 2008
    Posts
    210
    Plugin Contributions
    21

    Default Re: Replace states name with state abbreviation on admin orders

    I think you can go to admin - configuration - customers detail and set:

    State - Always display as pulldown? = true.

    Quote Originally Posted by firebug View Post
    Am I asking too much here? I feel sure there is someone among the Zen Cart gurus that can tell me what to change in the general.php file to make this happen or at least why I cannot make it happen.
    Our Site: http://zucando.com
    Marketing Plugins: Marketing Modules
    Free Response Templates: Responsive Templates

  5. #5
    Join Date
    Mar 2011
    Location
    Georgia
    Posts
    18
    Plugin Contributions
    0

    Default Re: Replace states name with state abbreviation on admin orders

    No I need the States abbreviation to show instead of the whole spelled out States name when I print the customer invoice from the Zen Cart admin. In the ZC admin when you go to Customer>Orders and click on an order the customers address information shows the spelled out States name like this

    JOHN DOE
    123 ANY ST
    ANYTOWN, Florida 34238

    And I need it to be like this when I print the invoices.

    JOHN DOE
    123 ANY ST
    ANYTOWN, FL 34238


    Quote Originally Posted by mc12345678 View Post
    If I understand correctly you want the state abbreviation of the state your cart is in (the admin's address) to be displayed. I thought this information was taken from the address entered in the my Cart (or My Store) field on the admin panel, configuration menu. As such, the "wrong" information is filled in there and should be changed to FL instead of Florida.

    Otherwise you would want to track down the variables that put Florida onto the page(s) in question and where they pull Florida (or whatever states name) replace with the code that returns the state's abbreviation.

  6. #6
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Replace states name with state abbreviation on admin orders

    Quote Originally Posted by firebug View Post
    No I need the States abbreviation to show instead of the whole spelled out States name when I print the customer invoice from the Zen Cart admin. In the ZC admin when you go to Customer>Orders and click on an order the customers address information shows the spelled out States name like this

    JOHN DOE
    123 ANY ST
    ANYTOWN, Florida 34238

    And I need it to be like this when I print the invoices.

    JOHN DOE
    123 ANY ST
    ANYTOWN, FL 34238
    So here's what I can gather... (BTW, thank you for the clarification.) The process was still the same; however, it turns out that the state names are stored in the database. The addresses are built off of the zone_name field. The database does contain a zone_code which is the two letter abbreviation; however, when searching through for 'zone_name' to see where the field is used, there seemed to only be a few files. The classes/orders.php file seemed to have zone_name in it, but I do not have a copy of that file or the others that were returned to be able to follow the path of where it would be acceptable to change the value from zone_name to zone_code so that the two letter abbreviation could be shown. The other "fix" though, is like cvhainb suggested, require users to enter their state using the drop down, where the drop down would need to be repopulated or shown in a different way to store the two letter abbreviation instead of the spelt out name.

    I didn't follow the code close enough to determine what is entered into the user's record when using the drop down (whether the zone_name itself is entered or a reference to the zone_name is made); however, you may be able to back fill the customer information or change the data to be presented by following all of the "clues" to how the information is displayed/printed. I think I've seen someone post a solution somewhere about that, but I haven't found anything yet...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Sep 2008
    Location
    DownUnder, overlooking South Pole.
    Posts
    976
    Plugin Contributions
    6

    Default Re: Replace states name with state abbreviation on admin orders

    Quote Originally Posted by firebug View Post
    function zen_get_zone_code($country_id, $zone_id, $default_zone) {
    global $db;
    $zone_query = "select zone_code
    from " . TABLE_ZONES . "
    where zone_country_id = '" . (int)$country_id . "'
    and zone_id = '" . (int)$zone_id . "'";

    $zone = $db->Execute($zone_query);

    if ($zone->RecordCount() > 0) {
    return $zone->fields['zone_code'];
    } else {
    return $default_zone;
    }
    }

    One way would be to duplicate this function and then change:

    1. the function name from zen_get_zone_code to zen_get_zone_abbr (or whatever, provided there are no conflicts) and then change

    2. return $zone->fields['zone_code']; or whatever, to the specific name of the field that contains the required abbreviation.

    3. and the call to the newly named function.


    (It would be handy in future versions if an admin > configuration > customer switch could be made to affect this change, rather than forcing admins to duplicate the function code)

    My 2c worth.
    Last edited by dw08gm; 22 Nov 2013 at 05:49 AM.

  8. #8
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Replace states name with state abbreviation on admin orders

    It's actually a bit more complicated... The customer, billing, and shipping addresses are not stored in the "orders" database table as "pointers" to an entry in a customers "address_book". Instead the data is extracted from the "address_book" when the order is created and only the text portions are stored directly with the order.

    This ensures the address information associated from an order is kept separate from the customer's "address book". This makes sure the order history is always accurate. It also allows for county / state data not present in the database to be used (such as when state dropdowns are disabled). As a side effect one can also edit addresses associated with a specific order directly without affecting anything else (editing an existing order requires a third party Zen Cart plugin).

    This means we cannot use the "address_book" and will need read the addresses associated with the order. These do not contain the "country_id" or "zone_id" for the address. We also need to take into consideration some "country" and "state" (zone) data may not exist in the database and fall back to simply displaying the raw data from the order (when they cannot be found in the database).

    The function zen_address_format already takes both of these scenarios into account. If one includes the "country_id" and "zone_id" in the address, it will display the "state abbr" (zone_code) instead of the full "state" (state name). If one does not include these, the passed "country" and "state" are displayed as-is.

    Code Follows
    I've had the need to check / validate / lookup both country and zone information in the past (largely for Admin New Orders and Edit Orders). The following changes should effectively alter the display of your invoices without affecting any other pages or altering the data stored in the database (so should not impact any other Zen Cart code or 3rd party modules).

    First we need to create a function to "search" for the country_id and zone_id. When found the function should add them to the address. For example one could add the following function (in "/admin/includes/functions/extra_functions/use_state_abbr.php"):
    Code:
      function add_zone_info_to_address($address) {
        global $db;
    
        $query = 'SELECT `countries_id` FROM `' . TABLE_COUNTRIES . '` ';
    
        if(strlen($address['country']) == 2) $query .= 'WHERE `countries_iso_code_2`= \'' . $db->prepare_input($address['country']) . '\'';
        else if(strlen($address['country']) == 3) $query .= 'WHERE `countries_iso_code_3`=\'' . $db->prepare_input($address['country']) . '\'';
        else $query .= 'WHERE `countries_name`=\'' . $db->prepare_input($address['country']) . '\'';
    
        $query = $db->Execute($query . ' LIMIT 1');
        if(!$query->EOF) {
          $address['country_id'] = $query->fields['countries_id'];
    
          $query = $db->Execute(
            'SELECT `zone_id` FROM `' . TABLE_ZONES . '` ' .
            'WHERE `zone_country_id`=\'' . $address['country_id'] .
            '\' AND (`zone_code`=\'' . $db->prepare_input($address['state']) .
            '\' OR `zone_name`=\''. $db->prepare_input($address['state']) . '\') LIMIT 1'
          );
          if(!$query->EOF) {
            $address['zone_id'] = $query->fields['zone_id'];
          }
        }
        return $address;
      }
    Second when sending the address to zen_address_format, we need to wrap the address with the new function. In the stock ZC 1.5.1 copy of "/admin/invoice.php" these are on line 91, 100, and 117. For example on line 91:
    Code:
            <td class="main"><?php echo zen_address_format($order->customer['format_id'], add_zone_info_to_address($order->customer), 1, '', '<br>'); ?></td>
    This should produce the desired result with the least number of changes to core Zen Cart files :)
    Last edited by lhungil; 22 Nov 2013 at 08:21 AM.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  9. #9
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Replace states name with state abbreviation on admin orders

    Quote Originally Posted by firebug View Post
    No I need the States abbreviation to show instead of the whole spelled out States name when I print the customer invoice from the Zen Cart admin. In the ZC admin when you go to Customer>Orders and click on an order the customers address information shows the spelled out States name like this

    JOHN DOE
    123 ANY ST
    ANYTOWN, Florida 34238

    And I need it to be like this when I print the invoices.

    JOHN DOE
    123 ANY ST
    ANYTOWN, FL 34238
    Don't know where you are at with this problem; however, I just completed some research to try to help someone that was looking for a related address presentation issue. Their's was for an international address; however, I found that a similar solution may help without all sorts of coding as provided "above"... Get this, check the address format for United States: This would be found in the Locations/Taxes drop down of the admin panel. Then choose countries. Change to page 10. Look at the address format for United States. It probably is set to a value of 1.... This value assigns a display address with the state fully spelt. What you want is the two letter abbreviation... Change the address format to 2... This should provide an address format that has the two letter abbreviation for the state. It may be further helpful to require states to be a dropdown (as I am not sure what database lookup is performed when the state is manually typed in versus lookup from the table(s).)

    If existing entries are not automatically changed to the two letter abbreviation, and there is a need to change the records, I would suggest adding a new entry with the above settings, see the differences, track down the applicable information for the change outs, then update the database through your favorite method to change all of the entered addresses desired to be modified...

    Can't believe that it is/would be that easy, but there ya' go... (That said, I'm not sure how my database got populated with countries and states, if by initial installation or upload of some other data, but it does have information related to all of that.) Or upon rereading ihungil's response, I could be completely wrong regarding the order data, but possibly correct as far as the user's data...
    Last edited by mc12345678; 27 Nov 2013 at 07:45 PM.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v139h Incorrect state abbreviation being passed to ???
    By JeffLC in forum Built-in Shipping and Payment Modules
    Replies: 5
    Last Post: 12 Feb 2015, 03:03 PM
  2. How To Replace Store Name with Logo?
    By kenix in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 23 Apr 2009, 05:55 PM
  3. Replies: 7
    Last Post: 24 Nov 2008, 04:25 AM
  4. How to replace category/product name with image?
    By Rotkale in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 19 Dec 2006, 03:59 PM
  5. replace product name text with images - possible??
    By Matt Noiseux in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 11 Oct 2006, 06:48 AM

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