Post by zitter » Tue Sep 29, 2009 8:06 am

Hi, how to put cats and subcats on header menu as in http://www.vcscleaningsupplies.com.au/ ?
I've tried to search an answer in this forum, but only useful thread (I mean this: http://forum.opencart.com/viewtopic.php ... 9&start=30 ) has broken links.

Can someone help me, please?

Newbie

Posts

Joined
Tue Sep 29, 2009 7:52 am

Post by zitter » Wed Sep 30, 2009 4:52 am

I've solved in this way:
1. Open catalog/controller/common/header.php adding these lines of code:

Code: Select all

protected function getCategories($parent_id, $current_path = '') {
                $output = '';

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

                if ($results) {
                        $output .= '<ul>';
        }

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

                        $output .= '<li>';

                        $children = '';

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

                        if ($this->category_id == $result['category_id']) {
                                $output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '"><b>' . $result['name'] . '</b></a>';
                        } else {
                                $output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '">' . $result['name'] . '</a>';
                        }

                $output .= $children;

                $output .= '</li>';
                }

                if ($results) {
                        $output .= '</ul>';
                }
        return $output;
        }
2. in function index() in the same file add this code:

Code: Select all

   $this->data['category'] = $this->getCategories(0);
3. We can access to the list of categories from view using $category var. I've done in this way. In catalog/view/theme/{your_theme_name_here}/template/common/header.tpl I've rewritten "div5" div in this way:

Code: Select all

 <div class="div5">
  <ul id="nav">
  <li><a href="<?php echo $home; ?>"><img src="catalog/view/theme/vespamania/image/icon_home.png" alt="" /><?php echo $text_home; ?></a></li>
  <!--<li><a href="<?php echo $special; ?>"><img src="catalog/view/theme/vespamania/image/icon_special.png" alt="" /><?php echo $text_special; ?></a></li>-->
  <li><a href="<?php echo $home;?>"><img src="catalog/view/theme/vespamania/image/icon_home.png" alt="" /><?php echo "Prodotti"; ?></a>
  <?php echo $category;?>
  </li>
  <?php if (!$logged) { ?>
    <li><a href="<?php echo $login; ?>"><img src="catalog/view/theme/vespamania/image/icon_login.png" alt="" /><?php echo $text_login; ?></a></li>
    <?php } else { ?>
    <li><a href="<?php echo $logout; ?>"><img src="catalog/view/theme/vespamania/image/icon_logout.png" alt="" /><?php echo $text_logout; ?></a></li>
    <?php } ?>
    <li><a href="<?php echo $account; ?>"><img src="catalog/view/theme/vespamania/image/icon_account.png" alt="" /><?php echo $text_account; ?></a></li></ul></div>
And I've styled with http://www.kriesi.at/archives/create-a- ... via-jquery

You can see @ http://www.vespamania.net/store (it is already under construction eh!)

Newbie

Posts

Joined
Tue Sep 29, 2009 7:52 am

Post by vimal » Fri Oct 02, 2009 3:45 am

Very nice work. I am also impressed by another thing. How did you manage to get the search and language in 2 separate boxes? I have been trying for some time now but it never works. Do you mind sharing that too?

www.beeshop.se
Starta webbshop, Starta e-butik, Starta e-handel


Active Member

Posts

Joined
Wed Aug 26, 2009 8:54 am
Location - Sweden

Post by zitter » Fri Oct 02, 2009 8:28 pm

OK, I will post ASAP :)

Newbie

Posts

Joined
Tue Sep 29, 2009 7:52 am

Post by zitter » Fri Oct 02, 2009 8:44 pm

I remember that I found Search Box module in the download section of this site. I've create langauge box module using same technique. Both are in posted attachments.
Enjoy!

PS. No warranties, of course :)

Newbie

Posts

Joined
Tue Sep 29, 2009 7:52 am

Post by vimal » Fri Oct 02, 2009 10:22 pm

Thanks a lot! I will try and see if it works for me!

www.beeshop.se
Starta webbshop, Starta e-butik, Starta e-handel


Active Member

Posts

Joined
Wed Aug 26, 2009 8:54 am
Location - Sweden

Post by vimal » Tue Oct 06, 2009 9:12 pm

Hi I am working on the category and sub category to be in the nav bar. I get an error as below.

Fatal error: Call to a member function getCategories() on a non-object in C:\Server\xampp\htdocs\ezebutik\catalog\controller\common\header.php on line 44

The code in my catalog\controller\common\header.php is as follows..line 44 is $results = $this->model_catalog_category->getCategories($parent_id);

Code: Select all

<?php   
class ControllerCommonHeader extends Controller {
	protected function index() {
		$this->language->load('common/header');
	    	
		$this->data['store'] = $this->config->get('config_store');
		
		if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on')) {
			$this->data['logo'] = HTTPS_IMAGE . $this->config->get('config_logo');
		} else {
			$this->data['logo'] = HTTP_IMAGE . $this->config->get('config_logo');
		}
		
		$this->data['text_home'] = $this->language->get('text_home');
		$this->data['text_special'] = $this->language->get('text_special');
    	$this->data['text_account'] = $this->language->get('text_account');
    	$this->data['text_login'] = $this->language->get('text_login');
    	$this->data['text_logout'] = $this->language->get('text_logout');
    	$this->data['text_cart'] = $this->language->get('text_cart'); 
    	$this->data['text_checkout'] = $this->language->get('text_checkout');

		$this->data['home'] = $this->url->http('common/home');
		$this->data['special'] = $this->url->http('product/special');
    	$this->data['account'] = $this->url->https('account/account');
		$this->data['logged'] = $this->customer->isLogged();
		$this->data['login'] = $this->url->https('account/login');
		$this->data['logout'] = $this->url->http('account/logout');
    	$this->data['cart'] = $this->url->http('checkout/cart');
		$this->data['checkout'] = $this->url->https('checkout/shipping');

		$this->id       = 'header';
		$this->template = $this->config->get('config_template') . 'common/header.tpl';
		$this->children = array(
			'common/language',
			'common/search'
		);
		
    	$this->render();
		$this->data['category'] = $this->getCategories(0);
	}	
    protected function getCategories($parent_id, $current_path = '') {
                    $output = '';
					
                    $results = $this->model_catalog_category->getCategories($parent_id);

                    if ($results) {
                            $output .= '<ul>';
            }

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

                            $output .= '<li>';

                            $children = '';

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

                            if ($this->category_id == $result['category_id']) {
                                    $output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '"><b>' . $result['name'] . '</b></a>';
                            } else {
                                    $output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '">' . $result['name'] . '</a>';
                            }

                    $output .= $children;

                    $output .= '</li>';
                    }

                    if ($results) {
                            $output .= '</ul>';
                    }
            return $output;
            }

}
?>
Please help me with this.
Thanks!
Vimal.

www.beeshop.se
Starta webbshop, Starta e-butik, Starta e-handel


Active Member

Posts

Joined
Wed Aug 26, 2009 8:54 am
Location - Sweden

Post by fido-x » Tue Oct 06, 2009 9:54 pm

Insert the following:-

Code: Select all

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

Code: Select all

$this->language->load('common/header');
at the start of the file.

I might also suggest placing:

Code: Select all

$this->data['category'] = $this->getCategories(0);
above:

Code: Select all

$this->render();
at the end of the index() function.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by vimal » Thu Oct 08, 2009 3:48 pm

Thanks Fido-x!

It works now. How can I get the name i.e. Category to be pulled out with code instead of writing category in the header.tpl. Problem is that I use 2 languages on my site and hence categories will be wrong in the other language.

Another question..sorry don't kill me..how can I add information on top too? I checked the code for information..I think also in catalog/controller/module/information.php file. It doesnt have "protected function getInformation($parent_id, $current_path = '') " like in category.php there is "protected function getCategories($parent_id, $current_path = '') " . I know I sound silly but my knowledge of php is 0!

www.beeshop.se
Starta webbshop, Starta e-butik, Starta e-handel


Active Member

Posts

Joined
Wed Aug 26, 2009 8:54 am
Location - Sweden

