Hi so I have a hierarchy of categories, the parent of which is Ranges
Each range may have subcategories several levels deep.
What I need to do is check to see if the current product belongs to a category which is in ranges.
For example the product may be in several categories as follows:
Tables > Coffee Tables
Chairs > Comfy Chairs
Ranges > Range Name > Range
If any category is found which is an ancestor (no matter how many levels deep) or ranges, I want the logic to return true.
Here's what I have so far...
<?php
$_product = Mage::registry('current_product');
$categoryIds = $_product->getCategoryIds();
if(count($categoryIds) ){
foreach ($categoryIds as $cat) {
$_category = Mage::getModel('catalog/category')->load($cat);
if($_category->getParentId() == '683') {
$_catname = $_category->getName();
$_catimg = $_category->getImageUrl();
$_caturl = $_category->getUrl();
?>
<div class="range">
<img src="<?php echo $_catimg;?>" alt="Part of the <?php echo $_catname;?> range" />
<span>
Part of the
<span>
<?php echo $_catname;?>
</span>
Range<br />
<a class="btn btn-blue btn-large" href="<?php echo $_caturl;?>">
View All
</a>
</span>
</div>
<?php }
}
}?>
I think the problem is that getParentId only refers to the immediate parent, I want this to return true if 683 is an ancestor on any level.
Hope that makes sense,