Related Products

Warning in Admin 1.0.8.20 PHP 8 - Related Products

Warning in Admin 1.0.8.20 PHP 8

by heatherbell » Sun Nov 20, 2022 8:13 am

Installed your latest Related_Products_Phoenix_7.5.4 on our staging site using 1.0.8.20 PHP 8
/admin/optional_related_products.php gives
Warning: Trying to access array offset on value of type null in C:\xampp8\htdocs\PhoenixCart-1.0.8.20\includes\system\versioned\1.0.7.other\1.0.7.12\product_builder.php on line 98
Any pointers appreciated.
heatherbell
VIP Member
VIP Member
Posts: 1996
Joined: Mon Oct 07, 2019 4:39 am
Contact:

Re: Warning in Admin 1.0.8.20 PHP 8

by heatherbell » Sun Nov 20, 2022 3:54 pm

Used the Delete Orphans button and the warnings disappeared :roll:
heatherbell
VIP Member
VIP Member
Posts: 1996
Joined: Mon Oct 07, 2019 4:39 am
Contact:

Re: Warning in Admin 1.0.8.20 PHP 8

by raiwa » Sun Nov 20, 2022 3:57 pm

I can't reproduce this error even after recent installation with empty related products table. Product class (product_builder) is not used in that page. So I have no clue how this error can be produced.
Maybe you could try error trace to get to root where the error comes from.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1184
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Warning in Admin 1.0.8.20 PHP 8

by raiwa » Sun Nov 20, 2022 3:58 pm

heatherbell wrote:Used the Delete Orphans button and the warnings disappeared :roll:
Ok, that's from obsolete entries in the table. I'll check it.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1184
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Warning in Admin 1.0.8.20 PHP 8

by raiwa » Sun Nov 20, 2022 6:21 pm

I could reproduce it.
It happens at line 382:

Code: Select all

          $products_name_slave = Product::fetch_name($relations_values['pop_products_id_slave']);
I have overseen that there the product class is used to get the product name which can happen on not existing products in the products table.
I'll have a look and try to secure this.

However it might be a good idea to secure this in core:
includes\system\versioned\1.0.7.other\1.0.7.12\product_builder.php

Code: Select all

    public static function fetch_name($product_id, $language_id = null) {
      if (empty($language_id)) {
        $language_id = $_SESSION['languages_id'];
      }

      $query = $GLOBALS['db']->query(sprintf("SELECT products_name FROM products_description WHERE products_id = %d AND language_id = %d", (int)$product_id, (int)$language_id));
      $result = $query->fetch_assoc();
      return $result['products_name']?? '';
    }
Maybe you can forward this to @ecartz?
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1184
Joined: Sat Dec 21, 2019 8:08 am
Contact:

Re: Warning in Admin 1.0.8.20 PHP 8

by raiwa » Mon Nov 21, 2022 10:19 am

Updated with fix for above warning message. Thanks for the report.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1184
Joined: Sat Dec 21, 2019 8:08 am
Contact: