I have an URL from which I would like to get the categories. I have this: /hats/trucker-hats/hat1.html/ which is a product detail page.
I need to retrieve the categories, which are "hats" and "trucker-hats". I tried using
$product->getCategoryIds() and looked through the IDs, the categories are there, but never at the same index, is there a way to retrieve these?