Linked Categories - Work in Progress
I was working on getting linked categories on our site. That is the ability to copy a category to two different locations without duplicating it. I made some initial progress and thought I'd share.
SQL Patch:
Code:
CREATE TABLE `categories_to_categories` ( `categories_id` INT(11) NOT NULL , `parent_id` INT(11) NOT NULL ) ENGINE = InnoDB;
INSERT INTO categories_to_categories (categories_id, parent_id)
SELECT categories_id, parent_id
FROM cart1_categories WHERE 1;
Then create the following file: includes/extra_datafiles/category_to_category.php
and put this define in it to set up the database table we just created.
Code:
<?php
define('TABLE_CATEGORIES_TO_CATEGORIES', DB_PREFIX . 'categories_to_categories');
Finally patch the index page to pull up categories that are linked.
Code:
diff --git a/includes/modules/pages/index/main_template_vars.php b/includes/modules/pages/index/main_template_vars.php
index 41c26a6..ec1dc16 100644
--- a/includes/modules/pages/index/main_template_vars.php
+++ b/includes/modules/pages/index/main_template_vars.php
@@ -94,9 +94,10 @@ if ($category_depth == 'nested')
// do nothing, go through the loop
} else {
$categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id
- FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
- WHERE c.parent_id = :parentID
+ FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_CATEGORIES_TO_CATEGORIES . " cc
+ WHERE cc.parent_id = :parentID
AND c.categories_id = cd.categories_id
+ AND c.categories_id = cc.categories_id
AND cd.language_id = :languagesID
AND c.categories_status= '1'
ORDER BY sort_order, cd.categories_name";
@@ -108,9 +109,10 @@ if ($category_depth == 'nested')
}
} else {
$categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id
- FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
- WHERE c.parent_id = :parentID
+ FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_CATEGORIES_TO_CATEGORIES . " cc
+ WHERE cc.parent_id = :parentID
AND c.categories_id = cd.categories_id
+ AND c.categories_id = cc.categories_id
AND cd.language_id = :languagesID
AND c.categories_status= '1'
ORDER BY sort_order, cd.categories_name";
There isn't a backend patch yet for linking categories. At this moment you have to add a new row to the category to category table to get categories linked.
There is also probably a lot more that would need to be modified. Breadcrumbs and any navigation sideboxes come to mine.
Re: Linked Categories - Work in Progress
So what are the pros and cons of this as compared to linking the product that are within the category(ies)? How is the meta data expected to eventually be handled so that the two categories don't appear as duplicate(s)?
Is a potential use of this like having say shock absorbers that are a part of two models of a car, but instead of populating each model's shocks group, that it is populated once and carried everywhere that the category is identified as a child?
Re: Linked Categories - Work in Progress
In our case we sell different types of equipment and parts to the equipment and would like to have them in two spots. Like we have Autoclaves -> Autoclave Parts and we also have Parts and Accessories -> Autoclaves Parts
Inside Autoclave parts is a nest of hundreds of categories with thousands of products. Linking product by product isn't really an option.
But then we are also running the multi-site plugin, and have a sister site where we sell health supplies. And this code didn't work right with multi-site at all.
I hadn't thought about meta tag considerations.
Re: Linked Categories - Work in Progress
I believe that I was thinking of the same concept that you proposed above whether I clearly stated (or most likely not) :).
Well, would think of the category configuration in this situation like products that are linked. A category has a master category (parent) and then is shown in multiple other categories. Therefore would think that such a linked category might have some sort of common canonical address. But event then... just trying to get/through a couple of ideas/concepts out there...