How to get sub-categories from parent category id in PrestaShop 1.7

In this post I am going to explain how to get sub-categories from parent category id in PrestaShop 1.7.

 

// Your Product id
$id_parent_category = 3;

// Fetch parent category
$categoryObj = new Category($id_parent_category);
// Validate category object
if (Validate::isLoadedObject($categoryObj)) {
	$categoryList = $categoryObj->getSubCategories($this->context->language->id);
	if ($categoryList && count($categoryList) > 0) {
		foreach ($categoryList AS $key => $val) {
			// get sub category id
			$id_category = $val['id_category'];

			// get sub category name
			$name = $val['name'];

			// get sub category description
			$description = $val['description'];
		}
	}
}

Thats it!

1 Comment

  1. Where to show this code, and front in which file

Leave a Reply

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