Post by moggiex » Tue Dec 08, 2009 5:33 am

Howdy,

Hoping someone can point me in the right direction for this. I would like to add a 'related categories' section to last leaf category in a category tree.

To explains this, lets pretend I have a category tree like this:

Electronics
> Toasters
> Televisions
> Televisions > 15" TV's
> Televisions > 17" TV's
> Televisions > 20" TV's


Now lets say, I navigate to 'Televisions', the user will be shown the three sub categories in the upper section of the site:

> Televisions > 15" TV's
> Televisions > 17" TV's
> Televisions > 20" TV's

Now when I got into the last leaf category, lets say '> Televisions > 17" TV's' we loose the categories at the top.

I'd like to show these categories, because if I have gone into the wrong category, and instead wanted to look at 15" or 20" TV's I cannot readily jump back and as part of the 'exit strategy' I'd like to show the categories.

Any suggestions on how to achieve this?

Matt

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm

Post by montanaflynn » Sun Dec 13, 2009 1:00 pm

That would be nice, I am looking into this as well. I would like the final product page to list the categories it belongs to in the middle column too.

User avatar
New member

Posts

Joined
Fri Oct 09, 2009 5:19 am

Post by hubba » Tue Dec 15, 2009 2:46 am

Do you meant to say you do not want the categories to be collapsable?

I think there is a module somewhere.. but I can't find it.

if anyone sees the module please point us to the right way, I am looking for that too!

New member

Posts

Joined
Mon Sep 07, 2009 1:13 am

Post by moggiex » Tue Dec 15, 2009 2:52 am

hubba wrote:Do you meant to say you do not want the categories to be collapsable?

I think there is a module somewhere.. but I can't find it.

if anyone sees the module please point us to the right way, I am looking for that too!
No, that's a simple hack around the IF statement in the categories module (about line 55), this is referring to displaying the children categories in a final leaf category.

I'll take stab at this tonight as I am needing it for a few sites now as exit options if the landing category is not the the right category and I hate having to hard code stuff as its a bar-steward to update later.

Matt

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm

Post by moggiex » Tue Dec 15, 2009 7:25 am

HAX!!! I got it, took a bit of faffing but it works.

File:
/catalog/model/catalog/category.php

We need to add a new function, so at line 21 add this:

Code: Select all

	// We need to know the parent ID, so that we can work out what its equal level categories are
	public function getTotalEqualCategoriesByCategoryId($category_id = 0) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$category_id . "'");
		
		return $query->row['parent_id'];
	}
This gets us the parent_id of the category we're looking at, superb, now we just need to use this function and use the results when needed.

File:
/catalog/controller/catalog/category.php

Around line: 93 look for:

Code: Select all

$category_total 		= $this->model_catalog_category->getTotalCategoriesByCategoryId($category_id);
$product_total 			= $this->model_catalog_product->getTotalProductsByCategoryId($category_id);
ADD this after it:

Code: Select all

$category_equal_total 	= $this->model_catalog_category->getTotalEqualCategoriesByCategoryId($category_id);
One more bit to alter....

just below this change:

Code: Select all

if ($category_total || $product_total) {
        		$this->data['categories'] = array();
        		
				
				$results = $this->model_catalog_category->getCategories($category_id);
To this:

Code: Select all

if ($category_total || $product_total || $category_equal_total) {
        		$this->data['categories'] = array();
        		
				
				$results = $this->model_catalog_category->getCategories($category_id);
				$results = $this->model_catalog_category->getCategories($category_equal_total);
No edits are needed for the category.tpl file, as it will appear with the categories automatically, as we've just populated with categories, even when its at its final leaf.

Happy days, considering my php and sql skillz suck :D

Matt

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm

Post by moggiex » Tue Dec 15, 2009 7:38 am

whoops, this has an interesting side affect of showing level categories when at level 0, which is not desirable, will post some alternative code when I've stopped it from doing so.

Matt

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm

Post by moggiex » Tue Dec 15, 2009 7:47 am

Na, stuck now,

Its party solved by putting an IF around the new request for the categories:

Code: Select all

$results = $this->model_catalog_category->getCategories($category_id);
if (!$results && $category_equal_total != 0) {
					$results = $this->model_catalog_category->getCategories($category_equal_total);
				}
However, I don't know how to make it relaise that its already at the bottom level, because the category links are coming out like this:

Tree:
> Televisions
> Televisions > 15" TV's

The links are coming out as:

Televisions > 15" TV's > 15" TV's

Which is wrong :( Sooooo close as well!

Matt

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm
Who is online

Users browsing this forum: No registered users and 45 guests