Should I share this?

Share it please
36
100%
Do not share it.
0
No votes
 
Total votes: 36


Post by bruce » Mon Jan 07, 2008 8:17 am

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.

Attachments

[The extension has been deactivated and can no longer be displayed.]

???
category menu sorted.png

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by trippy » Sun Jan 27, 2008 9:58 pm

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....

New member

Posts

Joined
Sun Dec 16, 2007 5:12 pm

Post by bruce » Mon Jan 28, 2008 11:00 am

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);


Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by trippy » Wed Jan 30, 2008 10:07 pm

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

New member

Posts

Joined
Sun Dec 16, 2007 5:12 pm

Post by bruce » Thu Jan 31, 2008 7:15 am

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);


Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by trippy » Sat Feb 09, 2008 4:16 pm

Bruce.... you're WONDERFUL! :) :**
many thanks!!!!

New member

Posts

Joined
Sun Dec 16, 2007 5:12 pm

Post by ironman » Sat Mar 01, 2008 5:30 pm

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?

Newbie

Posts

Joined
Tue Nov 20, 2007 2:01 am

Post by bruce » Sat Mar 01, 2008 6:15 pm

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)
      			);
    		}

Last edited by bruce on Sat Mar 01, 2008 6:37 pm, edited 1 time in total.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by OrT » Sun Mar 02, 2008 10:23 pm

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.

OrT
Newbie

Posts

Joined
Sun Mar 02, 2008 10:21 pm

Post by WCNZ » Mon Mar 24, 2008 3:09 pm

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!  :)

New member

Posts

Joined
Mon Mar 24, 2008 11:21 am

Post by ven.ganeva » Mon Apr 07, 2008 11:02 pm

Do we have a mod for 0.6.5? Had to install older version as i don't have up to date php :(

Newbie

Posts

Joined
Mon Apr 07, 2008 6:45 pm

Post by dvfd9 » Mon Apr 07, 2008 11:34 pm

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'])
Last edited by dvfd9 on Mon Apr 07, 2008 11:36 pm, edited 1 time in total.

Newbie

Posts

Joined
Mon Apr 07, 2008 2:43 am

Post by dvfd9 » Tue Apr 08, 2008 8:36 am

awesome mod, thanks man!
Last edited by dvfd9 on Tue Apr 08, 2008 8:47 am, edited 1 time in total.

Newbie

Posts

Joined
Mon Apr 07, 2008 2:43 am
Who is online

Users browsing this forum: No registered users and 2 guests