I've read a lot about sub-menu's all of which don't support the "ordering" feature as provided in the Admin feature. I'd like to thank tmcguire for his mod, as it got me to get mine working the way i wanted.
I've found a way to do this in a fashion that may or may not be coding etiquette (as it add's another query) but preserves the Admin Sorting feature, if the sub-categories had a separate table then this wouldn't be an issue as all the categories share the same sort_order field.
This code was not tested for sub-sub-categories (categories 2 levels or more deep) but it does work for those that would like the sort method for 1 category, i'm sure it could be modified to do such however I didn't spend the time doing so.
first: backup the following files in case something goes wrong
"your store path"/catalog/template/default/css/default.css (adjust this path accordingly with how you setup your template)
"your store path"/catalog/extension/module/category.php
"your store path"/catalog/template/default/module/category.tpl
in file:
"your store path"/catalog/template/default/css/default.css
find css tag that looks like:
Code: Select all
.box .category a {
padding: 0px 0px 0px 10px;
display: block;
font-size:14px;
font-weight:bold;
text-decoration: none;
margin-bottom: 8px;
}
Code: Select all
.box .subcategory a{
background: url('../image/bullet_1.png') no-repeat 15px 4px;
padding: 0px 0px 0px 25px;
display: block;
font-size:11px;
font-weight:bold;
text-decoration: none;
margin-bottom: 8px;
}
adjust the css for however you want the text to look like
Next,
in file:
"your store path"/catalog/extension/module/category.php
find:
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");
foreach ($results as $result) {
$category_data[] = array(
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['category_id']))
);
}
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");
foreach ($results as $result) {
$category_data[] = array(
'catid' => $result['category_id'],
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['category_id']))
);
}
$subcategory_data = array();
$results = $database->getRows("select c.category_id, c.parent_id, cd.name from category c left join category_description cd on (c.category_id = cd.category_id) where c.parent_id != 0 and language_id = '" . (int)$language->getId() . "' order by c.sort_order");
foreach ($results as $result) {
$subcategory_data[] = array(
'parid' => $result['parent_id'],
'name' => $result['name'],
'href' => $url->href('category', false, array('path' => $result['category_id']))
);
}
$view->set('subcategories', $subcategory_data);
in the file
"your store path"/catalog/template/default/module/category.tpl:
find :
Code: Select all
<div class="category">
<?php foreach ($categories as $category) { ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
</div>
Code: Select all
<?php foreach ($categories as $category) { ?>
<div class="category"><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a> </div>
<?php foreach ($subcategories as $subcategory) { ?>
<?php if ($category['catid'] == $subcategory['parid']){ ?>
<div class="subcategory"><a href="<?php echo $subcategory['href']; ?>"><?php echo $subcategory['name']; ?></a></div>
<?php } ?>
<?php } ?>
<?php } ?>