Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default adding full name of logged in user

    1.5.7b

    I am using this snip for the logged in user
    PHP Code:
    <?php echo $_SESSION['customer_first_name']?>
    instead of
    PHP Code:
    <?php echo HEADER_TITLE_LOGOFF?>
    and it works.

    I have two questions:
    1 - is this correct, and enough for the version in use?
    2 - how would I add the lastname as well?
    I tried vaious combinations, but all turned out wrong

    Thank you

  2. #2
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,221
    Plugin Contributions
    1

    Default Re: adding full name of logged in user

    Quote Originally Posted by keneso View Post
    1.5.7b

    I am using this snip for the logged in user
    PHP Code:
    <?php echo $_SESSION['customer_first_name']?>
    instead of
    PHP Code:
    <?php echo HEADER_TITLE_LOGOFF?>
    and it works.

    I have two questions:
    1 - is this correct, and enough for the version in use?
    2 - how would I add the lastname as well?
    I tried vaious combinations, but all turned out wrong

    Thank you
    1 - not sure

    2 - this works for me:

    Code:
    <?php echo $_SESSION['customer_first_name'] . ' ' . $_SESSION['customer_last_name'];?>
    I borrowed the code from includes/init_includes/init_customer_auth.php
    Simon

  3. #3
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: adding full name of logged in user

    Thank you.

    Well, since it is like that in the mentinoed file I'd guess it is ok.

  4. #4
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,221
    Plugin Contributions
    1

    Default Re: adding full name of logged in user

    The actual code was:

    Code:
    $shopping_for_name = $_SESSION['customer_first_name'] . ' ' . $_SESSION['customer_last_name'];
    not 'echoed' but I too would think it's ok.
    Simon

  5. #5
    Join Date
    Jul 2012
    Posts
    16,719
    Plugin Contributions
    17

    Default Re: adding full name of logged in user

    Problem that may occur is if that session data is "collected" while it doesn't yet exist and some other conditions exist.

    Considering this text is "replacing" the log-off text, which would probably be expected only when an individual is already logged in it probably is a non-issue. In more recent php versions and/or where strict operation is expected, trying to use an array variable that isn't set or defined will generate some sort of debug log type message.

    One might ask, why was the language define not modified to capture that logic instead of changing the template file? Does clicking on the users name still log the user off? Do they have a way to logoff and restrict access to their personal info other than manually typing the address to do so?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: adding full name of logged in user

    Thank you.
    I knew there was more to it, thus I asked.

    So in order to better understand:

    Would you think what you describe, or part of it, applies to the following setup as well?

    PHP Code:
    <?php if (zen_is_logged_in() && !zen_in_guest_checkout()) { ?>
    <li class="dropdown"><a class="fz-logged-on" href="#"><i class="fas fa-user"></i> <?php echo $_SESSION['customer_first_name'] . ' ' $_SESSION['customer_last_name'];?></a>
                <ul class="sub">
          <li>
            <a class="nav-link" href="<?php echo zen_href_link(FILENAME_ACCOUNT'''SSL'); ?>"><?php echo HEADER_TITLE_MY_ACCOUNT?></a>
          </li>
          <li class="fz-logoff">
            <a class="nav-link fz-login-button" href="<?php echo zen_href_link(FILENAME_LOGOFF'''SSL'); ?>"><?php echo HEADER_TITLE_LOGOFF?></a>
          </li>
          
          </ul>
          </li>
    <?php
          
    } else {
            if (
    STORE_STATUS == '0') {
    ?>
    One might ask, why was the language define not modified to capture that logic instead of changing the template file? Does clicking on the users name still log the user off? Do they have a way to logoff and restrict access to their personal info other than manually typing the address to do so?
    If the question is directed at me, the answer is: not being a coder it didn't even cross my mind I could use language files, and even if it did I wouldn't know how. ;)

    On my local test no log files generated, and by clicking on user name nothing happens, save showing the actual logoff, and my account links.

  7. #7
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,541
    Plugin Contributions
    19

    Default Re: adding full name of logged in user

    This looks good to me, but what do I know...

    And, personally, I prefer modifying the template files for such purposes - user name is not related to a language, so why would one want to include it in a language file? It's not like it's gonna say "Hello, John" in English, and "Willkommen, Maria" for the same user in different languages... When echoing some session variables that are common for all languages, I find it better to modify the template files (one file) instead of modifying one file for each language used.

    BTW, I'd prefer seeing ONLY my first name in the header - imagine riding a train to work and doing some last minute shopping on your laptop, and the person next to you peeking at your screen to see your first AND last name after you just added a realistic extra-large dragon d.i.l.d.o. to your cart... Just kidding, of course, but I'd still go with first name only.

  8. #8
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: adding full name of logged in user

    Quote Originally Posted by balihr View Post
    BTW, I'd prefer seeing ONLY my first name in the header - imagine riding a train to work and doing some last minute shopping on your laptop, and the person next to you peeking at your screen to see your first AND last name after you just added a realistic extra-large dragon d.i.l.d.o. to your cart... Just kidding, of course, but I'd still go with first name only.
    Darn, now I have to think of a conditional to hide last name based on the item in user's cart ... nah ... too much work even if I knew what I was doing ... would you do it for me?

    Seriously, good point about the last name, I'll remove it, at least I learned something in the process.

  9. #9
    Join Date
    Dec 2007
    Location
    Payson, AZ
    Posts
    1,076
    Plugin Contributions
    15

    Default Re: adding full name of logged in user

    Quote Originally Posted by keneso View Post
    Darn, now I have to think of a conditional to hide last name based on the item in user's cart ... nah ... too much work even if I knew what I was doing ... would you do it for me?

    Seriously, good point about the last name, I'll remove it, at least I learned something in the process.
    Even the top eCommerce site only uses the first name! And... it's not just replacing the logoff word with a name!
    You have to take in account what your template is.. can it display a list box/page with the account links! for mine it was easy to do a hover drop down with the logoff and account links.. The template I use was designed with a hover drop down so converting it was simple. Got a little more polishing to do before I upload it.
    Name:  logoff_pannel.png
Views: 287
Size:  53.9 KB
    Dave
    Always forward thinking... Lost my mind!

  10. #10
    Join Date
    Jul 2012
    Posts
    16,719
    Plugin Contributions
    17

    Default Re: adding full name of logged in user

    Quote Originally Posted by balihr View Post
    This looks good to me, but what do I know...

    And, personally, I prefer modifying the template files for such purposes - user name is not related to a language, so why would one want to include it in a language file? It's not like it's gonna say "Hello, John" in English, and "Willkommen, Maria" for the same user in different languages... When echoing some session variables that are common for all languages, I find it better to modify the template files (one file) instead of modifying one file for each language used.

    BTW, I'd prefer seeing ONLY my first name in the header
    Quote Originally Posted by keneso View Post
    Seriously, good point about the last name, I'll remove it, at least I learned something in the process.
    True that isn't necessarily a language dependent object; however, templates tend to use/reuse the same define in multiple places. For example the define in question: HEADER_TITLE_LOGOFF is used or can be used in more than one template file for a given active template. For example the responsive_classic template: includes/templates/responsive_classic/templates/tpl_modules_mobile_menu.php and includes/templates/responsive_classic/common/tpl_header.php

    As for handling the situation identified by balihr (no hope on the product of choice), associated (rhetorical) code is within the same file (at least in the responsive_classic version) though it only identifies the presence of any content, not a specific item as might be of concern. :) (https://github.com/zencart/zencart/b....php#L64-L68):
    Code:
    <?php if ($_SESSION['cart']->count_contents() != 0) { ?>    <li><a href="<?php echo zen_href_link(FILENAME_ACCOUNT, '', 'SSL'); ?>"><i class="fa fa-user" title="My Account"></i></a></li>
    <?php } else { ?>
        <li class="last"><a href="<?php echo zen_href_link(FILENAME_ACCOUNT, '', 'SSL'); ?>"><i class="fa fa-user" title="My Account"></i></a></li>
    <?php } ?>
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 22 Mar 2013, 03:21 PM
  2. display user name in nav bar once logged in
    By Sushigal in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 7 Jul 2010, 11:02 AM
  3. Logged user
    By Sharkishadow in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 13 Nov 2009, 12:26 AM
  4. Adding the user's name to a sidebox
    By FrankDeRosa in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 4 May 2009, 05:43 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