Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Lets help each other out, and point out the required changes to bring our shops up to the PHP8 level.

1) Replacing tep_session_is_registered

You will find this in several places throughout the osCommerce project, so you have to check for them all, and then change it over. Be careful to note the use of ! before tep_session_is_registered.

eg. checkout_success.php

FInd:

if (!tep_session_is_registered('customer_id')) {

Replace with:

if (!isset($_SESSION['customer_id'])) {

You will find several instances of tep_session_is_registered in application_top.php

Then starting from account.php, account_edit.php ..., you will typically find:

  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link('login.php', '', 'SSL'));
  }

Using tep_session_is_registered is a common condition for addons, so you have to check any mods you have made.

Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

Instead of updating all of the files that use this osC function, why not just update the function itself in /includes/functions/sessions.php?

Zombie Phoenix v1.0.8.3 has the latest version of this function. I haven't tried it yet, but it should work.

https://www.php.net/manual/en/migration80.deprecated.php

 

 

 

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&geo=US&q=oscommerce

Link to comment
Share on other sites

I need to retract my first post. Yesterday i switched over to php8 for the first time and did a quick test order. The process failed on checkout_success.php and i may have incorrectly assumed that tep_session_is_registered was the code at fault. On closer inspection the failure was due to one of the checkout success modules. After reinstalling that module the problem disappeared. So I am going to revert the changes I mentioned above. This is what the function looks like in sessions.php:

  function tep_session_is_registered($variable) {
    if (PHP_VERSION < 4.3) {
      return session_is_registered($variable);
    } else {
      return isset($_SESSION) && array_key_exists($variable, $_SESSION);
    }
  }

Can anybody see anything wrong with it that may cause a compatibility problem with php8 ?

So for the moment I don't see any issues with php8 on the catalog side. The Admin breaks with the error:

Fatal error: Uncaught Error: Call to undefined function get_magic_quotes_gpc() in

 

Link to comment
Share on other sites

Perhaps like this (untested, I have to install Php8) ? :
 

// handle magic_quotes_gpc turned off.

if (PHP_VERSION < '8') {
  if (!get_magic_quotes_gpc()) {
    do_magic_quotes_gpc($HTTP_GET_VARS);
    do_magic_quotes_gpc($HTTP_POST_VARS);
    do_magic_quotes_gpc($HTTP_COOKIE_VARS);
  }
}

 

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

9 minutes ago, bonbec said:

Perhaps like this (untested, I have to install Php8) ? :
 


// handle magic_quotes_gpc turned off.

if (PHP_VERSION < '8') {
  if (!get_magic_quotes_gpc()) {
    do_magic_quotes_gpc($HTTP_GET_VARS);
    do_magic_quotes_gpc($HTTP_POST_VARS);
    do_magic_quotes_gpc($HTTP_COOKIE_VARS);
  }
}

 

This will work, it will have the same effect as commenting out the code like:

// handle magic_quotes_gpc turned off.
  #if (!get_magic_quotes_gpc()) {
    #do_magic_quotes_gpc($HTTP_GET_VARS);
    #do_magic_quotes_gpc($HTTP_POST_VARS);
    #do_magic_quotes_gpc($HTTP_COOKIE_VARS);
  #}

This is in admin/includes/functions/compatibility.php line 45

Link to comment
Share on other sites

      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO . '<br /><br /><strong>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '</strong>');

replace with:

      #$contents[] = array('text' => TEXT_INFO_DELETE_INTRO . '<br /><br /><strong>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '</strong>');
      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO . '<br /><br /><strong>' . $oInfo->customers_name . '</strong>');

 

Link to comment
Share on other sites

1 hour ago, Hotclutch said:

This will work, it will have the same effect as commenting out the code like:

Not exactly, what I'm suggesting keeps compatibility for versions of PHP <8 (for those who don't yet have PHP 8).

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

The theme of this thread is to update to PHP8,... that means code related to PHP versions that precede 8.0 is irrelevant.

Similarly, the first part of that conditional IF statement in the tep_session_is_registered function is useless because PHP versions of 4.3 and lower, are no longer supported.

 

 

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Link to comment
Share on other sites

yes, I realise the first part of the function is irrelevant, it could be rewritten as:

  function tep_session_is_registered($variable) {
    return isset($_SESSION) && array_key_exists($variable, $_SESSION);
  }

its array_key_exists that I am not sure about. Anyway no errors are shown running with a debugger on.

Link to comment
Share on other sites

Here is that function from Zombie Phoenix v1.0.8.0  (not v1.0.8.3 as I had posted prior):

  function tep_session_is_registered($variable) {
    trigger_error('The tep_session_is_registered function has been deprecated.', E_USER_DEPRECATED);
    return isset($_SESSION) && array_key_exists($variable, $_SESSION);
  }

...though I don't think this has anything to do with migrating to PHP8.0

 

Quote