Post by fido-x » Thu Oct 08, 2009 4:54 pm

vimal wrote:Thanks Fido-x!

It works now. How can I get the name i.e. Category to be pulled out with code instead of writing category in the header.tpl. Problem is that I use 2 languages on my site and hence categories will be wrong in the other language.
In "catalog/controller/common/header.php", insert the following:-

Code: Select all

$this->data['text_category'] = $this->language->get('text_category');
Then, in "catalog/language/english/common/header.php", add the following:-

Code: Select all

$_['text_category'] = 'Categories';
Do the same for the other language.

Then, in "catalog/view/theme/TEMPLATE_NAME/template/common/header.tpl", insert:

Code: Select all

<li><img src="catalog/view/theme/<?php $tpl = explode('/', $this->template); echo $tpl[0]; ?>/image/icon_category.png" alt="" /><?php echo $text_category; ?></li>
Note: this will not provide a "clickable" link for the categories in the header.
Another question..sorry don't kill me..how can I add information on top too? I checked the code for information..I think also in catalog/controller/module/information.php file. It doesnt have "protected function getInformation($parent_id, $current_path = '') " like in category.php there is "protected function getCategories($parent_id, $current_path = '') " . I know I sound silly but my knowledge of php is 0!
To add in the information, you could try inserting the following into "catalog/controller/common/header.php":-

Code: Select all

$this->data['text_information'] = $this->language->get('text_information');
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformations();
$this->data['informations'] = array();
foreach ($information_info as $result) {
	$this->data['informations'][] = array(
       		'title' => $result['title'],
    		'href'  => $this->model_tool_seo_url->rewrite($this->url->http('information/information&information_id=' . $result['information_id']))
	);
}
Then, in the relevant language file(s), insert:

Code: Select all

$_['text_information'] = 'Information';
And, in your template file, insert the following:- EDIT

Code: Select all

<li><img src="catalog/view/theme/<?php $tpl = explode('/', $this->template); echo $tpl[0]; ?>/image/icon_information.png" alt="" /><?php echo $text_information; ?>
<ul>
  <?php foreach ($informations as $information) { ?>
    <li><a href="<?php echo $information['href']; ?>"><?php echo $information['title']; ?></a></li>
  <?php } ?>
</ul></li>
Don't know if it will work, but it looks like it should ;D

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by ocfreak » Mon Nov 23, 2009 7:15 pm

Hi everyone,
I have a question regarding code above, can I apply it for opencart 1.3.4?
I just installed opencart 1.3.4 and implemented code above, but it seem doesn't work.
I'm not a coder. Please help me, I've been searching in other threads. But still no solution.
Thanks.

Newbie

Posts

Joined
Sat Nov 21, 2009 11:15 pm

Post by RhiAtTantrwm » Tue Mar 02, 2010 10:18 pm

Help! I'm trying to do exactly what you have done, so I tried with this code and I get this:

Parse error: syntax error, unexpected T_PROTECTED ...(in header.php)

Can anyone advise me how to tackle trying to get this kind of functionality? - I want my categories to become menu items as on play.com/amazon.com, but my brain is completely fried trying to work it out! I keep getting ALL categories up including sub-cats and I can't work out how to seperate them for my menu... I tried this code but got the error described above and I've run out of brain power today to figure it out!

I've been in every file I can find with "header" or "category" in the filename and although I do understand the MVC framework, I'm still having trouble trying to figure out the connections between them all. My PHP is pretty basic and is being tested to it's limits! Any advice/previous examples/forum links welcome - this is the most relevant thread my search pulled up but I'm sure someone must have tried a similar thing before?

Thanks

Newbie

Posts

Joined
Tue Mar 02, 2010 8:19 pm

Post by ryannelson » Mon Mar 15, 2010 12:25 pm

I'm trying to figure this out as well for 1.4.3. Does anyone know how to do this?

Newbie

Posts

Joined
Sat Mar 13, 2010 12:35 pm

Post by dramony » Fri Apr 09, 2010 4:04 pm

will this work on OC 1.3.2?

User avatar
Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm
Who is online

Users browsing this forum: No registered users and 20 guests