If anyone has implemented the category sorting fix mentioned earlier http://code.google.com/p/open-cart/issues/detail?id=20 and either of the category menu changes I suggested then you can get the categories to display in the correct order by replacing catalog\extension\module\category.php with the attached version. A picture of the menu is also attached for comparison with the previous result.
Hallo Bruce!
You've been really so kind to link me your solution to view categories and its subcategories. And it works well!
Unfortunately I have another problem: i would like to see only the category with its first subcategory (and not all the others)....
Taking your image "category menu sorted" as example, i would like to see Category 2, Category 2.1, Category 2.2, but NOT Category 2.2.1/2.2.2/ ecc.
Can you (or somenone) help me to find the solution? I tried to modify the code... but with no results....
You've been really so kind to link me your solution to view categories and its subcategories. And it works well!

Unfortunately I have another problem: i would like to see only the category with its first subcategory (and not all the others)....
Taking your image "category menu sorted" as example, i would like to see Category 2, Category 2.1, Category 2.2, but NOT Category 2.2.1/2.2.2/ ecc.
Can you (or somenone) help me to find the solution? I tried to modify the code... but with no results....
Hi, and thanks. I am glad you got some value from this.
The indent value has the information that you need to filter with. The change you need to make to \catalog\extension\module\category.php is shown below.
The indent value has the information that you need to filter with. The change you need to make to \catalog\extension\module\category.php is shown below.
Code: Select all
foreach ($flatList as $node)
{
$tag = $node->getTag();
if ($tag['indent'] < 2) // 2 is the maximum category depth to display
$new_category_data[] = $tag;
}
$view->set('categories', $new_category_data);
Hi Bruce!! You're really very helpful and very kind.
I thought it was the config.php but i really didn't know how to manage it
I've tried to change the code as you have shown but it doesn't work......
I paste my code (that actually is yours!!) so you can see where i do wrong......
if i replace
with
it gives me no categories, no subcategories and some errors.... sure i'm doing something wrong.... 
waiting for your precious reply
I thought it was the config.php but i really didn't know how to manage it

I've tried to change the code as you have shown but it doesn't work......
I paste my code (that actually is yours!!) so you can see where i do wrong......
Code: Select all
<?php
class ModuleCategory extends Controller {
function fetch() {
$config =& $this->locator->get('config');
$database =& $this->locator->get('database');
$language =& $this->locator->get('language');
$url =& $this->locator->get('url');
if ($config->get('category_status')) {
$language->load('extension/module/category.php');
$view = $this->locator->create('template');
$view->set('heading_title', $language->get('heading_title'));
$category_data = array();
$results = $database->getRows("select c.category_id, cd.name, c.parent_id, c.path from category c left join category_description cd on (c.category_id = cd.category_id) where cd.language_id = '" . (int)$language->getId() . "' order by c.path");
foreach ($results as $result) {
$category_data[] = array(
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['category_id'])),
'indent' => (count(explode('_', $result['path'])) - 1)
);
}
$view->set('categories', $category_data);
return $view->fetch('module/category.tpl');
}
}
}
?>
Code: Select all
foreach ($results as $result) {
$category_data[] = array(
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['category_id'])),
'indent' => (count(explode('_', $result['path'])) - 1)
);
}
$view->set('categories', $category_data);
Code: Select all
foreach ($flatList as $node)
{
$tag = $node->getTag();
if ($tag['indent'] < 2) // 2 is the maximum category depth to display
$new_category_data[] = $tag;
}
$view->set('categories', $new_category_data);

