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
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.
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.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!
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!
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:
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:
ADD this after it:
One more bit to alter....
just below this change:
To this:
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
Matt
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'];
}
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);
Code: Select all
$category_equal_total = $this->model_catalog_category->getTotalEqualCategoriesByCategoryId($category_id);
just below this change:
Code: Select all
if ($category_total || $product_total) {
$this->data['categories'] = array();
$results = $this->model_catalog_category->getCategories($category_id);
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);
Happy days, considering my php and sql skillz suck
Matt
Code: Select all
It was like that when I found it, honest!
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
Matt
Code: Select all
It was like that when I found it, honest!
Na, stuck now,
Its party solved by putting an IF around the new request for the categories:
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
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);
}
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!
Who is online
Users browsing this forum: No registered users and 45 guests