Jump to content

[SOLVED] [PS 1.7] Get product's categories in ProductController


tumil
 Share

Recommended Posts

Hello!

I am trying to make some custom changes to breadcrumbs so I'm trying to edit the getBreadcrumbLinks() method in ProductController.php.

What I need is to get IDs from more categories than just the default one. The code which is in the current code is:

$categoryDefault = new Category($this->product->id_category_default, $this->context->language->id);

How can I achieve that? I tried to add a new element in the ProductControllerCore. An array which would take the necessary IDs from Product.php in the init() method. But that didn't go well and I've ran out of ideas how to do it properly.

I would appreciate any help,

thanks!

Edited by tumil (see edit history)

Share this post


Link to post
Share on other sites

Hi,

Use getCategories() function of the product class to get the all categories of the product like

$categories = $this->product->getCategories();

& after that loop through each category using the function which you mentioned to get the name & other details of the categories.

$categoryDefault = new Category($category_id, $this->context->language->id);

 

Share this post


Link to post
Share on other sites

  • 1 year later...

This is not working for me i have tried

 

$allcat = $prestashopProductClass->getCategories();

            foreach($allcat as $catdata){
                $categoryDefault = new Category($catdata, 1);
               print_r($categoryDefault);
            }
            exit;

 

any thoughts on this ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More