Skip to content

Instantly share code, notes, and snippets.

@herveguetin
Created May 20, 2014 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herveguetin/217fcc05a03d2aef9dd5 to your computer and use it in GitHub Desktop.
Save herveguetin/217fcc05a03d2aef9dd5 to your computer and use it in GitHub Desktop.
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