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