waiting for your precious reply
Sorry, I misunderstood which one of the suggestions I presented that you were using.
this should work for you
this should work for you
Code: Select all
foreach ($results as $result)
{
$indent = (count(explode('_', $result['path'])) - 1);
if ($indent < 2) // 2 is the maximum category depth to display
{
$category_data[] = array(
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['category_id'])),
'indent' => (count(explode('_', $result['path'])) - 1)
);
}
}
$view->set('categories', $category_data);
hi bruce, i made the modification on my local computer and when i put it online i receive an error message:
can you help me?
on my local machine works great.Warning: require_once(Tree.php) [function.require-once]: failed to open stream: No such file or directory in /home/galeriil/public_html/catalog/extension/module/category.php on line 5
Fatal error: require_once() [function.require]: Failed opening required 'Tree.php' (include_path='.:/scripts/php:/usr/lib/php:/usr/local/lib/php:/usr/share/pear:/tmp;/home/galeriil/public_html/library/external/Tree-2.0.0') in /home/galeriil/public_html/catalog/extension/module/category.php on line 5
can you help me?
You haven't uploaded the tree component and the external folder that contains it to your production site.
note also that I found an issue with \catalog\extension\module\category.php that makes the breadcrumb incorrect. The following fixes it with the error commented out for reference.
note also that I found an issue with \catalog\extension\module\category.php that makes the breadcrumb incorrect. The following fixes it with the error commented out for reference.
Code: Select all
$results = $database->getRows("select c.category_id, cd.name, c.parent_id, c.path, c.sort_order from category c left join category_description cd on (c.category_id = cd.category_id) where cd.language_id = '" . (int)$language->getId() . "' order by c.path");
foreach ($results as $result) {
$list_data[] = $result['path'];
$category_data[$result['category_id']] = array(
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['path'])),
// 'href' => $url->href('category', false, array('path' => $result['category_id'])),
'sort_order' => (int)$result['sort_order'],
'indent' => (count(explode('_', $result['path'])) - 1)
);
}
Last edited by bruce on Sat Mar 01, 2008 6:37 pm, edited 1 time in total.
Hi all, I've just joined up, and am really excited about the possibilities of OpenCart. Many thanks to Daniel for his excellent work, and sharing of OpenCart.
The above posts really helped me, especially Bruce's code for displaying sub-categories. I wanted to go one step further however, and create a CSS only dropdown menu from the categories, using nested lists. To do this, I needed to be able to detect which categories were sub-categories, and add a further level of lists to them. Using Bruce's code (unchanged), in category.php:
And changing category.tpl to the following:
allowed me to get the basic elements in place for a CSS dropdown menu. For examples of such menus see cssplay.co.uk. This code can also be used to set up the link structure for a Javascript menu.
Hope this is of some benefit to someone out there!
The above posts really helped me, especially Bruce's code for displaying sub-categories. I wanted to go one step further however, and create a CSS only dropdown menu from the categories, using nested lists. To do this, I needed to be able to detect which categories were sub-categories, and add a further level of lists to them. Using Bruce's code (unchanged), in category.php:
Code: Select all
//$results = $database->getRows("select c.category_id, cd.name from category c left join category_description cd on (c.category_id = cd.category_id) where parent_id = '0' and language_id = '" . (int)$language->getId() . "' order by c.sort_order");
$results = $database->getRows("select c.category_id, cd.name, c.parent_id, c.path from category c left join category_description cd on (c.category_id = cd.category_id) where cd.language_id = '" . (int)$language->getId() . "' order by c.path");
foreach ($results as $result) {
$category_data[] = array(
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['category_id'])),
'indent' => (count(explode('_', $result['path'])) - 1)
);
}
Code: Select all
<div class="box">
<div class="heading"><?php echo $heading_title; ?></div>
<ul class="products"><?php foreach ($categories as $category) { ?>
<?php if ($category['indent'] == 1)
echo "<li><ul><li><a href=".$category['href'].">".$category['name']."</a></li></ul></li>";
else {
echo "<li><a href=".$category['href'].">".$category['name']."</a></li>";
}
?>
<?php } ?>
</ul>
</div>
Hope this is of some benefit to someone out there!

hello,tmcguire wrote: items showing taxes on home page . I have no idea what is causing it. Any help with that would be great.
in catalog/controller/home.php
line #41 says -->
Code: Select all
'price' =>$currency->format($tax->calculate($result['price'], $result['tax_class_id']))
Code: Select all
'price' => $currency->format($result['price'])
Last edited by dvfd9 on Mon Apr 07, 2008 11:36 pm, edited 1 time in total.
Who is online
Users browsing this forum: No registered users and 2 guests