Wednesday, January 26, 2011

How to get current category id in product detail page

Sometimes we need current category id or other stuff in product detail page.
We can get current category id in product detail page by :
$this->getProduct()->getCategory()->getEntityId();

1 comment:

  1. This process encounter a problem, If it does not come from its parent category, then it returns nothing but error!!!
    So this is a good practice:
    $_product->getCategoryIds();

    and $catIds[0] this returns the parent category.

    ReplyDelete