Post by ekanga » Thu Dec 05, 2013 9:47 pm

Hello Guys,
version 1.5.5.1

Hi Guys moving to opencart so please understand: and I have been having an issue with this for 3 days now....any help would be appreciated.
I am trying to set my categories and subcategories as follow ( Note I don't care about the left menu or the header)
--> Accessoires
--> Accessoires --> Samsung
--> Accessoires --> Apple
--> Accessoires --> Nokia
--->Accessoires ---> Samsung--> ( Then the Samsung Products eg headphones, batteries...)
--->Accessoires ---> Samsung--> ( Then the Apple Products)
--->Accessoires ---> htc--> ( Then the htc Products)

The problem is my category home page.
When I click on 'Accessoires'( Header)
I would like opencart to show something like in my screenshot.( Force it to show the third sub sub category on home page when I click on the main category
At the moment when I click on the category it shows the sub cat. i hope it is clear.

to make things short would like to show all sub sub categories linked to the main category on my home page ( I don't want to have to click on the sub category to access them) please see screenshot.
Any help would be helpful, or maybe just direct me to an extension, I don't mind paying.

Thanx

Attachments

openc.jpg

please see screenshot - openc.jpg (43.76 KiB) Viewed 8663 times


Newbie

Posts

Joined
Thu Dec 05, 2013 9:12 pm

Post by inactiveaccount9912 » Fri Dec 06, 2013 12:01 am

Edit catalog/controller/product/category.php and find:

Code: Select all

foreach ($results as $result) {
				$data = array(
					'filter_category_id'  => $result['category_id'],
					'filter_sub_category' => true
				);
				
				$product_total = $this->model_catalog_product->getTotalProducts($data);				
				
				$this->data['categories'][] = array(
					'name'  => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
				);
			}
and replace with:

Code: Select all

foreach ($results as $result) {
			
				$subcats = array();
				
		        $subresults = $this->model_catalog_category->getCategories($result['category_id']);
				
		        foreach ($subresults as $subresult) {
				
				if ($subresult['image']) {
					$image = $this->model_tool_image->resize($subresult['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
				} else {
					$image = $this->model_tool_image->resize('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
				}
		        $subcats[] = array(
					'name'  => $subresult['name'],
					'image' => $image,
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . '_' . $subresult['category_id'] . $url)
				);
		        }		
				$this->data['categories'][] = array(
					'name'  => $result['name'],
					'subcats' => $subcats,
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
				);
			}
then edit catalog/view/theme/yourtheme/template/product/category.tpl find:

Code: Select all

 <?php if ($categories) { ?>
  <h2><?php echo $text_refine; ?></h2>
  <div class="category-list">
    <?php if (count($categories) <= 5) { ?>
    <ul>
      <?php foreach ($categories as $category) { ?>
      <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></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><a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>
      <?php } ?>
      <?php } ?>
    </ul>
    <?php } ?>
    <?php } ?>
  </div>
  <?php } ?>
and replace with:

Code: Select all

<?php if ($categories) { ?>
      <?php foreach ($categories as $category) { ?>
	   <h3 style="padding-bottom: 3px; border-bottom: 1px solid #ddd;"><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></h3>
	    <?php if ($category['subcats']) { ?>
         <div class="box-product">
          <?php foreach ($category['subcats'] as $subcat) { ?>
           <div>
	        <div class="image"><a href="<?php echo $subcat['href']; ?>"><img src="<?php echo $subcat['image']; ?>" title="<?php echo $subcat['name']; ?>" alt="<?php echo $subcat['name']; ?>" /></a></div>
	        <div class="name"><a href="<?php echo $subcat['href']; ?>"><?php echo $subcat['name']; ?></a></div>
	       </div>
          <?php } ?>
         </div>
        <?php } ?>
      <?php } ?>
  <?php } ?>

I think I might have misunderstood, my code is for displaing that way the subcategories on a category page, if you want on homepage you might find a module for that.

Expert Member

Posts

Joined
Fri May 14, 2010 2:36 am

Post by ekanga » Fri Dec 06, 2013 2:32 am

Thanx @florinsith, I believe I wasn't maybe clear enough: It is exactly for displaying on a category page, I will try what you suggested and givve you guys an update. again Thanx

Newbie

Posts

Joined
Thu Dec 05, 2013 9:12 pm

Post by inactiveaccount9912 » Fri Dec 06, 2013 3:14 am

Oh, then that should work fine for you, you might want to tweak the visual output a bit.

Expert Member

Posts

Joined
Fri May 14, 2010 2:36 am

Post by ekanga » Sat Dec 07, 2013 12:30 am

Just a quick update:
It worked fine ( Using the Sellya template)
But I have another issue now: images for ( sub sub categories are too big) please see screenshot, I believe it has to do with the changes to catalog/controller/product/category.php (everything works fine apart from that size!)
------catalog/controller/product/category.php before---------

Code: Select all

[code]foreach ($results as $result) {
				$data = array(
					'filter_category_id'  => $result['category_id'],
					'filter_sub_category' => true
				);
				
				$product_total = $this->model_catalog_product->getTotalProducts($data);		
				$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
				
				$this->data['categories'][] = array(
					'name'  => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
					'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url), 'thumb' => $image
				);
			}
[/code]
------catalog/controller/product/category.php after---------

Code: Select all

 foreach ($results as $result) {
         
            $subcats = array();
            
              $subresults = $this->model_catalog_category->getCategories($result['category_id']);
            
              foreach ($subresults as $subresult) {
            
            if ($subresult['image']) {
               $image = $this->model_tool_image->resize($subresult['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
            } else {
               $image = $this->model_tool_image->resize('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
            }
              $subcats[] = array(
               'name'  => $subresult['name'],
               'image' => $image,
               'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . '_' . $subresult['category_id'] . $url)
            );
              }      
            $this->data['categories'][] = array(
               'name'  => $result['name'],
               'subcats' => $subcats,
               'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
            );
         }
-------------------------------------------------
It might be a quick fix or extension fix i don't really mind...really sorry guys but again guys thanx for your understanding especially @florinsith

Attachments

openc2.jpg

openc2.jpg (79.69 KiB) Viewed 8632 times


Newbie

Posts

Joined
Thu Dec 05, 2013 9:12 pm

Post by inactiveaccount9912 » Sat Dec 07, 2013 3:55 am

In this part of the modification:

Code: Select all

 if ($subresult['image']) {
               $image = $this->model_tool_image->resize($subresult['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
            } else {
               $image = $this->model_tool_image->resize('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
            }
you can input direct image size like below:

Code: Select all

 if ($subresult['image']) {
               $image = $this->model_tool_image->resize($subresult['image'], 100, 100);
            } else {
               $image = $this->model_tool_image->resize('no_image.jpg', 100, 100);
            }
now I change it to 100 by 100 px, you can change the numbers.

Expert Member

Posts

Joined
Fri May 14, 2010 2:36 am

Post by ekanga » Sat Dec 07, 2013 10:35 am

thanx! worked perfectly. This topic can be closed. Thank you

Newbie

Posts

Joined
Thu Dec 05, 2013 9:12 pm

Post by scottie5689 » Thu Jan 21, 2016 1:01 am

This worked perfectly for my situation, thank you! I was wondering if there was a conditional statement that could be added to exclude certain pages from showing the subcats. Thank you.

Newbie

Posts

Joined
Thu Jan 21, 2016 12:59 am

Post by fathima » Sat Aug 20, 2016 8:03 pm

Hi,

I am looking similar design can you plz email us complete source code

Newbie

Posts

Joined
Mon Jul 18, 2016 12:55 pm
Who is online

Users browsing this forum: No registered users and 19 guests