To answer my own question, I decided to take the easy way out, and considering i would only have around 40 categories max, i don't think this should be much of a problem.
In my categories model class i created 2 static methods,
static function getCategoryWithChildren( $id = NULL ) {
$obj = new self;
$parent = $obj->getCategory( $id );
$list = array();
self::iterateCategoriesChildren($parent, $list);
return array_reverse($list);
}
static function iterateCategoriesChildren( $category, &$array ) {
if( $category->hasChildren() ) {
foreach( $category->getChildren() as $child ) {
self::iterateCategoriesChildren($child, $array);
}
}
$array[] = $category;
}
So pretty much this will get the parent and iterate all the children and assign each 1 to the flat array.
Then from my searchProducts method i just added a bit more under the $category check.
if( $category ) {
if( $this->settings->get('product_child_categories') ) {
$categories = Categories_model::getCategoryWithChildren($category);
foreach($categories as $_category) {
$qb ->orWhere( "p.category = " . $_category->getID() );
}
} else {
$qb ->andWhere( "p.category = ?1" )
->setParameter(1, $category);
}
}
May not be best or practical, but it works and does what I need for the time being.