Skip to content

Instantly share code, notes, and snippets.

@andrew-smart
Created September 4, 2015 18:19
Show Gist options
  • Select an option

  • Save andrew-smart/c0b59104028d0ef4e86b to your computer and use it in GitHub Desktop.

Select an option

Save andrew-smart/c0b59104028d0ef4e86b to your computer and use it in GitHub Desktop.
Get product categories under a particular parent (Magento 1.x)
<?php
function getSubs($product, $parentId)
{
$cats = array();
// get the product category ids
$ids = $product->getCategoryIds();
// get all children of the parent $catId
$children = Mage::getModel('catalog/category')->getCategories($parentId, 0, false, true);
foreach ($children as $category) {
// if the child is in the product categories,
// include it
if (in_array($category->getId(), $ids)) {
$cats[] = $category;
}
}
return $cats;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment