Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,023
    Plugin Contributions
    32

    Default PHP Fatal error: Call to a member function count_contents() on a non-object

    I am seeing this error, and I cannot figure out WHY.. After spending hours trying to replicate what sequence of steps cause this error, I still can't seem to replicate the exact action(s) that triggers the error..
    Code:
    [26-Sep-2013 00:27:20] PHP Fatal error:  Call to a member function  count_contents() on a non-object in  /home2/myhost/public_html/shop/includes/templates/custom_template/common/tpl_main_page.php  on line 96
    This is line 96:
    Code:
      <li><img src="<?php echo ZEN_DIR_WS_TEMPLATE_IMAGES . 'icons/cart.png'; ?>" alt="cart icon" class="cart-icon"  /><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>"><?php echo $_SESSION['cart']->count_contents();?> item(s) - <?php echo $currencies->format($_SESSION['cart']->show_total());?></a> | </li>
    What's really odd is this site is pretty identical to another site I'm working on, and this error doesn't occur at ALL.. Need a little expert help tracking this down..
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

  2. #2
    Join Date
    Feb 2010
    Location
    Syracuse, NY
    Posts
    2,159
    Plugin Contributions
    17

    Default Re: PHP Fatal error

    Quote Originally Posted by DivaVocals View Post
    I am seeing this error, and I cannot figure out WHY.. After spending hours trying to replicate what sequence of steps cause this error, I still can't seem to replicate the exact action(s) that triggers the error..
    Code:
    [26-Sep-2013 00:27:20] PHP Fatal error:  Call to a member function   count_contents() on a non-object in   /home2/myhost/public_html/shop/includes/templates/custom_template/common/tpl_main_page.php   on line 96
    This is line 96:
    Code:
      <li><img src="<?php echo ZEN_DIR_WS_TEMPLATE_IMAGES .  'icons/cart.png'; ?>" alt="cart icon" class="cart-icon"  /><a  href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL');  ?>"><?php echo $_SESSION['cart']->count_contents();?> item(s) - <?php echo $currencies->format($_SESSION['cart']->show_total());?></a> | </li>
    What's really odd is this site is pretty identical to another site I'm working on, and this error doesn't occur at ALL.. Need a little expert help tracking this down..

    try:

    <?php $showCartTotals = $currencies->format($_SESSION['cart']->show_total());?><?php echo $showCartTotals;?>

    -> May be wrong though.
    -> May also break something else as well.
    Website - Github. Like the ZCA Bootstrap 4 Template? Donations Welcome. Bootstrap Plugins?

  3. #3
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: PHP Fatal error

    Quote Originally Posted by rbarbour View Post
    try:

    <?php $showCartTotals = $currencies->format($_SESSION['cart']->show_total());?><?php echo $showCartTotals;?>

    -> May be wrong though.
    I think that suggestion is wrong ... because the error is about count_contents() not show_total()
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: PHP Fatal error: Call to a member function count_contents() on a non-object

    Quote Originally Posted by DivaVocals View Post
    I am seeing this error
    *where* are you seeing it?

    Quote Originally Posted by DivaVocals View Post
    Code:
    [26-Sep-2013 00:27:20] PHP Fatal error:  Call to a member function  count_contents() on a non-object in  /home2/myhost/public_html/shop/includes/templates/custom_template/common/tpl_main_page.php  on line 96
    This is line 96:
    Code:
      ...<?php echo $_SESSION['cart']->count_contents();?> ...
    In this case the "object" it's referring to is $_SESSION['cart'] and the function it's referring to is count_contents(), which would be found inside whatever class the $_SESSION['cart'] was instantiated from. But if there is no session started when that particular line of code is executed, then the object won't exist and thus the member function it's trying to call can never be found let alone called.

    I'm guessing you've added code to display cart contents on every page of the site, for every visitor, but haven't accommodated the fact that spiders don't get sessions started for them, and thus you can't output that information.

    Better would be to set another variable (blank unless the session is started, ie: $_SESSION['customers_id'] > 0 or $_SESSION['cart'] exists) long before the template fires, and echo that variable in the template. Separate your logic from the display.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Feb 2010
    Location
    Syracuse, NY
    Posts
    2,159
    Plugin Contributions
    17

    Default Re: PHP Fatal error: Call to a member function count_contents() on a non-object

    Quote Originally Posted by rbarbour View Post

    -> May be wrong though.
    -> May also break something else as well.
    Quote Originally Posted by DrByte View Post
    I think that suggestion is wrong ... because the error is about count_contents() not show_total()
    Quote Originally Posted by DrByte View Post
    *where* are you seeing it?


    In this case the "object" it's referring to is $_SESSION['cart'] and the function it's referring to is count_contents(), which would be found inside whatever class the $_SESSION['cart'] was instantiated from. But if there is no session started when that particular line of code is executed, then the object won't exist and thus the member function it's trying to call can never be found let alone called.

    I'm guessing you've added code to display cart contents on every page of the site, for every visitor, but haven't accommodated the fact that spiders don't get sessions started for them, and thus you can't output that information.

    Better would be to set another variable (blank unless the session is started, ie: $_SESSION['customers_id'] > 0 or $_SESSION['cart'] exists) long before the template fires, and echo that variable in the template. Separate your logic from the display.
    Makes sense, never thought to ask if the $_SESSION was started. LOL

    That is why you are the DR.
    Website - Github. Like the ZCA Bootstrap 4 Template? Donations Welcome. Bootstrap Plugins?

  6. #6
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,023
    Plugin Contributions
    32

    Default Re: PHP Fatal error: Call to a member function count_contents() on a non-object

    Quote Originally Posted by DrByte View Post
    *where* are you seeing it?
    My shop and blog error logs.. Interestingly initially they ONLY showed up in my WordPress error log, but NOT the Zen Cart error log.. When I turned off the WordPress error logging, then these errors began appearing in the Zen Cart error logs.. **shrugs**


    Quote Originally Posted by DrByte View Post
    In this case the "object" it's referring to is $_SESSION['cart'] and the function it's referring to is count_contents(), which would be found inside whatever class the $_SESSION['cart'] was instantiated from. But if there is no session started when that particular line of code is executed, then the object won't exist and thus the member function it's trying to call can never be found let alone called.

    I'm guessing you've added code to display cart contents on every page of the site, for every visitor, but haven't accommodated the fact that spiders don't get sessions started for them, and thus you can't output that information.

    Better would be to set another variable (blank unless the session is started, ie: $_SESSION['customers_id'] > 0 or $_SESSION['cart'] exists) long before the template fires, and echo that variable in the template. Separate your logic from the display.
    You are right I do have code to display the cart contents on every page, and now that you've explained WHY this happens, I think I know what I did wrong..

    My cart code appears below this block in includes/templates/custom_template/common/tpl_main_page.php:
    Code:
    <?php
     /**
      * prepares and displays header output
      *
      */
      if (CUSTOMERS_APPROVAL_AUTHORIZATION == 1 && CUSTOMERS_AUTHORIZATION_HEADER_OFF == 'true' and ($_SESSION['customers_authorization'] != 0 or $_SESSION['customer_id'] == '')) {
        $flag_disable_header = true;
      }
      require($template->get_template_dir('tpl_header.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_header.php');?>
    If I understand the issue, I believe that moving my cart code to the tpl_header.php file will solve my issue.. This might explain why I never had this issue "before" with this code.. I never placed this code in the tpl_main_page.php file "before".. This is what my husband would refer to as a "learning fall".. I call it just being a bonehead..

    Thanks Doc for the assist..

    **does the walk of shame out the thread**
    Last edited by DivaVocals; 26 Sep 2013 at 05:30 PM.
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

  7. #7
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,023
    Plugin Contributions
    32

    Default Re: PHP Fatal error: Call to a member function count_contents() on a non-object

    Well that didn't do it.. Same error..

    Code:
    PHP Fatal error:  Call to a member function count_contents() on a  non-object in  /home2/mysite/public_html/shop/includes/templates/custom_template/common/tpl_header.php  on line 99

    Here's the full cart code section (the offending line is highlighted)
    Code:
    <div id="navMain">
        <ul class="back">
       <?php if (($_SESSION['customer_id']) && (!$_SESSION['COWOA']=='True')) { ?>
       <li><a href="<?php echo zen_href_link(FILENAME_LOGOFF, '', 'SSL'); ?>"><?php echo HEADER_TITLE_LOGOFF; ?></a> | </li>
       <li><a href="<?php echo zen_href_link(FILENAME_ACCOUNT, '', 'SSL'); ?>"><?php echo HEADER_TITLE_MY_ACCOUNT; ?></a> | </li>
    <?php
      } else {
       if (STORE_STATUS == '0') {
    ?>
         <li><a href="<?php echo zen_href_link(FILENAME_LOGIN, '', 'SSL'); ?>"><?php echo HEADER_TITLE_LOGIN; ?></a> | </li>
        <?php } } ?>
      <li><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>"><img src="<?php echo $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images').'/' . 'icons/cart.png'; ?>" alt="cart icon" class="cart-icon"  /><?php echo $_SESSION['cart']->count_contents();?>  item(s)  - <?php echo $currencies->format($_SESSION['cart']->show_total());?></a> | </li>
        <li><a href="<?php echo zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>"><?php echo HEADER_TITLE_CHECKOUT; ?></a></li>
        <?php if ($_SESSION['cart']->count_contents() != 0) { ?>
       <?php }?>
    </ul>
    </div>

    Normally this code is just before this section:
    Code:
    <!--bof-branding display-->
    <div id="logoWrapper">
        <div id="logo"><?php echo '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . '">' . zen_image($template->get_template_dir(HEADER_LOGO_IMAGE, DIR_WS_TEMPLATE, $current_page_base,'images'). '/' . HEADER_LOGO_IMAGE, HEADER_ALT_TEXT) . '</a>'; ?></div>
    <?php if (HEADER_SALES_TEXT != '' || (SHOW_BANNERS_GROUP_SET2 != '' && $banner = zen_banner_exists('dynamic', SHOW_BANNERS_GROUP_SET2))) { ?>
        <div id="taglineWrapper">
    <?php
                  if (HEADER_SALES_TEXT != '') {
    ?>
          <div id="tagline"><?php echo HEADER_SALES_TEXT;?></div>
    <?php
                  }
    ?>
    <?php
                  if (SHOW_BANNERS_GROUP_SET2 != '' && $banner = zen_banner_exists('dynamic', SHOW_BANNERS_GROUP_SET2)) {
                    if ($banner->RecordCount() > 0) {
    ?>
          <div id="bannerTwo" class="banners"><?php echo zen_display_banner('static', $banner);?></div>
    <?php
                    }
                  }
    ?>
        </div>
    <?php } // no HEADER_SALES_TEXT or SHOW_BANNERS_GROUP_SET2 ?>
    </div>
    <br class="clearBoth" />
    <!--eof-branding display-->
    I moved the cart code to just below this section.
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

  8. #8
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: PHP Fatal error: Call to a member function count_contents() on a non-object

    Moving it from tpl_main_page to tpl_header won't address the fact that the non-existent $_SESSION['cart'] is your problem.

    You didn't say how you trigger the error.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,023
    Plugin Contributions
    32

    Default Re: PHP Fatal error: Call to a member function count_contents() on a non-object

    Quote Originally Posted by DrByte View Post
    Moving it from tpl_main_page to tpl_header won't address the fact that the non-existent $_SESSION['cart'] is your problem.

    You didn't say how you trigger the error.
    That's the problem.. I really don't know how/when the error is triggered.. I spent the better part of the last two days doing controlled tests to try and "make" this error happen, and I can't figure out exactly what action is triggering the error..
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

  10. #10
    Join Date
    Feb 2010
    Location
    Syracuse, NY
    Posts
    2,159
    Plugin Contributions
    17

    Default Re: PHP Fatal error: Call to a member function count_contents() on a non-object

    Quote Originally Posted by DivaVocals View Post
    That's the problem.. I really don't know how/when the error is triggered.. I spent the better part of the last two days doing controlled tests to try and "make" this error happen, and I can't figure out exactly what action is triggering the error..
    I hate to offer suggestions at this point because lately I have been way off, can't seem to focus.

    Maybe the issue has something to do with the changes made to the file you altered in this thread? If it is the same site in question?

    http://www.zen-cart.com/showthread.p...Estimator-runs
    Website - Github. Like the ZCA Bootstrap 4 Template? Donations Welcome. Bootstrap Plugins?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 8 May 2016, 03:44 PM
  2. v139h PHP Fatal error: Call to a member function add_session() on a non-object
    By absoluteblock in forum General Questions
    Replies: 5
    Last Post: 27 Apr 2013, 01:23 AM
  3. Replies: 5
    Last Post: 31 Jul 2012, 11:33 AM
  4. Replies: 6
    Last Post: 4 Jun 2007, 11:42 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