Jump to content
Sign in to follow this  
1Putts

Call to Member Function a Non-Object - PHP Error?

Recommended Posts

I'm getting the following error when I try to use the order editor contrib and edit an order on a live server which is running PHP 5.2.6:

 

Fatal error: Call to a member function show_total() on a non-object in /osc/includes/modules/shipping/mzmt.php on line 137

 

mzmt.php is a multi-zone, mult-table shipping rate calculator. Line 137 is part of a function that reads as follows:

 

131 function determineTableMethod($geozone_mode) {
132	  global $total_count, $shipping_weight;
133
134	  $this->geozone_mode = $geozone_mode;
135
136	  if ($this->geozone_mode == 'price') {
137		$this->order_total = $_SESSION['cart']->show_total();
138	  } elseif ($this->geozone_mode == 'count') {
139		$this->order_total = $total_count;
140	  } else {
141		$this->order_total = $shipping_weight;
142	  }
143
144	  return true;	
145	}

 

It all works on my local machine where I'm running PHP 4.3.11 so I'm guessing it's a PHP issue. I've looked high and low and I can't find any solutions that will work. Thanks in advance for any ideas you can offer.

Share this post


Link to post
Share on other sites

It's possible that $_SESSION is not providing the cart class. You can verify this by adding the following just before line 137

print 'Session:<pre>';
print_r ($_SESSION);
print '</pre>';

Since this is a shipping module, you should have at least one item in the cart. If that is not shown, that's it.

 

Please post the result.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Try changing the following line ..

 

$this->order_total = $_SESSION['cart']->show_total();

 

To ...

 

$this->order_total = ( (array_key_exists('cart', $_SESSION) && is_object($_SESSION['cart'])) ? $_SESSION['cart']->show_total() : 0 );

Edited by FWR Media

Share this post


Link to post
Share on other sites

Thank you both for your help. Robert, I tried your suggestion first and it appeared to work. That is, I didn't get the same error when I hit "Edit" on the order. But then when I attempted to change a value in the shipping, I received a bunch of errors (which I'll post below).

 

Kymation, your suggestion returns the following...so what exactly am I looking for here?

 

Session:

Array
(
[language] => english
[languages_id] => 1
[selected_box] => customers
[admin] => Array
	(
		[id] => 1
		[username] => admin
	)

)

And Robert, here are the error messages (there's quite a bit):

 

Warning: order_total::include(includes/languages/english/modules/order_total/ot_subtotal.php) [order-total.include]: failed to open stream: No such file or directory in /catalog/admin/order_editor/order_total.php on line 30

Warning: order_total::include(includes/languages/english/modules/order_total/ot_subtotal.php) [order-total.include]: failed to open stream: No such file or directory in /catalog/admin/order_editor/order_total.php on line 30

Warning: order_total::include() [function.include]: Failed opening 'includes/languages/english/modules/order_total/ot_subtotal.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php:/usr/share/pear/') in /catalog/admin/order_editor/order_total.php on line 30

Warning: order_total::include(includes/modules/order_total/ot_subtotal.php) [order-total.include]: failed to open stream: No such file or directory in /catalog/admin/order_editor/order_total.php on line 31

Warning: order_total::include(includes/modules/order_total/ot_subtotal.php) [order-total.include]: failed to open stream: No such file or directory in /catalog/admin/order_editor/order_total.php on line 31

Warning: order_total::include() [function.include]: Failed opening 'includes/modules/order_total/ot_subtotal.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php:/usr/share/pear/') in /catalog/admin/order_editor/order_total.php on line 31

Fatal error: Class 'ot_subtotal' not found in /catalog/admin/order_editor/order_total.php on line 34

 

And here is the relevant function code from the order_total.php file from the order editor:

 

