Answer the question
In order to leave comments, you need to log in
How to detect all parents of an opencart 2.3 category?
Hey! I am getting the categories as an array. And I need, knowing the id of one category, to find out the id of the parent. And if there is also a 3 parent, then his too. I actually implemented it. But I have a constant appeal to the model. So is it possible or better not to do it? Though the request simplified.
foreach ($results2 as $result2) {
if ($result2['parent_id'] > 0) {
$category_link = $result2['parent_id'].'_'.$result2['category_id'];
$category_info = $this->model_catalog_category->getCategoryParent($result2['parent_id']);
if ($category_info['parent_id'] > 0) {
$category_link = $category_info['parent_id'].'_'.$result2['parent_id'].'_'.$result2['category_id'];
}
} else {
$category_link = $result2['category_id'];
}
$json['items']['categories'][] = array(
'name' => $result2['name'],
'href' => $this->url->link('product/category', 'path='.$category_link)
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question