its array_key_exists that I am not sure about.

array_key_exists() is not part of the deprecated functions in PHP8.0. See links below.

https://www.php.net/manual/en/migration80.deprecated.php

https://www.php.net/manual/en/function.array-key-exists.php

 

 

osCommerce: made for programmers, ...because store owners do not want to be programmers.

https://trends.google.com/trends/explore?date=all&amp;geo=US&amp;q=oscommerce

Link to comment
Share on other sites

  • 2 weeks later...

So whats the difference in error reporting between the CEs and last official osCommerce?

I see

// Set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);

  if (defined('E_DEPRECATED')) {
    error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
  }

on both them.

I am running 2 test shops on the same php8 server environment, the one is Defrosted (created from Frozen), the other is W3 osCommerce, I created from scratch on a 2.3.4.1 installation.

On the W3 osCommerce admin i get a fatal error in classes/split_page_results.php, whereas i see no problem for it on the Frozen admin.

    function display_count($query_numrows, $max_rows_per_page, $current_page_number, $text_output) {
      $to_num = ($max_rows_per_page * $current_page_number);
      if ($to_num > $query_numrows) $to_num = $query_numrows;
      $from_num = ($max_rows_per_page * ($current_page_number - 1));
      if ($to_num == 0) {
        $from_num = 0;
      } else {
        $from_num++;
      }

      return sprintf($text_output, $from_num, $to_num, $query_numrows);
    }

I googled this, and a possible solution appears to be:

    function display_count($query_numrows, $max_rows_per_page, $current_page_number, $text_output) {
      $to_num = ((int)$max_rows_per_page * (int)$current_page_number);
      if ($to_num > $query_numrows) $to_num = $query_numrows;
      $from_num = ((int)$max_rows_per_page * ((int)$current_page_number - 1));
      if ($to_num == 0) {
        $from_num = 0;
      } else {
        $from_num++;
      }

      return sprintf($text_output, $from_num, $to_num, $query_numrows);
    }

 which does clear the error. 

Link to comment
Share on other sites

The following errors are thrown in admin whos online, when click on a customer row.

Warning: Trying to access array offset on value of type null

admin/includes/classes/shopping_cart.php on line 154

admin/includes/classes/shopping_cart.php on line 218
admin/includes/classes/shopping_cart.php on line 221

