Zen Cart Logo
Forums / General Questions / Fatal error when calling count_contents in checkout

Fatal error when calling count_contents in checkout

Locked

Views: 4,559

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
13 Nov 2007, 2:59 AM
#1
rbobzin avatar

rbobzin

Zen Follower

Join Date:
Mar 2007
Posts:
112
Plugin Contributions:
0

Fatal error when calling count_contents in checkout

I just looked into a site's error log and noticed the following error has been occurring since the site went "live" in July:

"Call to a member function count_contents() on a non-object in /xxxxxxxx/includes/modules/sideboxes/shopping_cart.php on line 24"

The lines from shopping_cart.php the error refers to are:

case (SHOW_SHOPPING_CART_BOX_STATUS == '2'):
      if ( ( ($_SESSION['cart']->count_contents() > 0) || (isset($_SESSION['customer_id']) && zen_user_has_gv_account($_SESSION['customer_id']) > 0) ) && ($_GET['main_page'] != FILENAME_SHOPPING_CART) ) {
        $show_shopping_cart_box = true;
      } else {
        $show_shopping_cart_box = false;
      }
      break;
```Does anyone know what this means? Did the user see a "fatal error" message? Did the user's order go into the basket instead of being processed? Is there something I can do to prevent this?

I did a search on "count_contents", but didn't find anything useful. If anyone can steer me in the right direction on this, I would really appreciate it. Thanks!
13 Nov 2007, 4:56 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Fatal error when calling count_contents in checkout

What addons/contributions do you have installed?
What sorts of customizations have you made to your site?
Can you trigger the error by doing a test purchase? What do you see on-screen when the error shows up in the logs while you're shopping?

13 Nov 2007, 6:23 AM
#3
rbobzin avatar

rbobzin

Zen Follower

Join Date:
Mar 2007
Posts:
112
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

Hi Doc,

Quite frankly, the client and I thought the site was running just fine. We did a lot of pretty intensive testing before going "live" and never encountered a fatal error. When the site went live, we had some problems with orders getting processed (approved) by Authorize.net but then going into the basket instead of completing. Talking with you and others about this led us to install the External Order ID Generator mod, and another fix you did to get around the apostrophe in the name problem. But no one reported, and we never saw, any fatal errors. The first time I saw it was when I looked at the error log today, and it showed the error had been occurring pretty regularly since July 29!

Mods we've installed include:

Add Custs from Admin
Admin Profiles
Capitalize Signup Fields
Captcha
Email Address Exporter
Email Archive Manager
Export Shipping Info
External Order ID Generator
Super Orders

I didn't do a lot of coding customization - don't know php well enough for that. Since I just discovered the existance of the error, I'll start testing on my local site to see if I can reproduce.

I have to admit that this is very discouraging as we all thought the site was doing great. Can I assume that thie error would have stopped the user from continuing whatever they were doing - that would be depressing!

13 Nov 2007, 7:33 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Fatal error when calling count_contents in checkout

rbobzin:

Can I assume that thie error would have stopped the user from continuing whatever they were doingMaybe. Maybe not.
Usually a fatal error will abort subsequent page processing. If your shopping-cart sidebox is on the right-hand column, then it's possible that the rest of the side boxes on the page just simply didn't get drawn, and no error message was shown.

The only reason why that error should appear is if there is no shopping cart object set ... and the only reason for $_SESSION['cart'] to not be set is if something has specifically unset() it, since that object is created before any page-specific processing ever starts. Hence the question about addons/contributions/customizations.

13 Nov 2007, 6:16 PM
#5
rbobzin avatar

rbobzin

Zen Follower

Join Date:
Mar 2007
Posts:
112
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

The cart is indeed the last box in the right column, so maybe customers didn't see the error code, but what coulde have unset the cart in the first place? I'm not sure any of the add-on modules would have any effect on that, except possibly the External Order ID Generator - but that mod fixed a major problem, so I'm really hoping that's not it.

I did a search for files with $_SESSION['cart'] in them to see if there might be any that I remember editing, and there are a couple that look a bit familiar, so will now compare them with the originals. (Although I'm not sure I'll know what to do after that!)

In the meantime, the error keeps on happening - according to the error log, 7 times today already.

[13-Nov-2007 02:04:02]
[13-Nov-2007 02:41:14]
[13-Nov-2007 03:58:58]
[13-Nov-2007 07:16:33]
[13-Nov-2007 07:18:05]
[13-Nov-2007 08:52:02]
[13-Nov-2007 09:05:06]

And that also looks a little weird - 95% of the site's users are college students, and these times seem a little too early in the morning to me. Is there any way I can record users sessions, try to match sessions with errors, then contact the users to find out what happened?

This thing really has me bugged, so I much appreciate your help!

13 Nov 2007, 7:16 PM
#6
rbobzin avatar

rbobzin

Zen Follower

Join Date:
Mar 2007
Posts:
112
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

OK, just compared all the files with $_SESSION['cart'] in them, and all were identical except these 3:

**includes/classes/order.php - **3 changes made by External Order ID Generator

**includes/modules/qps/create_account.php -** 2 changes re: anti-robot registration (I think this was a Dr. Byte fix?)

includes/templates/qps/common/tpl_header.php - I moved the navMainWrapper div to the bottom of the page (based on reading how to do that in one of the forums)

So, unless I screwed up in the tpl_header.php file, I don't think any customizations are at fault. Now what?

13 Nov 2007, 7:23 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Fatal error when calling count_contents in checkout

rbobzin:

The cart is indeed the last box in the right column, so maybe customers didn't see the error codeDo you always see the shopping-cart sidebox? It only appears if there is something in the cart.

Oh, and if the drawing of the right column dies due to an error, the site footer won't show either.

14 Nov 2007, 4:28 AM
#8
rbobzin avatar

rbobzin

Zen Follower

Join Date:
Mar 2007
Posts:
112
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

I've tried several times to reproduce the error, but no luck. Everything worked just fine - cart showed up in right column whenever there was something in it, and disapeared when all items were deleted. And, of course, the error log shows no errors during the time I tested it.

Do you think if I install the User Tracking mod, it might give me any useful info?

I've changed the cart box status from 2 to 1 (since that offending line 24 is checking for status=2) to see if that stops the error. If it does, I'm fine for now and will re-visit this problem later. If it doesn't, where else should I be looking?

14 Nov 2007, 1:05 PM
#9
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

Just an idle thought but could the error be generated by search engine spiders? They don't get sessions so $_SESSION['cart']->count_contents() would throw an error for them. Maybe the code should be...

if ( ( (isset($_SESSION['cart']) && ($_SESSION['cart']->count_contents() > 0)) || (isset($_SESSION['customer_id']) && zen_user_has_gv_account($_SESSION['customer_id']) > 0) ) && ($_GET['main_page'] != FILENAME_SHOPPING_CART) ) {
```Just a thought.

