E
E
Elena2018-07-31 18:16:56
opencart
Elena, 2018-07-31 18:16:56

Opencart: How to display category images in the sidebar?

Good afternoon dear forum users!
I really need your help, because I do not understand where to go next.
In the standard module, it turns out without problems, but here the stopper ...
.../extension/module/category.tpl
Added to the right place:

<?php if ($category['image']) { ?>
<img src="<?php echo $category['image']; ?>"/>
<?php } else { ?>
<?php } ?>

There were similarities of torn, empty images in categories where there are pictures.
.../extension/module/category.php
Before
$data['categories_tree']
added
if ($category['image']) {
  $image = $this->model_tool_image->resize($category['image'], 20, 20);
} else {
  $image = $this->model_tool_image->resize('placeholder.png', 20,20);
}

Next, you need to add
'image' => $image
to $data['categories'][] = array(
I don’t have this. I do not understand where to add?
Here is the main part of the code:
if (isset($this->request->get['path'])) {
            $parts = explode('_', (string)$this->request->get['path']);
        } else {
            $parts = array();
        }

        if(!empty($parts)){
            $data['active'] = end($parts);
        }else{
            $data['active'] = 0;
        }

        $this->load->model('catalog/tree_cats');
        $this->load->model('tool/image');
        
        $data['categories'] = array();

        $categories = $this->model_catalog_tree_cats->getTreeCats();
        foreach($categories as $id => $category){
            $categories[$id]['href'] = $this->url->link('product/category', 'path=' . $category['category_id']);
        }

if ($category['image']) {
    $image = $this->model_tool_image->resize($category['image'], 20, 20);
} else {
    $image = $this->model_tool_image->resize('placeholder.png', 20,20);
}
        $data['categories_tree'] = $this->model_catalog_tree_cats->getMapTree($categories);

        return $this->load->view('extension/module/tree_cats', $data);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kafeuri1989, 2018-09-07
@kafeuri1989

forgot to add to the controller

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question