Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to fix undefined function errors?


spencerb

Recommended Posts

Here's my specific problem: Using the Order Editor and Individual Shipping contribs give an error when trying to edit orders:

 

Fatal error: Call to undefined function: get_shiptotal() in xxx/includes/modules/shipping/indvship.php on line 32, with the code there being as follows:

 

function process() {

global $order, $cart, $currencies;

 

32-> $shiptot = $cart->get_shiptotal();

 

I came across one solution:

 

http://www.oscommerce.com/forums/index.php?s=&...t&p=1121904

 

but it doesn't work. My main concern is getting this specific problem fixed, but also I'd like to know what it means to get an undefined function error and the basic steps to resolve it. How and where do you define functions? I assume it's largely dependent on what process produces the error.

 

It seems like undefined function errors are very common, and I'd like a better understanding of how to fix them.

 

NOTE: I'm actually using my contribution for individual product order total fee that is used to add insurance, not shipping, but the contribution is basically the individual shipping one with renamed variables, and others with individual shipping are having the same problem. I changed the variable names in the code above so others with the same problem can recognize it.

 

Thanks for your help!

Link to comment
Share on other sites

This generally means you have not installed a contribution correctly.

 

Functions can be coded in almost any file and then an include staement lets the web server know to look in that file.

 

So if you don't add the funtion into the right file or put the file contaioning the function in the right place or......

 

It can't find it and so breaks.

 

Normally just going back and carefully checking the installation has been done correctly solves these problems, unlees of cource the contributor has messed up and not tested their work.

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

I don't believe it is an installation problem. I think what's happening is that two different contributions are just not happy together. Each one works great by itself (someone else with this problem mentioned that he can turn off individual shipping to get the order editor to work). So it looks like I'm on my own as far as fixing it.

 

Could you explain it a little further, maybe with examples? I understand that it's trying to execute a function that it doesn't know anything about. So you have to define that function somewhere. How do you know where it wants it defined, and what constitutes a definition?

Link to comment
Share on other sites

Generally speaking, you define a function by invoking syntax that looks something like this:

 

function someFunction() {

echo 'some code';

}

 

a function is sort of like a reusable lego block of code - this way instead of having to put

echo 'some code';

over and over again, you can just call the function. This is rudimentary of course. In you case a search for the name of the function get_shiptotal should show you where else it is called FROM while a search for "function get_shiptotal" will show you where it is defined, if it is. Since a function can be (and oftentimes is) defined in a different file, you would want to search the entire directory. If you are renaming things, the definition of the function has to match up with its call, if that makes any sense ...

Even at a Mensa convention someone is the dumbest person in the room.

Link to comment
Share on other sites

Very clear explanation, thank you.

 

So I found where the function is defined, in /includes/classes/shopping_cart.php

 

So how do I tell it to look there for the definition? And will the code to "point" there be in the file that contain the undefined function (in this case /includes/modules/shipping/indvship.php)?

Link to comment
Share on other sites

  • 2 months later...
Here's my specific problem: Using the Order Editor and Individual Shipping contribs give an error when trying to edit orders:

 

Fatal error: Call to undefined function: get_shiptotal() in xxx/includes/modules/shipping/indvship.php on line 32, with the code there being as follows:

 

function process() {

global $order, $cart, $currencies;

 

32-> $shiptot = $cart->get_shiptotal();

 

I came across one solution:

 

http://www.oscommerce.com/forums/index.php?s=&...t&p=1121904

 

but it doesn't work. My main concern is getting this specific problem fixed, but also I'd like to know what it means to get an undefined function error and the basic steps to resolve it. How and where do you define functions? I assume it's largely dependent on what process produces the error.

 

It seems like undefined function errors are very common, and I'd like a better understanding of how to fix them.

 

NOTE: I'm actually using my contribution for individual product order total fee that is used to add insurance, not shipping, but the contribution is basically the individual shipping one with renamed variables, and others with individual shipping are having the same problem. I changed the variable names in the code above so others with the same problem can recognize it.

 

Thanks for your help!

This will fix the problem!

 

 

In Indvship1.php

 

Find :

$shiptotal1 = $cart->get_shiptotal1();

 

Replace :

$currpage =$_SERVER["PHP_SELF"];

if ($currpage <> "/admin/edit_orders.php"){

$shiptotal1 = $cart->get_shiptotal1();

}

 

More of a patch rather than fix, none the less works. You will need to repeat this accross all shipping per item pages where

$shiptotal1 = $cart->get_shiptotal1();

 

exists

 

Happy days.

Dan

Link to comment
Share on other sites

Here is a revision to psylencer's fix you may need. There are three scripts in the order editor, and we need to exclude calling the individual shipping function from all three:

 

Find (around line 32) in indvship.php:

 

$shiptot = $cart->get_shiptotal();

 

Replace with:

	  $currpage = $_SERVER['PHP_SELF'];
  if ($currpage == "/admin/edit_orders.php") {
  }
	elseif ($currpage == "/admin/edit_orders_ajax.php") {
	}
	  elseif ($currpage == "/admin/edit_orders_add_product.php") {
	  }
		else {
		$shiptot = $cart->get_shiptotal();
		}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...