Post by dimko » Tue Nov 01, 2011 6:03 am

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.

Using OpenCart v1.5.1.3


Active Member

Posts

Joined
Sun Sep 25, 2011 2:10 am

Post by pagetopixel » Wed Nov 02, 2011 2:28 pm

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
Last edited by pagetopixel on Thu Nov 17, 2011 1:16 pm, edited 1 time in total.

Newbie

Posts

Joined
Tue Oct 04, 2011 1:52 pm

Post by dimko » Wed Nov 02, 2011 6:27 pm

Thanks buddy, will try. I already combined some code from other posts, so I'll see what I will end up with :)

Using OpenCart v1.5.1.3


Active Member

Posts

Joined
Sun Sep 25, 2011 2:10 am

Post by pagetopixel » Mon Nov 07, 2011 11:48 am

Any luck?

Newbie

Posts

Joined
Tue Oct 04, 2011 1:52 pm

Post by Script webshop » Mon Nov 07, 2011 6:06 pm

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

http://www.4youshop.nl
Image


User avatar
New member

Posts

Joined
Thu Jul 29, 2010 10:23 pm

Post by jimaras » Thu Nov 10, 2011 4:35 am

Can we add the images in the same row?

http://e-kreopoleio.com/


Active Member

Posts

Joined
Thu Sep 15, 2011 1:45 am

Post by pagetopixel » Wed Nov 16, 2011 1:43 pm

jimaras wrote:Can we add the images in the same row?
You would do that with CSS. Unless I am not understanding your question.

Newbie

Posts

Joined
Tue Oct 04, 2011 1:52 pm

Post by pagetopixel » Wed Nov 16, 2011 1:45 pm

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.

Newbie

Posts

Joined
Tue Oct 04, 2011 1:52 pm

Post by eleven28 » Fri Mar 02, 2012 6:32 am

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!

User avatar
Newbie

Posts

Joined
Fri Jan 27, 2012 6:41 am
Location - Australia

Post by seito » Sat Mar 24, 2012 12:29 am

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!

User avatar
Newbie

Posts

Joined
Sat Mar 24, 2012 12:12 am

Post by Avvici » Sat Mar 24, 2012 1:35 am

That else is only if there is no image being detected from the database. That's all.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by seito » Sat Mar 24, 2012 9:13 am

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?

User avatar
Newbie

Posts

Joined
Sat Mar 24, 2012 12:12 am

Post by mytindahan » Tue Apr 03, 2012 1:07 pm

is there a vqmod for this?

http://www.mytindahan.net


New member

Posts

Joined
Mon Sep 27, 2010 1:28 pm

Post by itmanvn » Tue Apr 24, 2012 6:52 pm

mytindahan wrote:is there a vqmod for this?
http://www.opencart.com/index.php?route ... on_id=3907 ;D

Newbie

Posts

Joined
Thu Jan 13, 2011 12:57 pm
Who is online

Users browsing this forum: No registered users and 35 guests