Regards,
Christian.
14 Nov 2007, 1:31 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Fatal error when calling count_contents in checkout

Actually, yes, that's a distinct possibility...

Would be good to check your site pages in search engine cache history ... see if the footer is included or not.

14 Nov 2007, 8:34 PM
#11
rbobzin avatar

rbobzin

Zen Follower

Join Date:
Mar 2007
Posts:
112
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

Way to go, Christian!!! :clap:

A quick comparison of the error log with the raw access log showed that every error today (Nov 14) was caused by some "bot". If you're interested, here's the list:

ACCESS LOG - 66.249.66.136 - - [14/Nov/2007:04:41:00 -0600] "GET /index.php?main_page=index&cPath=19 HTTP/1.1" 500 2698 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
ERROR LOG - [14-Nov-2007 04:41:00] PHP Fatal error:  Call to a member function count_contents() on a non-object in /home/qpsmarke/public_html/includes/modules/sideboxes/shopping_cart.php on line 17

ACCESS LOG - 66.249.66.136 - - [14/Nov/2007:06:18:22 -0600] "GET /index.php?main_page=popup_image&pID=159 HTTP/1.1" 200 1395 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
ERROR LOG - [14-Nov-2007 06:18:22] PHP Warning:  ereg_replace() [<a href='function.ereg-replace'>function.ereg-replace</a>]: REG_EMPTY in /home/qpsmarke/public_html/includes/modules/pages/popup_image/header_php.php on line 41

