MegaFemaTron2
2012-01-12 22:47:44
I used the sub categories feature found in categoryheading.php to get this thing going after many failed attempts at other methods.
In /includes/display/ create a file called: HomeCategories.php and inside of it paste this:
<?php
CLASS ISC_HOMECATEGORIES_PANEL extends PANEL
{
public function SetPanelSettings()
{
$GLOBALS['ISC_CLASS_CATEGORY'] = GetClass('ISC_CATEGORY');
if ($GLOBALS['EnableSEOUrls'] == 1) {
$baseLink = sprintf("%s/categories", $GLOBALS['ShopPath']);
} else {
$baseLink = sprintf("%s/categories.php?category=", $GLOBALS['ShopPath']);
}
// Output Top-level Categories
$GLOBALS['SNIPPETS']['HomeCategories'] = "";
$query = sprintf("select * from [|PREFIX|]categories where catparentid='0' and catvisible=1 order by catsort asc, catname asc", $GLOBALS['ISC_CLASS_DB']->Quote($GLOBALS['CatId']));
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
if($GLOBALS['ISC_CLASS_DB']->CountResult($result) > 0) {
// Check to see if we need to add in place holder images or if we are just displaying text
if (!($rtn = $GLOBALS['ISC_CLASS_DB']->Fetch($GLOBALS['ISC_CLASS_DB']->Query("SELECT COUNT(*) AS Total FROM [|PREFIX|]categories WHERE catimagefile != ''"))) || !$rtn['Total']) {
$useImages = false;
} else {
$useImages = true;
if (GetConfig('CategoryDefaultImage') !== '') {
$defaultImage = GetConfig('ShopPath') . '/' . GetConfig('CategoryDefaultImage');
} else {
$defaultImage = $GLOBALS['IMG_PATH'].'/CategoryDefault.gif';
}
}
$i = 0;
while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
$i++;
if (!CustomerGroupHasAccessToCategory($row['categoryid'])) {
continue;
}
$GLOBALS['HomeCatName'] = isc_html_escape($row['catname']);
$GLOBALS['HomeCatLink'] = CatLink($row['categoryid'], $row['catname']);
if ($useImages) {
if ($row['catimagefile'] !== '') {
$GLOBALS['CatImage'] = GetConfig('ShopPath') . '/' . GetConfig('ImageDirectory') . '/' . $row['catimagefile'];
} else {
$GLOBALS['CatImage'] = $defaultImage;
}
$GLOBALS['ISC_CLASS_TEMPLATE']->assign('width', getConfig('CategoryImageWidth'));
$GLOBALS['ISC_CLASS_TEMPLATE']->assign('height', getConfig('CategoryImageHeight') + 50);
$GLOBALS['SNIPPETS']['HomeCategories'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CatItemImage");
if ($i % GetConfig('CategoryPerRow') == 0) {
$GLOBALS['SNIPPETS']['HomeCategories'] .= '<li class="RowDivider" style="float:none; clear:both;"></li>';
}
} else {
$GLOBALS['SNIPPETS']['HomeCategories'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CatItem");
}
}
if ($useImages) {
if ($i % GetConfig('CategoryPerRow') > 0) {
$GLOBALS['SNIPPETS']['HomeCategories'] .= '<li style="float: none; clear: both;"/>';
}
$output = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("HomeCategoriesGrid");
} else {
$output = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("HomeCategories");
}
$output = $GLOBALS['ISC_CLASS_TEMPLATE']->ParseSnippets($output, $GLOBALS['SNIPPETS']);
$GLOBALS['SNIPPETS']['HomeCategories'] = $output;
}
}
}
And in /templates/yourtemplatename/Panels/ create a new file called: HomeCategories.html and paste this in it:
<div class="Block Moveable Panel" id="CategoryHeading">
<div class="BlockContent">
%%SNIPPET_HomeCategories%%
</div>
</div>
In /templates/yourtemplatename/Snippets/ you are going to be creating 4 files. Create a file called: CatItem.html and paste this in it:
<li><a href="%%GLOBAL_HomeCatLink%%">%%GLOBAL_HomeCatName%%</a></li>Then create a file called: CatItemImage.html and paste this in it:
<li style="width: %%GLOBAL_width%%px; height: %%GLOBAL_height%%px;">
<a href="%%GLOBAL_HomeCatLink%%" style="text-decoration: none;"><img src="%%GLOBAL_CatImage%%" border="0" /></a><br /><a href="%%GLOBAL_HomeCatLink%%">%%GLOBAL_HomeCatName%%</a>
</li>Then create a file called: HomeCategoriesGrid.html and paste this in it:
<div class="SubCategoryListGrid">
<ul>
%%SNIPPET_HomeCategories%%
</ul>
</div>
Then create a file called: HomeCategories.html and paste this in it:
<div class="SubCategoryList">
<ul>
%%SNIPPET_HomeCategories%%
</ul>
</div>Then use this code where you want the panel to show up:
%%Panel.HomeCategories%%Now you will probably have a link list of all of your top level categories wherever you put this code. The next step below is to help you add images to this panel for each category. When you do, the text links will still be there as well. I'm thinking of removing those.
This part was quite infuriating. If only sucker punches could be sent via mail.
In admin/includes/classes/class.category.php locate the following code and delete it.
// Also forcefully delete the image if it is a root category
if ($catData['category'] == "0") {
$this->DelCategoryImage($this->categoryAPI->catimagefile);
$catImage = '';
}
Also find and delete this in the same file:
public function RemoveRootImages()
{
$result = $GLOBALS['ISC_CLASS_DB']->Query("SELECT * FROM [|PREFIX|]categories WHERE catparentid='0' AND catimagefile != ''");
while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
$this->DelCategoryImage($row['categoryid']);
$GLOBALS['ISC_CLASS_DB']->UpdateQuery('categories', array('catimagefile' => ''), "categoryid='" . (int)$row['categoryid'] . "'");
}
}
Also in admin/includes/class.remote.php you can also delete this:
// Also make sure that all the root categories do NOT have any images assoiated with them
$GLOBALS['ISC_CLASS_ADMIN_CATEGORY'] = GetClass('ISC_ADMIN_CATEGORY');
$GLOBALS['ISC_CLASS_ADMIN_CATEGORY']->RemoveRootImages();
You're on your own from here and you'll have to style your new panel and make tweaks however you like. Cheers! Sharing is caring!