18  class order_total {
19	var $modules;
20
21 // class constructor
22   function order_total() {
23	  global $language;
24
25	  if (defined('MODULE_ORDER_TOTAL_INSTALLED') && tep_not_null(MODULE_ORDER_TOTAL_INSTALLED)) {
26		$this->modules = explode(';', MODULE_ORDER_TOTAL_INSTALLED);
27
28		reset($this->modules);
29		while (list(, $value) = each($this->modules)) {
30		  include(DIR_WS_LANGUAGES . $language . '/modules/order_total/' . $value);
31		  include(DIR_WS_MODULES . 'order_total/' . $value);
32
33		  $class = substr($value, 0, strrpos($value, '.'));
34		  $GLOBALS[$class] = new $class;
35		}
36	  }
37	}

 

Again, thank you both so much for your assistance. I appreciate it very much.

Share this post


Link to post
Share on other sites

Well this looks like you are simply missing certain core files and the modification should not be necessary.

 

e.g. include(includes/languages/english/modules/order_total/ot_subtotal.php

 

Means that ot_subtotal.php is missing in the folder admin/includes/languages/english/modules/order_total/

 

I would take out any file changes then ensure that all the core files are in place.

 

all my modification achieved was to "hide" the first issue which in turn allowed you to see more issues.

Edited by FWR Media

Share this post


Link to post
Share on other sites

ADDENDUM for Kymation:

 

Here is what is returned...for some reason I didn't get all this the first time around:

Session:

Array
(
[language] => english
[languages_id] => 1
[selected_box] => customers
[admin] => Array
	(
		[id] => 1
		[username] => admin
	)

[cart] => manualcart Object
	(
		[contents] => Array
			(
				[2] => Array
					(
						[qty] => 1
					)

				[1] => Array
					(
						[qty] => 2
					)

			)

		[total] => 199.9
		[weight] => 3
	)

)

Share this post


Link to post
Share on other sites

Interesting. It looks like the cart data is sometimes in the $_SESSION and sometimes not. (I was looking for the part starting with [cart] =>.)

 

Try changing the lines you posted above to this

  function determineTableMethod($geozone_mode) {
  global $total_count, $shipping_weight, $cart;

  $this->geozone_mode = $geozone_mode;

  if ($this->geozone_mode == 'price') {
	$this->order_total = $cart->show_total();
  } elseif ($this->geozone_mode == 'count') {
	$this->order_total = $total_count;
  } else {
	$this->order_total = $shipping_weight;
  }

  return true;	
}

As Robert mentioned above, you seem to have missing files in catalog/includes/modules/order_total/. I suggest that you check that as well.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
Interesting. It looks like the cart data is sometimes in the $_SESSION and sometimes not. (I was looking for the part starting with [cart] =>.)

 

Try changing the lines you posted above to this

  function determineTableMethod($geozone_mode) {
  global $total_count, $shipping_weight, $cart;

  $this->geozone_mode = $geozone_mode;

  if ($this->geozone_mode == 'price') {
	$this->order_total = $cart->show_total();
  } elseif ($this->geozone_mode == 'count') {
	$this->order_total = $total_count;
  } else {
	$this->order_total = $shipping_weight;
  }

  return true;	
}

As Robert mentioned above, you seem to have missing files in catalog/includes/modules/order_total/. I suggest that you check that as well.

 

Regards

Jim

 

Yes Jim this is odd, cart should never be missing from the session.

Share this post


Link to post
Share on other sites
Interesting. It looks like the cart data is sometimes in the $_SESSION and sometimes not. (I was looking for the part starting with [cart] =>.)

 

Try changing the lines you posted above to this

  function determineTableMethod($geozone_mode) {
  global $total_count, $shipping_weight, $cart;

  $this->geozone_mode = $geozone_mode;

  if ($this->geozone_mode == 'price') {
	$this->order_total = $cart->show_total();
  } elseif ($this->geozone_mode == 'count') {
	$this->order_total = $total_count;
  } else {
	$this->order_total = $shipping_weight;
  }

  return true;	
}

As Robert mentioned above, you seem to have missing files in catalog/includes/modules/order_total/. I suggest that you check that as well.

 

Regards

Jim

 

I double checked and all the files were there. However, I replaced the function as you instructed above and...IT WORKED! Thank you Jim and also thank you Robert for you assistance. I never would have gotten this on my own...I Googled my brains out all day and couldn't find anything nearly as useful as you two. Thank you so much...I love ending the day with at least one thing accomplished.

 

Now how to add this info to the shipping contribution so that others can benefit from your expertise? This is the shipping contribution: http://addons.oscommerce.com/info/2571 and, of course, the infamous order editor: http://addons.oscommerce.com/info/1435

Share this post


Link to post
Share on other sites

Good, that should always work. While the cart data should always be in the session, this only applies to the class constructor data and any other data that has been explicitly accessed. The entire class in not necessarily represented. It's therefore safer to instantiate the class and call it directly. Since the cart class is instantiated in application_top, it's available on every page. You need to pass it to functions/methods by using a Global deceleration (as I did here) or by passing it in the function call, but then it's available to use.

 

The missing file errors could have been a result of this error. If they're gone now, they were probably false results.

 

You could just modify the shipping addon and post a new version. This code should always work, and be more reliable than the previous version.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
Good, that should always work. While the cart data should always be in the session, this only applies to the class constructor data and any other data that has been explicitly accessed. The entire class in not necessarily represented. It's therefore safer to instantiate the class and call it directly. Since the cart class is instantiated in application_top, it's available on every page. You need to pass it to functions/methods by using a Global deceleration (as I did here) or by passing it in the function call, but then it's available to use.

 

The missing file errors could have been a result of this error. If they're gone now, they were probably false results.

 

You could just modify the shipping addon and post a new version. This code should always work, and be more reliable than the previous version.

 

Regards

Jim

 

Fix has been posted on the contribution and support thread with full credit given. Thanks again to you both for your help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×