ACCESS LOG - 65.55.210.15 - - [14/Nov/2007:07:59:51 -0600] "GET /index.php?main_page=index&cPath=15 HTTP/1.0" 500 13535 "-" "msnbot/1.0 (+http://search.msn.com/msnbot.htm)"
ERROR LOG - [14-Nov-2007 07:59:52] PHP Fatal error:  Call to a member function count_contents() on a non-object in /home/qpsmarke/public_html/includes/modules/sideboxes/shopping_cart.php on line 17

ACCESS LOG - 66.249.66.136 - - [14/Nov/2007:09:33:44 -0600] "GET /index.php?main_page=popup_image&pID=157 HTTP/1.1" 200 1395 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
ERROR LOG - [14-Nov-2007 09:33:44] PHP Warning:  ereg_replace() [<a href='function.ereg-replace'>function.ereg-replace</a>]: REG_EMPTY in /home/qpsmarke/public_html/includes/modules/pages/popup_image/header_php.php on line 41

ACCESS LOG - 65.55.210.15 - - [14/Nov/2007:09:40:47 -0600] "GET /index.php?main_page=index&cPath=9 HTTP/1.0" 500 12730 "-" "msnbot/1.0 (+http://search.msn.com/msnbot.htm)"
ERROR LOG - [14-Nov-2007 09:40:47] PHP Fatal error:  Call to a member function count_contents() on a non-object in /home/qpsmarke/public_html/includes/modules/sideboxes/shopping_cart.php on line 17

ACCESS LOG - 65.55.210.15 - - [14/Nov/2007:09:45:30 -0600] "GET /index.php?main_page=index&cPath=13 HTTP/1.0" 500 12020 "-" "msnbot/1.0 (+http://search.msn.com/msnbot.htm)"
ERROR LOG - [14-Nov-2007 09:45:30] PHP Fatal error:  Call to a member function count_contents() on a non-object in /home/qpsmarke/public_html/includes/modules/sideboxes/shopping_cart.php on line 17

ACCESS LOG - 66.249.66.136 - - [14/Nov/2007:10:14:58 -0600] "GET /index.php?main_page=index&cPath=13 HTTP/1.1" 500 2653 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
ERROR LOG - [14-Nov-2007 10:14:58] PHP Fatal error:  Call to a member function count_contents() on a non-object in /home/qpsmarke/public_html/includes/modules/sideboxes/shopping_cart.php on line 17
```I'll check other days to verify this, but it seems the bots are the culprits. Now, is there anything I can do to fix this? What would happen if I ignored it?
14 Nov 2007, 10:37 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Fatal error when calling count_contents in checkout

CJPinder's code suggestion should resolve the matter.

16 Nov 2007, 8:24 PM
#13
rbobzin avatar

rbobzin

Zen Follower

Join Date:
Mar 2007
Posts:
112
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

And so it did! Had all sorts of bots stop by at the site today, but no errors.:clap:

Thanks, Doc and Christian, your help is very much appreciated.

16 Nov 2007, 8:30 PM
#14
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: Fatal error when calling count_contents in checkout

rbobzin:

And so it did! Had all sorts of bots stop by at the site today, but no errors.
Cool. :cool:

rbobzin:

Thanks, Doc and Christian, your help is very much appreciated.
Your welcome, glad to help.

Christian.