Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

The global variables do not work


tioserch

Recommended Posts

Hello to all.

 

Perhaps I do not express myself in English well, because I am Spanish and know English little.

 

I have created three modules of form of shipment, and the third one does not work, appearing this error:

Fatal error: Call to a member function get_products() on a non-object in /home/dollsand/public_html/includes/modules/shipping/correospip.php on line 58

 

In this line appear this code:

$products = $cart->get_products();

 

I have been doing tests and cannot solve it. I have installed the contribution of REGISTER_GLOBALS, but the error keeps on appearing. I have removed the second form of shipment and I have put it again and now the same error appears (previously was working well).

 

How is this possible? Can anybody help me?

 

Thank you.

Link to comment
Share on other sites

Hello to all.

 

Perhaps I do not express myself in English well, because I am Spanish and know English little.

 

I have created three modules of form of shipment, and the third one does not work, appearing this error:

Fatal error: Call to a member function get_products() on a non-object in /home/dollsand/public_html/includes/modules/shipping/correospip.php on line 58

 

In this line appear this code:

$products = $cart->get_products();

 

I have been doing tests and cannot solve it. I have installed the contribution of REGISTER_GLOBALS, but the error keeps on appearing. I have removed the second form of shipment and I have put it again and now the same error appears (previously was working well).

 

How is this possible? Can anybody help me?

 

Thank you.

 

You need to make the $cart variable available in the class scope.

 

To do this look for a line like ..

 

global $thisvar, $thatvar;

 

Then add $cart to the end like ..

 

global $thisvar, $thatvar, $cart;

 

If you cannot find a line like global ...... just create one

 

global $cart;

Link to comment
Share on other sites

Thank you for your help.

 

I put $cart in the class scope like this:

  class correospip {
var $code, $title, $description, $icon, $enabled,$types;
global $cart;

// class constructor
function correospip() {
  global $order;//, $cart;

 

and I get the following error:

Parse error: syntax error, unexpected T_GLOBAL, expecting T_FUNCTION in /home/dollsand/public_html/includes/modules/shipping/correospip.php on line 17

 

Can you tell me where I need to define exactly $cart as global?

 

Thank you.

Link to comment
Share on other sites

Thank you for your help.

 

I put $cart in the class scope like this:

  class correospip {
var $code, $title, $description, $icon, $enabled,$types;
global $cart;

// class constructor
function correospip() {
  global $order;//, $cart;

 

and I get the following error:

 

 

Can you tell me where I need to define exactly $cart as global?

 

Thank you.

 

Put the global xx in the constructor ..

 

 

  class correospip {
 var $code, $title, $description, $icon, $enabled,$types;

 // class constructor
 function correospip() {
global $order, $cart;

Link to comment
Share on other sites

That's how it was placed from the outset and does not work.

 

Admin continues to give the same error message and in implementing the code does not give me wrong but its value is 0.

 

Can you think of a another idea, please?

Link to comment
Share on other sites

That's how it was placed from the outset and does not work.

 

Admin continues to give the same error message and in implementing the code does not give me wrong but its value is 0.

 

Can you think of a another idea, please?

 

It depends where it is used $cart would have to be passed to each method in the class (or set global) or alternatively you could do the following to access the $cart class as $this->cart anywhere in the class;

 

For example the following works, you could test the following code locally (you do seem out of your depth with classes though).

 

<?php
$cart = array('1', '2', '3', '4', '5', '6', '7');
 class correospip {
var $code, $title, $description, $icon, $enabled,$types, $cart;

// class constructor
function correospip() {
  global $order, $cart;
  $this->cart = $cart;
}

function echoCart(){
  print_r($this->cart);
}
 }

$class = new correospip;

$class->echoCart();
?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...