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?
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;
}
Code: Select all
$this->data['category'] = $this->getCategories(0);
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>
You can see @ http://www.vespamania.net/store (it is already under construction eh!)
www.beeshop.se
Starta webbshop, Starta e-butik, Starta e-handel
Enjoy!
PS. No warranties, of course

www.beeshop.se
Starta webbshop, Starta e-butik, Starta e-handel
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;
}
}
?>
Thanks!
Vimal.
www.beeshop.se
Starta webbshop, Starta e-butik, Starta e-handel
Code: Select all
$this->load->model('catalog/category');
$this->load->model('tool/seo_url');
Code: Select all
$this->language->load('common/header');
I might also suggest placing:
Code: Select all
$this->data['category'] = $this->getCategories(0);
Code: Select all
$this->render();
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!
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
In "catalog/controller/common/header.php", insert the following:-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.
Code: Select all
$this->data['text_category'] = $this->language->get('text_category');
Code: Select all
$_['text_category'] = 'Categories';
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>
To add in the information, you could try inserting the following into "catalog/controller/common/header.php":-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!
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']))
);
}
Code: Select all
$_['text_information'] = 'Information';
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>

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!
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.
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
Users browsing this forum: No registered users and 25 guests