Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Sep 2006
    Posts
    30
    Plugin Contributions
    0

    Default php code for "if logged in" vs "if not logged in"

    the canada post shipping module doesn't work with the shipping estimator unless the customer is logged in. there's been a number of threads trying to fix this problem, but no luck.

    as it is now, a not-logged-in customer who clicks the "estimate shipping" button on the shopping cart page on my site will get the little pop-up window to come up, but it won't work at all.

    so i want to prevent not-logged-in customers from seeing the "estimate shipping" button in the first place.

    in fact, what i'd like to do is put a different button or message in the same place, saying "please login to estimate shipping costs". that would link to the login page.

    so what i need is a php command with the following logic:
    (1) if login=true, then display "estimate shipping" button
    (2) if login=false, then display "login for shipping" button

    obviously i'll have to define BUTTON_IMAGE_LOGIN_FOR_SHIPPING_ESTIMATOR at some point. that's no problem. i just need help with how to code the if/else statement for logged in status.

    the relevant code is in templates/tpl_shopping_cart_default.php :

    Code:
    <?php
        switch (true) {
          case (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1'):
    ?>
    
    <div class="forward"><?php echo '<a href="javascript:popupWindow(\'' . zen_href_link(FILENAME_POPUP_SHIPPING_ESTIMATOR) . '\')">' .
     zen_image_button(BUTTON_IMAGE_SHIPPING_ESTIMATOR, BUTTON_SHIPPING_ESTIMATOR_ALT) . '</a>'; ?></div>
    
    <?php
          break;
          case (SHOW_SHIPPING_ESTIMATOR_BUTTON == '2'):
    /**
     * load the shipping estimator code if needed
     */
    ?>
          <?php require(DIR_WS_MODULES . zen_get_module_directory('shipping_estimator.php')); ?>
    the code is a bit more complicated than it would be because of the switch in admin-->configuration-->shipping which lets you decide whether to display a shipping estimator button (for the popup) or just the actual estimate on the same page. i'm planning to use a button, meaning

    Code:
    case (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1'):
    but i guess the proper way to code this would be to embed the switch (case 1 vs case 2) within the (if login vs if not-login) statement. that way logged in customers would see either the button or the shipping estimate, depending on how the switch is set, and not-logged in customers wouldn't see it either way.

    hope that makes sense...

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

    Default Re: php code for "if logged in" vs "if not logged in"

    When this is defined: $_SESSION['customer_id']

    Then the customer is logged in ...
    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
    Sep 2006
    Posts
    30
    Plugin Contributions
    0

    Default Re: php code for "if logged in" vs "if not logged in"

    hurrah! it works...

    in templates/tpl_shopping_cart.php the code above now reads:

    Code:
    <?php if ($_SESSION['customer_id']) { ?>
    
    <?php
        switch (true) {
          case (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1'):
    ?>
    
    <div class="forward"><?php echo '<a href="javascript:popupWindow(\'' . zen_href_link(FILENAME_POPUP_SHIPPING_ESTIMATOR) . '\')">' .
     zen_image_button(BUTTON_IMAGE_SHIPPING_ESTIMATOR, BUTTON_SHIPPING_ESTIMATOR_ALT) . '</a>'; ?></div>
    
    <?php
          break;
          case (SHOW_SHIPPING_ESTIMATOR_BUTTON == '2'):
    /**
     * load the shipping estimator code if needed
     */
    ?>
          <?php require(DIR_WS_MODULES . zen_get_module_directory('shipping_estimator.php')); ?>
    
    <?php
            break;
          }
    ?>
    <?php 
     } else {
     ?>
     <div class="forward"><a href="<?php echo zen_href_link(FILENAME_LOGIN, '', 'SSL'); ?>"><?php echo LOGIN_FOR_SHIPPING_ESTIMATOR; ?></a></div>
     
    <?php
                 }
    ?>
    i decided to use text instead of a button, since the phrase is too long. so i added this line to english.php

    Code:
    define('LOGIN_FOR_SHIPPING_ESTIMATOR', 'Please login for shipping estimate');
    and it works! thanks for the help.

  4. #4
    Join Date
    Feb 2008
    Location
    Southern California
    Posts
    142
    Plugin Contributions
    0

    Default Re: php code for "if logged in" vs "if not logged in"

    Dear Ajeh,

    What is the php syntax for "if not logged in" ?

    Thank you for your response in advance.

    I tried <?php if ($messageStack->size('login') > 0) { ?> but it didn't work. I'm just trying anything I can find at the moment.

    Is there such a thing without using "else"?
    Last edited by saitomedia; 13 Aug 2008 at 08:55 AM.

  5. #5
    Join Date
    Feb 2008
    Location
    Southern California
    Posts
    142
    Plugin Contributions
    0

    Default Re: php code for "if logged in" vs "if not logged in"

    while passing the cart information to index.php?main_page=create_account

    I hope I'm making sense.
    Last edited by saitomedia; 13 Aug 2008 at 09:14 AM.

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

    Default Re: php code for "if logged in" vs "if not logged in"

    Same as what I posted above ... use the $_SESSION['customer_id'] to determin if the customer is logged in or not ...

    For example, a simple IF can use:
    PHP Code:
    <?php
      
    if ($_SESSION['customer_id']  > 0) {
    // I am logged in
      
    } else {
    // I am not logged in
      
    }
    ?>
    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!

  7. #7
    Join Date
    Feb 2008
    Location
    Southern California
    Posts
    142
    Plugin Contributions
    0

    Default Re: php code for "if logged in" vs "if not logged in"

    Thank you Ajeh!

    By the way, here's the cart that I'm working on:

    http://www.scienscope-products.com/

    Hope you like this one, as it took me roughly 4 months to complete.

    Nori

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

    Default Re: php code for "if logged in" vs "if not logged in"

    That is a very sharp looking ...

    Too bad there isn't a nice link back to Zen Cart in the footer ...

    Good luck with your site!
    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!

  9. #9
    Join Date
    Feb 2008
    Location
    Southern California
    Posts
    142
    Plugin Contributions
    0

    Default Re: php code for "if logged in" vs "if not logged in"

    My apology ,

    I will put the zen cart link back. I don't know why I removed it before, it must be because I was learning how to modify the line.

    Thanks for your great comment Ajah

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

    Default Re: php code for "if logged in" vs "if not logged in"

    Thanks for making Zen Cart look so nice ... and for letting the world know about it too!
    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!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 4 Dec 2015, 11:46 PM
  2. Replies: 9
    Last Post: 8 Oct 2012, 05:16 PM
  3. Replies: 18
    Last Post: 29 Sep 2009, 02:37 PM
  4. Remove "Newsletters" link when logged into "My Account" (not in Admin?)
    By hedron in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 17 Sep 2009, 10:44 PM
  5. How to Change "Redemption Code" to "Coupon Code" & "GV Code"
    By dmfelder in forum Basic Configuration
    Replies: 5
    Last Post: 16 Apr 2008, 05:50 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