Yii, function to show all products in a category hierarchy

Below is the function to show all products in a category hierarchy created in Model file ‘Categories’:

<?php

public function get_category_products($cat_id) {
if ($cat_rs = $this->find('category_parent_id=' . $cat_id)) {

return $this->get_category_products($cat_rs->category_id);
} else {

return $product_rs = Products::model()->findAll('product_category_id=' . $cat_id);
}
}

?>

Leave a comment

Your email address will not be published. Required fields are marked *