line 154:

      if ($this->contents[$products_id]) {

line 218

if ($attribute_price['price_prefix'] == '+') {

line 221

$this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);

Also

Warning: Undefined array key "qty" on line 124:

if ($this->contents[$key]['qty'] < 1) {

 

Link to comment
Share on other sites

7 hours ago, Hotclutch said:

The following errors are thrown in admin whos online, when click on a customer row.

Warning: Trying to access array offset on value of type null

admin/includes/classes/shopping_cart.php on line 154

admin/includes/classes/shopping_cart.php on line 218
admin/includes/classes/shopping_cart.php on line 221

line 154:


      if ($this->contents[$products_id]) {

line 218


if ($attribute_price['price_prefix'] == '+') {

line 221


$this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);

Also

Warning: Undefined array key "qty" on line 124:


if ($this->contents[$key]['qty'] < 1) {

 

https://github.com/ruden/vanilla-oscommerce/blob/dev/catalog/admin/includes/classes/shopping_cart.php

The water in a vessel is sparkling; the water in the sea is dark. The small truth has words which are clear; the great truth has great silence.

- Rabindranath Tagore

Link to comment
Share on other sites

2 hours ago, Hotclutch said:

^^That clears Warning: Trying to access array offset on value of type null errors.

Still leaves the undefined array key errors.

 

p22-min.png

Change:

if ($this->contents[$key]['qty'] < 1) {

to:

if (isset($this->contents[$key]['qty']) < 1) {

 

The water in a vessel is sparkling; the water in the sea is dark. The small truth has words which are clear; the great truth has great silence.

- Rabindranath Tagore

Link to comment
Share on other sites

Warning: Trying to access array offset on value of type null /includes/classes/order.php on line 222

There are multiple warnings of this type in this section of code:

      $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
                          'currency' => $currency,
                          'currency_value' => $currencies->currencies[$currency]['value'],
                          'payment_method' => $payment,
                          'cc_type' => '',
                          'cc_owner' => '',
                          'cc_number' => '',
                          'cc_expires' => '',
                          'shipping_method' => $shipping['title'],
                          'shipping_cost' => $shipping['cost'],
                          'subtotal' => 0,
                          'tax' => 0,
                          'tax_groups' => array(),
                          'comments' => (tep_session_is_registered('comments') && !empty($comments) ? $comments : ''));

If i do this:

      $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
                          'currency' => $currency,
                          'currency_value' => $currencies->currencies[$currency]['value'],
                          'payment_method' => $payment,
                          'cc_type' => '',
                          'cc_owner' => '',
                          'cc_number' => '',
                          'cc_expires' => '',
                          #'shipping_method' => $shipping['title'],
                          'shipping_method' => isset($shipping['title']) ? $shipping['title'] : '',                          
                          #'shipping_cost' => $shipping['cost'],
                          'shipping_cost' => isset($shipping['cost']) ? $shipping['cost'] : '',                           
                          'subtotal' => 0,
                          'tax' => 0,
                          'tax_groups' => array(),
                          'comments' => (tep_session_is_registered('comments') && !empty($comments) ? $comments : ''));

the error is cleared, but is this the correct way to resolve this error?

Link to comment
Share on other sites

This is what I have and it seems to work.

      $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
                          'currency' => $currency,
                          'currency_value' => $currencies->currencies[$currency]['value'],
                          'payment_method' => $payment,
                          'cc_type' => '',
                          'cc_owner' => '',
                          'cc_number' => '',
                          'cc_expires' => '',
                          'shipping_method' => (isset($shipping['title']) ? $shipping['title'] : ''),
                          'shipping_cost' => (isset($shipping['cost']) ? $shipping['cost'] : 0),
                          'subtotal' => 0,
                          'tax' => 0,
                          'tax_groups' => array(),
                          'comments' => (isset($_SESSION['comments']) && !empty($comments) ? $comments : ''));

 

The water in a vessel is sparkling; the water in the sea is dark. The small truth has words which are clear; the great truth has great silence.

- Rabindranath Tagore

Link to comment
Share on other sites

I had that also and it worked, but then as i did the others the debugger started to throw more errors. Need to look at it some more.

      $this->customer = array('firstname' => $customer_address['customers_firstname'],
                              'lastname' => $customer_address['customers_lastname'],
                              'company' => $customer_address['entry_company'],
                              'street_address' => $customer_address['entry_street_address'],
                              'suburb' => $customer_address['entry_suburb'],
                              'city' => $customer_address['entry_city'],
                              'postcode' => $customer_address['entry_postcode'],
                              'state' => ((tep_not_null($customer_address['entry_state'])) ? $customer_address['entry_state'] : $customer_address['zone_name']),
                              'zone_id' => $customer_address['entry_zone_id'],
                              'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']),
                              'format_id' => $customer_address['address_format_id'],
                              'telephone' => $customer_address['customers_telephone'],
                              'email_address' => $customer_address['customers_email_address']);

      $this->delivery = array('firstname' => $shipping_address['entry_firstname'],
                              'lastname' => $shipping_address['entry_lastname'],
                              'company' => $shipping_address['entry_company'],
                              'street_address' => $shipping_address['entry_street_address'],
                              'suburb' => $shipping_address['entry_suburb'],
                              'city' => $shipping_address['entry_city'],
                              'postcode' => $shipping_address['entry_postcode'],
                              'state' => ((tep_not_null($shipping_address['entry_state'])) ? $shipping_address['entry_state'] : $shipping_address['zone_name']),
                              'zone_id' => $shipping_address['entry_zone_id'],
                              'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']),
                              'country_id' => $shipping_address['entry_country_id'],
                              'format_id' => $shipping_address['address_format_id']);

      $this->billing = array('firstname' => $billing_address['entry_firstname'],
                             'lastname' => $billing_address['entry_lastname'],
                             'company' => $billing_address['entry_company'],
                             'street_address' => $billing_address['entry_street_address'],
                             'suburb' => $billing_address['entry_suburb'],
                             'city' => $billing_address['entry_city'],
                             'postcode' => $billing_address['entry_postcode'],
                             'state' => ((tep_not_null($billing_address['entry_state'])) ? $billing_address['entry_state'] : $billing_address['zone_name']),
                             'zone_id' => $billing_address['entry_zone_id'],
                             'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']),
                             'country_id' => $billing_address['entry_country_id'],
                             'format_id' => $billing_address['address_format_id']);

All / most of these need to be done, then there is that one with tep_not_null ...

Link to comment
Share on other sites

banner_manager.php throws an error. 

Warning: count(): Parameter must be an array or an object that implements Countable in

admin/includes/classes/phplot.php on line 1324

		if ( count($color_asked) == 3 ) { //already array of 3 rgb

above is line 1324, the complete function is:

	function SetRgbColor($color_asked) {
		//Returns an array in R,G,B format 0-255
		if ($color_asked == "") { $color_asked = array(0,0,0); };

		if ( count($color_asked) == 3 ) { //already array of 3 rgb
	   		$ret_val =  $color_asked;
		} else { // is asking for a color by string
			if(substr($color_asked,0,1) == "#") {  //asking in #FFFFFF format. 
				$ret_val =  array(hexdec(substr($color_asked,1,2)), hexdec(substr($color_asked,3,2)), hexdec(substr($color,5,2)));
			} else { 
				$ret_val =  $this->rgb_array[$color_asked];
			}
		}
		return $ret_val;
	}

 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...