Page 1 of 2
Show linked categories on catalog.php
Posted: Thu Nov 09, 2023 6:19 pm
by tessthepup
Hi Guys,
Would anyone have any ideas on how to show the categories that a prouct is linked to under the 'Move' & 'Copy To' buttons in admin/catalog.php?
Thanks
Mark
Re: Show linked categories on catalog.php
Posted: Thu Nov 09, 2023 8:46 pm
by Kofod95
You can find how to get a list of the categories here:
https://github.com/CE-PhoenixCart/Phoen ... ct.php#L17
Then insert that into the infoBox with a hook (includes/hooks/admin/catalog/categories.php) that goes something like:
Code: Select all
class hook_admin_catalog_categories{
function listen_infoBox($parameters) {
global $product;
if ($product && ($product Instanceof Product)) $parameters['contents'][] = ['class' => 'style', 'text' => $GLOBALS['Categories']::draw_breadcrumbs($product->get('categories'))];
}
}
Add a meaningful class instead of "style" and add explanation in text (preferably as a constant defined in a language-file) as needed.
//Daniel
Re: Show linked categories on catalog.php
Posted: Sat Nov 11, 2023 2:19 pm
by tessthepup
Kofod95 wrote: ↑Thu Nov 09, 2023 8:46 pm
You can find how to get a list of the categories here:
https://github.com/CE-PhoenixCart/Phoen ... ct.php#L17
Then insert that into the infoBox with a hook (includes/hooks/admin/catalog/categories.php) that goes something like:
Code: Select all
class hook_admin_catalog_categories{
function listen_infoBox($parameters) {
global $product;
if ($product && ($product Instanceof Product)) $parameters['contents'][] = ['class' => 'style', 'text' => $GLOBALS['Categories']::draw_breadcrumbs($product->get('categories'))];
}
}
Add a meaningful class instead of "style" and add explanation in text (preferably as a constant defined in a language-file) as needed.
//Daniel
@Kofod95
Hi Daniel, thanks for that.
I had to change this
Code: Select all
if ($product && ($product Instanceof Product)) $parameters['contents'][] = ['class' => 'style', 'text' => $GLOBALS['Categories']::draw_breadcrumbs($product->get('categories'))];
to this
Code: Select all
if (class_exists($product && ($product Instanceof Product))) $parameters['contents'][] = ['class' => 'style', 'text' => $GLOBALS['Categories']::draw_breadcrumbs($product->get('categories'))];
as it was throwing a class error in PHP8
Now there are no errors but the categories do not show

Re: Show linked categories on catalog.php
Posted: Sat Nov 11, 2023 4:31 pm
by Kofod95
This looks wrong
Code: Select all
if (class_exists($product && ($product Instanceof Product)))
class_exists should only check something that could actually be a class (I think)
Maybe something like:
Code: Select all
if (class_exists(Product) && $product && ($product Instanceof Product))
However I don't know what error you got. If the class does not exist, then this will never return anything with or without an error, so fixing the original error would be better than using class_exists (unless that was to suppress the warning on categories)
//Daniel
Re: Show linked categories on catalog.php
Posted: Sat Nov 11, 2023 4:43 pm
by tessthepup
Kofod95 wrote: ↑Sat Nov 11, 2023 4:31 pm
This looks wrong
Code: Select all
if (class_exists($product && ($product Instanceof Product)))
class_exists should only check something that could actually be a class (I think)
Maybe something like:
Code: Select all
if (class_exists(Product) && $product && ($product Instanceof Product))
However I don't know what error you got. If the class does not exist, then this will never return anything with or without an error, so fixing the original error would be better than using class_exists (unless that was to suppress the warning on categories)
//Daniel
@Kofod95
The error log shows this
[11-Nov-2023 16:40:05 Europe/London] PHP Fatal error: Uncaught Error: Class name must be a valid object or a string in /home/***/public_html/includes/hooks/admin/catalog/categories.php:5
Stack trace:
#0 /home/***/public_html/includes/system/versioned/1.0.8.1/hooks.php(150): hook_admin_catalog_categories->listen_infoBox()
#1 /home/***/public_html/***/includes/components/infobox.php(22): hooks->cat()
#2 /home/***/public_html/***/includes/actions/catalog/views/default.php(183): require('/home/***...')
#3 /home/***/public_html/***/catalog.php(48): require('/home/***...')
#4 {main}
thrown in /home/***/public_html/includes/hooks/admin/catalog/categories.php on line 5
Re: Show linked categories on catalog.php
Posted: Sat Nov 11, 2023 8:56 pm
by Kofod95
Maybe Instanceof should be instanceof - Might be my autocorrect that changed that.
The Product class should exists, so "class_exists" should not be needed.
If it still fails, try with just
- I don't think it's likely that the variable contains anything it shouldn't, but I might be wrong...
//Daniel
Re: Show linked categories on catalog.php
Posted: Sun Nov 12, 2023 11:42 am
by Omar_one
@tessthepup try this ,, thank you
@Kofod95
Code: Select all
class hook_admin_catalog_categories{
public function listen_infoBox($parameters) {
global $product;
if (isset($product) && ($product instanceof Product)) $parameters['contents'][] = ['class' => 'style', 'text' => Categories::draw_breadcrumbs($product->get('categories'))];
}
}
1212.JPG
Re: Show linked categories on catalog.php
Posted: Sun Nov 12, 2023 12:37 pm
by tessthepup
Omar_one wrote: ↑Sun Nov 12, 2023 11:42 am
@tessthepup try this ,, thank you @Kofod95
Code: Select all
class hook_admin_catalog_categories{
function listen_infoBox($parameters) {
global $product;
if (isset($product && ($product Instanceof Product)) $parameters['contents'][] = ['class' => 'style', 'text' => Categories::draw_breadcrumbs($product->get('categories'))];
}
}
1212.JPG
@Kofod95 Neither of those worked Daniel
@Omar_one Thanks Omar but I get this error
PHP Parse error: syntax error, unexpected variable "$parameters"
Re: Show linked categories on catalog.php
Posted: Sun Nov 12, 2023 1:13 pm
by Omar_one
@tessthepup I edit my last post
I just try it on PHP 8.2 and 7.3 and it's working without error
Re: Show linked categories on catalog.php
Posted: Sun Nov 12, 2023 1:20 pm
by tessthepup
Omar_one wrote: ↑Sun Nov 12, 2023 1:13 pm
@tessthepup I edit my last post
I just try it on PHP 8.2 and 7.3 and it's working without error
@Omar_one
Still getting the same error
I am running php 8.0 if that makes any difference.
Could you check and see at your side?