Page 1 of 1

Little help with category images

Posted: Tue Nov 01, 2011 6:03 am
by dimko
Image

How can I put small thumbnails of category images before the name of the category? I know it's one line of code, but... :)

Thanks in advance.

Re: Little help with category images

Posted: Wed Nov 02, 2011 2:28 pm
by pagetopixel
In catalog/controller/product/category.php

around line 134 find

Code: Select all

$product_total = $this->model_catalog_product->getTotalProducts($data);
and paste below it

Code: Select all

if($result['image'])
                {
                    $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
                }
                else
                {
                    $image = '';
                }
Then below that you will see

Code: Select all

$this->data['categories'][] = array(
					'name'  => $result['name'] . ' (' . $product_total . ')',
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
				);
Change to

Code: Select all

$this->data['categories'][] = array(
					'name'  => $result['name'] . ' (' . $product_total . ')',
					'image'  => $image,
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
				);
Then in /catalog/view/theme/yourtheme/template/product/category.tpl

line 25 change

Code: Select all

<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
to

Code: Select all

<li>
      <?php if ($category['image']){ ?>
      <a href="<?php echo $category['href']; ?>">
      <img src="<?php echo $category['image']; ?>" title="<?php echo $category['name']; ?>" alt="<?php echo $category['name']; ?>" />
      </a>
      <?php } ?>
      <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
</li>

Then style away

Re: Little help with category images

Posted: Wed Nov 02, 2011 6:27 pm
by dimko
Thanks buddy, will try. I already combined some code from other posts, so I'll see what I will end up with :)

Re: Little help with category images

Posted: Mon Nov 07, 2011 11:48 am
by pagetopixel
Any luck?

Re: Little help with category images

Posted: Mon Nov 07, 2011 6:06 pm
by Script webshop
Nice one butt why use

Code: Select all

$this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
Why not

Code: Select all

$this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));

Re: Little help with category images

Posted: Thu Nov 10, 2011 4:35 am
by jimaras
Can we add the images in the same row?

Re: Little help with category images

Posted: Wed Nov 16, 2011 1:43 pm
by pagetopixel
jimaras wrote:Can we add the images in the same row?
You would do that with CSS. Unless I am not understanding your question.

Re: Little help with category images

Posted: Wed Nov 16, 2011 1:45 pm
by pagetopixel
Script webshop wrote:Nice one butt why use

Code: Select all

$this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
Why not

Code: Select all

$this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
Good call. I agree.

Re: Little help with category images

Posted: Fri Mar 02, 2012 6:32 am
by eleven28
pagetopixel wrote:In catalog/controller/product/category.php

around line 134 find

Code: Select all

$product_total = $this->model_catalog_product->getTotalProducts($data);
and paste below it

Code: Select all

if($result['image'])
                {
                    $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
                }
                else
                {
                    $image = '';
                }
Then below that you will see

Code: Select all

$this->data['categories'][] = array(
					'name'  => $result['name'] . ' (' . $product_total . ')',
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
				);
Change to

Code: Select all

$this->data['categories'][] = array(
					'name'  => $result['name'] . ' (' . $product_total . ')',
					'image'  => $image,
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
				);
Then in /catalog/view/theme/yourtheme/template/product/category.tpl

line 25 change

Code: Select all

<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
to

Code: Select all

<li>
      <?php if ($category['image']){ ?>
      <a href="<?php echo $category['href']; ?>">
      <img src="<?php echo $category['image']; ?>" title="<?php echo $category['name']; ?>" alt="<?php echo $category['name']; ?>" />
      </a>
      <?php } ?>
      <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
</li>

Then style away
Sweet! Worked fine for me in 1.5.1.3 (using Script webshop's minor change).

Thanks!

Re: Little help with category images

Posted: Sat Mar 24, 2012 12:29 am
by seito
Hy! Great code and much help! Thank you!

But sadly I must report an error with this in 1.5.2.1 OpenCart!

I used it with vQmode and It works as a charm in categories that DO have subcategories. But when opening a category/subcategory that does not have any (more) subcategories I get an error:

Notice: Undefined variable: result in /home/anteros/public_html/naravno-zdravje/vqmod/vqcache/vq2-catalog_controller_product_category.php on line 164

I opened my vq2-catalog_controller_product_category.php and looked at line 164 and surprise surprise, I get this new inserted block of code:

Code: Select all

$product_total = $this->model_catalog_product->getTotalProducts($data); 

if($result['image'])
                {
                    $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
                }
                else
                {
                    $image = '';
                }
where line 164 is: if($result['image'])

Does anybody have an idea what could be wrong? Why doesn't

Code: Select all

else
                {
                    $image = '';
define variable in case there is no subcategory?

Any help much appreciated!

Re: Little help with category images

Posted: Sat Mar 24, 2012 1:35 am
by Avvici
That else is only if there is no image being detected from the database. That's all.

Re: Little help with category images

Posted: Sat Mar 24, 2012 9:13 am
by seito
Oh, yes, thank you. Also, do you have any advice how to sort this problem? How to define variable in case there is no subcategory, so that I dont recieve error? Maybe some else if statement?

Re: Little help with category images

Posted: Tue Apr 03, 2012 1:07 pm
by mytindahan
is there a vqmod for this?

Re: Little help with category images

Posted: Tue Apr 24, 2012 6:52 pm
by itmanvn
mytindahan wrote:is there a vqmod for this?
http://www.opencart.com/index.php?route ... on_id=3907 ;D