PrestaCraft on Facebook

Please like our page on Facebook to get notifications about new tutorials :)


PrestaCraft

PrestaCraft on Facebook

Please like our page on Facebook to get notifications about new tutorials :)


PrestaCraft

I present you a nice snippet which will give you a full category path, based on category ID.

You can put this code in your module or wherever you need. There is one parameter required and it is (of course) category ID.

1. First of all define a class property. 2. Then copy this function to your class.

You can see there we are checking if $id < 2. That's because category IDs that are lower than 2 are PrestaShop root ones, which we don't need in our tree and shouldn't be used anywhere.

The lowest category for us has ID 2 and is "Home category".

If you want to display "Home category" in category path, remove array_pop($this->categoryArray); line.

That's all. As simple as that.

Thanks for reading 🙂

Leave a comment

Your email address will not be published.

Be the first to post a comment!

Leave a comment

Your email address will not be published.