lat9 / product_pagination

Zen Cart: Product Pagination
GNU General Public License v2.0
1 stars 1 forks source link

PHP Fatal error: Typed property ProductsPaginationObserver::$nextPosition must not be accessed before initialization #36

Closed torvista closed 6 months ago

torvista commented 6 months ago

This is triggered on my site by going to a product info page (having the wiki snippet), which is the first product in the listing, from another category entirely. Unfortunately I've not been able to duplicate this on a vanilla ZC2 install, yet.

I suspect it's something odd in my site, so this is here for the record only.

I've initially fixed it by setting $nextPosition=0;

[25-Apr-2024 23:00:35 Europe/Madrid] PHP Fatal error: Uncaught Error: Typed property ProductsPaginationObserver::$nextPosition must not be accessed before initialization in ..\includes\classes\observers\ProductsPaginationObserver.php:291 Stack trace:

0 ..\includes\templates\template_default\templates\tpl_pp_products_next_previous.php(129): ProductsPaginationObserver->getNextProductInfo()

1 ..\includes\templates\motorvista5\templates\tpl_products_next_previous.php(39): require('D:\OneDrive\Bus...')

2 ..\includes\templates\motorvista5\templates\tpl_product_info_display.php(72): require('D:\OneDrive\Bus...')

3 ..\includes\modules\pages\product_info\main_template_vars.php(147): require('D:\OneDrive\Bus...')

4 ..\includes\templates\motorvista5\common\tpl_main_page.php(209): require('D:\OneDrive\Bus...')

5 ..\index.php(94): require('D:\OneDrive\Bus...')

6 {main}

thrown in ..\includes\classes\observers\ProductsPaginationObserver.php on line 291

lat9 commented 6 months ago

Interesting; if you can replicate that would be great.

torvista commented 6 months ago

Phew... CeonUriMapping can add a ?cPath=3_26_1446_4108, whatever to the end of a static url. If some dumb spider tries to use such an url on a product that has since been moved, that old cPath is not valid for that product.

I suppose it should be handled elsewhere, but when $this->productsArray is created from that old cPath, the current product_id is not in the array, so the subsequent if ($values['id'] === (int)$_GET['products_id']) { never happens.

I added a clause in the function isPaginationEnabled to catch it and redirect 301 to the product, as I don't think it can happen through human navigation.

This may also be related to the Product Finder mod I use, so all this is for possible future reference and not any action.