Page 1 of 1

How to put images in sub-categories

Posted: Wed Jul 09, 2014 2:58 pm
by vinsbg
Hi,
firstly I want to apologize if I'm in wrong forum.
I just started with Opencart and my version is 1.5.6, also I have some background with php but not so much .. I trying to put images in sub-categories where is Refine Search. I want to have image above the text. Can someone help me how to do this?

So far I've made changes in my catalog\controller\module\category.php from this

Code: Select all

$children_data[] = array(
	'category_id' => $child['category_id'],
	'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
	'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])	
	);		
}
$this->data['categories'][] = array(
	'category_id' => $category['category_id'],
	'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
	'children'    => $children_data,
	'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
);
to this ( I've added 'image' => $category['image'], )

Code: Select all

$children_data[] = array(
	'category_id' => $child['category_id'],
	'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
        'image'       => $category['image'],
	'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])	
);		
}
$this->data['categories'][] = array(
	'category_id' => $category['category_id'],
	'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
        'image'       => $category['image'],
        'children'    => $children_data,
	'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
);
In catalog\view\theme\MYTHEME\template\product\category.tpl , I've added <img src="http://localhost/image/data/models/<?php echo $categories['image']; ?>" width="100"/> here

Code: Select all

<div class="category-list">

    <?php if (count($categories) <= 5) { ?>
    <ul>
      <?php foreach ($categories as $category) { ?>

      <li>
          <img src="http://localhost/image/data/models/<?php echo $categories['image']; ?>" width="100"/>
          <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
          <hr>
      </li>

      <?php } ?>
    </ul>
    <?php } else { ?>
    <?php for ($i = 0; $i < count($categories);) { ?>
    <ul>
      <?php $j = $i + ceil(count($categories) / 4); ?>
      <?php for (; $i < $j; $i++) { ?>
      <?php if (isset($categories[$i])) { ?>
      <li>
          <img src="http://localhost/image/data/models/<?php echo $categories['image']; ?>" width="100"/>
          <a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>

      <?php } ?>
      <?php } ?>
    </ul>
    <?php } ?>
    <?php } ?>
  </div>
This is the result so far on the attached image. Can someone help me?
p.s. Sorry for my English.

Re: How to put images in sub-categories

Posted: Wed Jul 09, 2014 9:12 pm
by labeshops
I use this mod that does exactly what you are trying to do: http://www.opencart.com/index.php?route ... n_id=12373

Re: How to put images in sub-categories

Posted: Wed Jul 09, 2014 9:18 pm
by vinsbg
I have 5-6 level deep menu -> category - sub category - sub-sub-sub etc.. I trying to show images for every next level sub-category and as I can see from description this extension wont help me or I'm wrong?
- A specific category: show its subcategories
- (ROOT): Show all top-level categories
- (CURRENT): In Category view, show the subcategories of the CURRENT category (similar to "Refine Search")

Re: How to put images in sub-categories

Posted: Wed Jul 09, 2014 9:35 pm
by labeshops
Current would show the current levels subcategories, so even if you have multiple levels, installing it on your category page set to <current> would give you what you are after I think, like:

Main Category - Current displays subcats Level 1
- Level 1 sub - current displays subcats level 2
- level 2 sub - current displays subcats level 3
- level 3 sub - current displays subcats level 4

etc.

I haven't tested this since I never have more than 1 level of subcats, but judging by how it works on mine, it should work as I describe above.

Re: How to put images in sub-categories

Posted: Wed Jul 09, 2014 9:45 pm
by vinsbg
Ok, I will have this in mind and will ask the developer of the extension.
But I think I'm almost done with this and will try a little bit more to figured out why the images are missing.

Re: How to put images in sub-categories

Posted: Wed Jul 09, 2014 11:43 pm
by grgr
Click the see all button below. There is a free little mod I did for refine search images in there somewhere.

Re: How to put images in sub-categories

Posted: Thu Jul 10, 2014 1:04 am
by vinsbg
I've made it. It was my fault :(
I've been edited controller/module/category.php instead of controller/product/category.php .

Re: How to put images in sub-categories

Posted: Mon Apr 25, 2022 9:39 pm
by paulfeakins