Created
September 4, 2015 18:19
-
-
Save andrew-smart/c0b59104028d0ef4e86b to your computer and use it in GitHub Desktop.
Get product categories under a particular parent (Magento 1.x)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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