ps_categorytree generates error when there are no nested categories
Prerequisites
- [X] I understand and accept the project's code of conduct.
- [x] I have already searched in existing issues and found no previous report of this bug.
Describe the bug and add attachments
Since we installed ps_categorytree v3.0.0, a TypeError is thrown when accessing some category pages in the front-office:
TypeError: Return value of Ps_CategoryTree::getCategories() must be of the type array, null returned in /var/www/html/htdocs/modules/ps_categorytree/ps_categorytree.php:151
Expected behavior
The page should load without any issues.
Steps to reproduce
I did not manage to reproduce exactly why this error occurs. The Category::getNestedCategories() method called by the ps_categorytree module seems to return nested categories depending whether it is enabled for a given customer group or shop. This issue may appear if the parent category is "visible" to a certain user (thus the category page is loaded), but nested ones have a few restrictions based on group or shop. I did not have much time to investigate but I'll try to think it through in a few days, but if you have a few ideas...
PrestaShop version(s) where the bug happened
8.0.5
PHP version(s) where the bug happened
7.4
If your bug is related to a module, specify its name and its version
ps_categorytree v3.0.0
Your company or customer's name goes here (if applicable).
WAM
Hello @Roxayl ,
I can't reproduce your issue. I have no error on inspect element, debug mode is enabled, no errors on BO>Logs>search for Ps_CategoryTree. I visited categories in my FO with/out subcategories.
I searched on my PHP log file, I couldn't find any error related to Ps_CategoryTree.
Could you specify how to reproduce the issue and send screenshots as well ?
Waiting for your feedback. Thanks!
@florine2623 I reproduced it, on develop, when the module is set to "Current category" and you visit a category that has no subcategories.
Hi, I also have the same issue on Prestashop 8.1.7. On all categories that have no subcategories, regardless of the settings for the module (current category, parent category...)
Hello I am on 1.7.8.9 when I activate the module, I have the similar problem with this error which appears everywhere on the site except on the home page: TypeError: Return value of Ps_CategoryTree::getCategories() must be of the type array, null returned in /home/onemorestyle/public_html/mo.....etc.etc. For me, the problem occurs on all the category settings. I thought that uninstalling and reinstalling the module might solve the problem, but not at all.
@florine2623 Please try to reproduce like this:
- Get latest PS version, get latest PHP version, latest version of the module.
- Enable debug mode.
- Set the module settings to "Current category".
- Go to any category in FO that does not have subcategories. There will be an error.
@florine2623 Sorry for the late reply, I didn't have time to investigate further. ^^'
You should be able to reproduce it following the steps suggested by @Hlavtox, thank you by the way!
Thank you, it's already very good to take time
Good luck to you
Franck
Le 2024-10-15 16:13, Elyn a écrit :
@florine2623 [1] Sorry for the late reply, I didn't have time to investigate further. ^^'
You should be able to reproduce it following the steps proposed by @Hlavtox [2], thank you by the way!
-- Reply to this email directly, view it on GitHub [3], or unsubscribe [4]. You are receiving this because you commented.Message ID: @.***>
Links:
[1] https://github.com/florine2623 [2] https://github.com/Hlavtox [3] https://github.com/PrestaShop/PrestaShop/issues/37040#issuecomment-2414043506 [4] https://github.com/notifications/unsubscribe-auth/BMCEAZBBH5DY4MHU7RU5OKLZ3UPJJAVCNFSM6AAAAABO7G3RP2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJUGA2DGNJQGY
Greetings.
I have the same problem on the 'offers' category of a prestashop 8.1.6 php 8.
The module called with error is always the one you mentioned, offers corresponds to the basic Prestashop 'prices-drop' page. Is there a new module released by any chance? Or how could we solve it?
I still can't reproduce it 😓 I didn't find the same error in log or in FO.
https://github.com/user-attachments/assets/3dba101c-aecc-4fe6-aba5-97c43983b3c8
@PrestaShop/qa-functional , can someone try to reproduce please ?
Thanks!
I couldn't save the error because the customer was in a hurry to fix his offers category.
However, updating the version of the module to 3.0.0 by clicking on the offers returned the error reported here.
It doesn't provide it to me on a specific category, but on the dynamic price-drop page called "offers" in Italian. The inherited error was that, in fact, it had no subcategories and therefore the page was no longer visible, returning the usual 500 error. home page: TypeError: Return value of Ps_CategoryTree::getCategories() was the same - recalling the categorization of Symfony and the existing theme (in this case warehouse. But reading various comments online I saw that it had also happened with other themes and, probably, also with the classic one. At the moment I haven't updated it and I won't update it for others) .
Hi @Roxayl
Thank you for your report, currently, I tried to reproduce your issue but I can't as you can see :
FYI : I put my store in the same configuration of yours ( 8.0.5 with php 7.4 to have the upgrade of the module possible ) even with this part, I can't reproduce the issue
I had the same error. It came from a "Creative Elements" widget that came with the Alysum theme. I removed the "Promokit general / Prestashop Module" widget (which retrieved the category links) and the page works again.
Regards :)
In the module private member function getCategories($category) the return value of Category::getNestedCategories() is assumed to be an array when it can be an array or null. In the case of the latter the function should not attempt to operate on the result as an array, but it does (using the function array_shift() after code manipulation that has no effect on the null return value).
got the same error. pretashop 8.1.7, php 8.1, module version v3.0.0. Fixed on line 151 of the class in the file ps_categorytree.php.
Hi guys, gixed by https://github.com/PrestaShop/ps_categorytree/pull/76
When 3.0.1 is released, update please. :-)
Hi everyone, I've encountered the same issue for one of our customers.
I've tried to add the code inside https://github.com/PrestaShop/ps_categorytree/pull/76 and while it fixed the error 500, the category tree was empty on the front page.
It seems that the cause for us was that the root category settings was set to "Not visible", and somehow that result in an empty category list / null value.
I've set the root category to visible and it works as before.
I hope this feedback will be helpful :)
Hi everyone, I've encountered the same issue for one of our customers.
I've tried to add the code inside PrestaShop/ps_categorytree#76 and while it fixed the error 500, the category tree was empty on the front page.
It seems that the cause for us was that the root category settings was set to "Not visible", and somehow that result in an empty category list / null value.
I've set the root category to visible and it works as before.
I hope this feedback will be helpful :)
I can confirm that this fix isn't a fix, it just masks the 500 error, but the category tree is completely empty when root category is disabled.
It doesn't mask anything, it properly handles a false response.
This error occurs because of changes that started to use the core logic to fetch categories. And this logic works a bit differently.
The home category should be always enabled. Ping @kpodemski Is there any reason to have a home category disabled?
What I meant is it currently brakes the feature that was working previously, if it should be always enabled then why have the option?
For me at least it is disabled to hide the view with all the products from search engines etc. since it is not necessary.
This is the change that broke it - https://github.com/PrestaShop/ps_categorytree/pull/35/files
Before, it's custom logic selected categories that were active or home.