Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Retrieve first active category of product in Magento
<?php
// $product must be an instance of Mage_Catalog_Model_Product
$productCategoryIds = $product->getCategoryIds();
$productCategory = Mage::getModel('catalog/category')->getCollection()
->addAttributeToFilter('is_active', true)
->addAttributeToFilter('entity_id', array('in' => $productCategoryIds))
->setPageSize(1)
->getFirstItem();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment