Post by lukinhasb » Tue Jan 10, 2012 1:35 am

How to use this solution on OpenCart 1.5.1?

Code: Select all

if (substr_count($new_path, '_') < 1) {
    $children = $this->getCategories($result['category_id'], $new_path);
}
category.php

Code: Select all

<?php  
class ControllerModuleCategory extends Controller {
	protected function index() {
		$this->language->load('module/category');
		
    	$this->data['heading_title'] = $this->language->get('heading_title');
		
		if (isset($this->request->get['path'])) {
			$parts = explode('_', (string)$this->request->get['path']);
		} else {
			$parts = array();
		}
		
		if (isset($parts[0])) {
			$this->data['category_id'] = $parts[0];
		} else {
			$this->data['category_id'] = 0;
		}
		
		if (isset($parts[1])) {
			$this->data['child_id'] = $parts[1];
		} else {
			$this->data['child_id'] = 0;
		}
							
		$this->load->model('catalog/category');
		$this->load->model('catalog/product');
		
		$this->data['categories'] = array();
					
		$categories = $this->model_catalog_category->getCategories(0);
		
		foreach ($categories as $category) {
			$children_data = array();
			
			$children = $this->model_catalog_category->getCategories($category['category_id']);
			
			foreach ($children as $child) {
				$data = array(
					'filter_category_id'  => $child['category_id'],
					'filter_sub_category' => true
				);		
					
				$product_total = $this->model_catalog_product->getTotalProducts($data);
							
				$children_data[] = array(
					'category_id' => $child['category_id'],
					'name'        => $child['name'] . ' (' . $product_total . ')',
					'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])	
				);					
			}
			
			$data = array(
				'filter_category_id'  => $category['category_id'],
				'filter_sub_category' => true	
			);		
				
			$product_total = $this->model_catalog_product->getTotalProducts($data);
						
			$this->data['categories'][] = array(
				'category_id' => $category['category_id'],
				'name'        => $category['name'] . ' (' . $product_total . ')',
				'children'    => $children_data,
				'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
			);
		}
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/category.tpl';
		} else {
			$this->template = 'default/template/module/category.tpl';
		}
		
		$this->render();
  	}
}
?>
I don't know much PHP, I've tried to mess around with the code but couldn't find... I've discovered it has something to do with this part of the code though:

Code: Select all

if (isset($this->request->get['path'])) {
			$parts = explode('_', (string)$this->request->get['path']);
		} else {
			$parts = array();
		}
It seems this part controls when the category will expand, dtk much lol :crazy:

New member

Posts

Joined
Fri Sep 30, 2011 8:21 am

Post by Qphoria » Tue Jan 10, 2012 9:45 pm

What are you trying to do? You want all categories to be expanded?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by lukinhasb » Tue Jan 10, 2012 10:13 pm

Yes.

New member

Posts

Joined
Fri Sep 30, 2011 8:21 am

Post by arturhaddad » Wed Jan 11, 2012 7:20 am

I need this solution too.
Thanks,
tsefeiso

Newbie

Posts

Joined
Wed Jan 11, 2012 6:51 am

Post by Qphoria » Thu Jan 12, 2012 10:56 pm

Try this...

1. EDIT: catalog/view/theme/default/template/modele/category.tpl

2. FIND:

Code: Select all

<?php if ($category['children']) { ?>
          <ul>
3. REPLACE WITH:

Code: Select all

<?php if ($category['children']) { ?>
          <ul style="display:block">

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by lukinhasb » Fri Jan 13, 2012 1:04 am

It works, thanks a lot!!!!!!!!!!!

New member

Posts

Joined
Fri Sep 30, 2011 8:21 am

Post by avriukas » Wed Feb 01, 2012 9:49 pm

Hello Guys,
How to solve this problem on 1.5.1.3 ?

this code not enought -
<?php if ($category['children']) { ?>
<ul style="display:block">
when I do in this way - all what I get - is always show all subcategories in the tree, but this not resolve subcategory of subcategory not show problem

Subcategories of subcategory not shown in category tree :(
Desktops > TEST (TEST subcategory) SHOW)
Desktops > TEST > TEST2 (TEST2 subcategory- NOT SHOW)

Thanx alot !
Last edited by avriukas on Sat Feb 04, 2012 2:55 am, edited 1 time in total.

User avatar
New member

Posts

Joined
Wed Feb 01, 2012 9:45 pm

Post by wowo » Fri Feb 03, 2012 6:08 pm

is there any fix to this?

More than that - does sub-sub-category keyword work? It does not for me.
Keyowrds are shown ok for parent and subcategory, but not for sub-sub category.
Is that the feature or bug? Is there any solution to this?

Newbie

Posts

Joined
Wed May 26, 2010 6:29 am

Post by wowo » Fri Feb 03, 2012 6:44 pm

NO Sub-sub-category kewords.

It looks like it doesnt work for default intall too.

Can anyone confirm if this is working for them?

Newbie

Posts

Joined
Wed May 26, 2010 6:29 am

Post by wowo » Sun Feb 05, 2012 1:44 am

up.


anyone?

Newbie

Posts

Joined
Wed May 26, 2010 6:29 am

Post by wowo » Tue Feb 07, 2012 3:17 pm

up

Newbie

Posts

Joined
Wed May 26, 2010 6:29 am

Post by dmonco » Wed Feb 22, 2012 3:16 am

Hi! I brought categories and subcategories to the home page. You can see here http://technolife.net.ua
The problem that there are too much subcategories for some categories. I decided to slice them till 10 for subcategory. Could anyone help me?
P.S. I think I should use array_slice somehow but frankly my knowledges are very poor.

My file controller/categoryhome.php

Code: Select all

<?php
class ControllerModulecategoryhome4 extends Controller {
	protected $category_id = 0;
	protected $path = array();

	protected function index() {
		$this->language->load('module/categoryhome4');

    	$this->data['heading_title'] = $this->language->get('heading_title');

		$this->load->model('catalog/category');

		$this->load->model('tool/image');

		if (isset($this->request->get['path'])) {
			$this->path = explode('_', $this->request->get['path']);

			$this->category_id = end($this->path);
		}
		$url = '';
		$this->data['categoryhome4'] = $this->getCategories($this->config->get('categoryhome4_category'));

		$this->id = 'categoryhome4';

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/categoryhome4.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/categoryhome4.tpl';
		} else {
			$this->template = 'default/template/module/categoryhome4.tpl';
		}

		$this->render();
  	}
	                                                                //dymm
	protected function getCategories($parent_id, $current_path = '',$stop = false) {

		$categoryhome4 = array();
		$category_id = array_shift($this->path);

		$results = $this->model_catalog_category->getCategories($parent_id);

		$i=0;
		foreach ($results as $result) {

			if (!$current_path)
			{
				$new_path = $result['category_id'];
			}
			else
			{
				$new_path = $current_path . '_' . $result['category_id'];
			}




			if ($this->category_id == $result['category_id']) {
			$categoryhome4[$i]['href'] = $this->url->link('product/category', 'path=' . $new_path);

			} else {
			$categoryhome4[$i]['href'] =  $this->url->link('product/category', 'path=' . $new_path);
			}
			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}
			$categoryhome4[$i]['thumb'] = $this->model_tool_image->resize($image, 110, 110);
			$categoryhome4[$i]['name'] = $result['name'];
			//dymm  ------------------>
			if(!$stop)
				$categoryhome4[$i]['subcats'] = $this->getCategories($result['category_id'],$new_path,true);
			//dymm  <------------------

        $i++;

		}


		return $categoryhome4;
	}
}
?>

New member

Posts

Joined
Sun Jun 12, 2011 8:05 am
Location - Ukraine

Post by dmonco » Fri Feb 24, 2012 1:05 am

SO? Anybody knows??

New member

Posts

Joined
Sun Jun 12, 2011 8:05 am
Location - Ukraine

Post by dmonco » Sat Feb 25, 2012 12:02 pm

So, I resolved my problem by myself.
I added this

Code: Select all

 if ($stop && $i==10){
                                break;
                        }
after this

Code: Select all

 //dymm  ------------------>
                        if (!$stop)
                                $categoryhome4[$i]['subcats'] = $this->getCategories($result['category_id'], $new_path, true);
                        //dymm  <------------------
                        $i++;
Everything works fine.

New member

Posts

Joined
Sun Jun 12, 2011 8:05 am
Location - Ukraine

Post by mifzal.mufthi » Fri Aug 24, 2012 12:45 am

TAurus wrote:
WeNDoR wrote:please, coul someone tell me how to solve this problem ? I need the caregories to be expanded as default (if they have subcategories)
open catalog\controller\module\category.php
and replace

Code: Select all

if ($category_id == $result['category_id']) { 
				$children = $this->getCategories($result['category_id'], $new_path);
}
with

Code: Select all

//if ($category_id == $result['category_id']) { //hack to display all subcategories
				$children = $this->getCategories($result['category_id'], $new_path);
//}

I don't find the following code in my catalog\controller\module\category.php file

Code: Select all

    if ($category_id == $result['category_id']) {
                $children = $this->getCategories($result['category_id'], $new_path);
    }
however, I find the following code

Code: Select all

<?php  
class ControllerModuleCategory extends Controller {
	protected function index($setting) {
		$this->language->load('module/category');
		
    	$this->data['heading_title'] = $this->language->get('heading_title');
		
		if (isset($this->request->get['path'])) {
			$parts = explode('_', (string)$this->request->get['path']);
		} else {
			$parts = array();
		}
		
		if (isset($parts[0])) {
			$this->data['category_id'] = $parts[0];
		} else {
			$this->data['category_id'] = 0;
		}
		
		if (isset($parts[1])) {
			$this->data['child_id'] = $parts[1];
		} else {
			$this->data['child_id'] = 0;
		}
							
		$this->load->model('catalog/category');

		$this->load->model('catalog/product');

		$this->data['categories'] = array();

		$categories = $this->model_catalog_category->getCategories(0);

		foreach ($categories as $category) {
			$total = $this->model_catalog_product->getTotalProducts(array('filter_category_id'  => $category['category_id']));

			$children_data = array();

			$children = $this->model_catalog_category->getCategories($category['category_id']);

			foreach ($children as $child) {
				$data = array(
					'filter_category_id'  => $child['category_id'],
					'filter_sub_category' => true
				);

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

				$total += $product_total;

				$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'])
			);	
		}
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/category.tpl';
		} else {
			$this->template = 'default/template/module/category.tpl';
		}
		
		$this->render();
  	}

}
?>

Newbie

Posts

Joined
Thu Feb 25, 2010 9:01 pm

Post by SuporteOn » Wed Oct 24, 2012 11:13 pm

In Opencart 1.5.4.1, you do expand subcategories in CSS, by editing the file \catalog\view\theme\default\stylesheet\stylesheet.css.

Replaces this code (lines 742-744)

Code: Select all

.box-category > ul > li ul {
	display: none;
}
by this one

Code: Select all

.box-category > ul > li ul {
	display: block;
}
________________________________________________________________________________________________
<new> Opencart 1.5.4.1 Override is an Opencart extension designed by SuporteOn that allows you to override your entire store (Classes, Files and Folders, Controller, View, Templates, Model, CSS, JS) in a separate folder, without changing the original files. It is an alternative for vQmod. With this extension, you edit files directly with your favorite PHP Editor, as you always did.

User avatar
Newbie

Posts

Joined
Tue Jul 19, 2011 7:46 pm


Post by fontez » Sat Oct 27, 2012 7:18 am

i have in my code: (module category accordion)

category_accordion.php

Code: Select all

protected function loadCategories($parent_id, $current_path = '', $cid = '') {
		$category_id = array_shift($this->path);
		$this->getCategoriesFromdb($category_id);
		
		$results = $this->model_catalog_category->getCategories($parent_id);
		
		$ret_string = '';
		if ($results) { 
			if ($parent_id == 0) {
				$ret_string .= '<ul id="cat_accordion">'; 
			} else {
				$ret_string .= '<ul>'; 
			}
		}
		
		foreach ($results as $result) {	
			if (!$current_path) {
				$new_path = $result['category_id'];
			} else {
				$new_path = $current_path . '_' . $result['category_id'];
			}
			
			$ret_string .= '<li class="cid' . $result['category_id'] . '">';
			
			$children = '';
			$children = $this->loadCategories($result['category_id'], $new_path);
appear all categories and subcategories.

i try change:

Code: Select all

	$results = $this->model_catalog_category->getCategories($parent_id);
to:

Code: Select all

$results = $this->model_catalog_category->getCategories($category_id);
and error. how change for appear only sub-categories by category active?

Newbie

Posts

Joined
Sun May 20, 2012 6:52 am

Post by khantisari » Tue Nov 06, 2012 12:38 pm

Qphoria wrote:Try this...

1. EDIT: catalog/view/theme/default/template/modele/category.tpl

2. FIND:

Code: Select all

<?php if ($category['children']) { ?>
          <ul>
3. REPLACE WITH:

Code: Select all

<?php if ($category['children']) { ?>
          <ul style="display:block">
this is the simple solution for everyone

thank a lot for this

baju korea | baju import


Newbie

Posts

Joined
Fri Jul 13, 2012 5:16 pm

Post by vanderlay359 » Mon Nov 26, 2012 6:47 pm

Hi all,

This is something I want to do on my shop, i.e. list all catagories and sub catagories as default, however I can not find (the below) in the catalog\controller\module\category.php file:

if ($category_id == $result['category_id']) {
$children = $this->getCategories($result['category_id'], $new_path);
}


Please help.

Thanks in advance!

Newbie

Posts

Joined
Mon Nov 26, 2012 6:44 pm

Post by openinteractive » Tue Jan 08, 2013 2:41 am

I am using OC 1.5.2 and have found a pretty simple solution for controlling this.
If you look at the source code in your browser, you will see that the subcategories are in fact being output already, but are hidden with css on line 1093 of the stylesheet.css in this selector:

.box-category > ul > li ul{
display: none;
}

so simply changing display: none; to display:block; will make all subcategories visible like this:

.box-category > ul > li ul{
display: block;
}

and in my case, I only wanted to display one group of category's subcategories, which is easily done by leaving the existing line as is, but creating a second, more specific selector like this:

.box-category > ul > li:nth-of-type(2) ul{
display: block;
}

This will display the subcategories for the second category in your list of categories.but could be easily changed to display any others but changing the "2" value in the pseudo selector nth-of-type(2).
I hope this helps anyone looking for a similar solution.


Posts

Joined
Wed May 30, 2012 4:09 am
Who is online

Users browsing this forum: No registered users and 116 guests