Page 2 of 2
Re: My category list with subs.
Posted: Mon Jan 07, 2008 8:17 am
by bruce
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.
Re: My category list with subs.
Posted: Sun Jan 27, 2008 9:58 pm
by trippy
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....
Re: My category list with subs.
Posted: Mon Jan 28, 2008 11:00 am
by bruce
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.
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);
Re: My category list with subs.
Posted: Wed Jan 30, 2008 10:07 pm
by trippy
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......
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');
}
}
}
?>
if i replace
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);
with
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);
it gives me no categories, no subcategories and some errors.... sure i'm doing something wrong....
waiting for your precious reply
Re: My category list with subs.
Posted: Thu Jan 31, 2008 7:15 am
by bruce
Sorry, I misunderstood which one of the suggestions I presented that you were using.
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);
Re: My category list with subs.
Posted: Sat Feb 09, 2008 4:16 pm
by trippy
Bruce.... you're WONDERFUL!

:**
many thanks!!!!
Re: My category list with subs.
Posted: Sat Mar 01, 2008 5:30 pm
by ironman
hi bruce, i made the modification on my local computer and when i put it online i receive an error message:
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
on my local machine works great.
can you help me?
Re: My category list with subs.
Posted: Sat Mar 01, 2008 6:15 pm
by bruce
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.
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)
);
}
Re: My category list with subs.
Posted: Sun Mar 02, 2008 10:23 pm
by OrT
This was also very usefull for me, my atmost congratulations and gratitude.
When and if I write extentions, I shall share them with the board.
Sub Cat: One Step Further...
Posted: Mon Mar 24, 2008 3:09 pm
by WCNZ
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:
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)
);
}
And changing category.tpl to the following:
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>
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!

Re: My category list with subs.
Posted: Mon Apr 07, 2008 11:02 pm
by ven.ganeva
Do we have a mod for 0.6.5? Had to install older version as i don't have up to date php

Re: My category list with subs.
Posted: Mon Apr 07, 2008 11:34 pm
by dvfd9
tmcguire wrote:
items showing taxes on home page . I have no idea what is causing it. Any help with that would be great.
hello,
in catalog/controller/home.php
line #41 says -->
Code: Select all
'price' =>$currency->format($tax->calculate($result['price'], $result['tax_class_id']))
comment out that line and add this
Code: Select all
'price' => $currency->format($result['price'])
Re: My category list with subs.
Posted: Tue Apr 08, 2008 8:36 am
by dvfd9
awesome mod, thanks man!