Show linked categories on catalog.php

Open to all! Ask other shopowners for help.
User avatar
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

Post 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
You do not have the required permissions to view the files attached to this post.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
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

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
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

Post 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 :?:
User avatar
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

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
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

Post 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
User avatar
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

Post 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

Code: Select all

if($product)
- I don't think it's likely that the variable contains anything it shouldn't, but I might be wrong...

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
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

Post 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
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.
User avatar
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

Post 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"
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

Post 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
User avatar
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

Post 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?


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply