K
K
kamisarlapsha2019-05-26 00:04:02
PHP
kamisarlapsha, 2019-05-26 00:04:02

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)
          );
        }

I need the path to a category to consist of all its parents. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zoozag, 2019-05-27
@zoozag

I need the path to a category to consist of all its parents.

Install seo_pro and you won't have to reinvent the wheel
Well, or look at how the path for the category is built in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question