Show linked categories on catalog.php
- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Show linked categories on catalog.php
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
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
You do not have the required permissions to view the files attached to this post.
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Show linked categories on catalog.php
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:
Add a meaningful class instead of "style" and add explanation in text (preferably as a constant defined in a language-file) as needed.
//Daniel
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'))];
}
}
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Show linked categories on catalog.php
@Kofod95Kofod95 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:Add a meaningful class instead of "style" and add explanation in text (preferably as a constant defined in a language-file) as needed.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'))]; } }
//Daniel
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'))];Code: Select all
if (class_exists($product && ($product Instanceof Product))) $parameters['contents'][] = ['class' => 'style', 'text' => $GLOBALS['Categories']::draw_breadcrumbs($product->get('categories'))];Now there are no errors but the categories do not show
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Show linked categories on catalog.php
This looks wrong
class_exists should only check something that could actually be a class (I think)
Maybe something like:
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
Code: Select all
if (class_exists($product && ($product Instanceof Product)))Maybe something like:
Code: Select all
if (class_exists(Product) && $product && ($product Instanceof Product))
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Show linked categories on catalog.php
@Kofod95Kofod95 wrote: ↑Sat Nov 11, 2023 4:31 pm This looks wrongclass_exists should only check something that could actually be a class (I think)Code: Select all
if (class_exists($product && ($product Instanceof Product)))
Maybe something like: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)Code: Select all
if (class_exists(Product) && $product && ($product Instanceof Product))
//Daniel
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
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Show linked categories on catalog.php
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
The Product class should exists, so "class_exists" should not be needed.
If it still fails, try with just
Code: Select all
if($product)//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
-
Omar_one
- Senior Contributor
- Posts: 679
- Joined: Fri Oct 25, 2019 5:06 pm
- Phoenix Version: v1.0.8.16
- Has thanked: 100 times
- Been thanked: 56 times
Re: Show linked categories on catalog.php
@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'))];
}
}
You do not have the required permissions to view the files attached to this post.
Last edited by Omar_one on Sun Nov 12, 2023 1:11 pm, edited 1 time in total.
- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Show linked categories on catalog.php
@Kofod95 Neither of those worked DanielOmar_one wrote: ↑Sun Nov 12, 2023 11:42 am @tessthepup try this ,, thank you @Kofod951212.JPGCode: 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'))]; } }
@Omar_one Thanks Omar but I get this error
PHP Parse error: syntax error, unexpected variable "$parameters"
-
Omar_one
- Senior Contributor
- Posts: 679
- Joined: Fri Oct 25, 2019 5:06 pm
- Phoenix Version: v1.0.8.16
- Has thanked: 100 times
- Been thanked: 56 times
Re: Show linked categories on catalog.php
@tessthepup I edit my last post
I just try it on PHP 8.2 and 7.3 and it's working without error
I just try it on PHP 8.2 and 7.3 and it's working without error
- tessthepup
- Certified Developer
- Posts: 383
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Show linked categories on catalog.php
@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?