Page 1 of 4

Active SideCategoryList

Posted: Sat Oct 17, 2009 2:57 am
by Painstik
Hi guys, I am working on SideCategoryList, I don't want to use jquery for sidecategory list, and stil i want to be able to show/hide subcategories and hilight selected ones.

Open: includes/classes/class.category.php

Find:

Code: Select all

				$this->SetTrail(array($row['categoryid'], $row['catname']));
				$this->SetId($row['categoryid']);
				$this->SetName($row['catname']);
				$this->SetDesc($row['catdesc']);
Add before:

Code: Select all

$GLOBALS['ActiveCategory'] = $row['categoryid'];
Find:

Code: Select all

							$parentCat = $row['categoryid'];
							$this->Data = $row;
							$this->SetTrail(array($row['categoryid'], $row['catname']));
Add before:

Code: Select all

$GLOBALS['ActiveSubCategory'] = $row['categoryid'];

Open: includes/display/SideCategoryList.php

Find:

Code: Select all

$GLOBALS['CategoryLink'] = CatLink($rootCat['categoryid'], $rootCat['catname'], true);
Add after:

Code: Select all

if(isset($GLOBALS['ActiveCategory']) && $GLOBALS['ActiveCategory'] == $rootCat['categoryid']) {
						$GLOBALS['ActiveCategoryClass'] = "ActiveCategory";
					}
					else {
						$GLOBALS['ActiveCategoryClass'] = '';
					}
Find:

Code: Select all

if($i == count($categories[$parentCatId])) {
						$GLOBALS['LastChildClass']='LastChild';
					}
					$i++;
Add after:

Code: Select all

if(isset($GLOBALS['ActiveSubCategory']) && $GLOBALS['ActiveSubCategory'] == $subCat['categoryid']) {
						$GLOBALS['ActiveCategoryClass'] = "ActiveCategory";
					}
					else {
						$GLOBALS['ActiveCategoryClass'] = '';
					}
Find:

Code: Select all

if (isset($categories[$parentCatId]) && !empty($categories[$parentCatId])) {
				$i=1;
Add after:

Code: Select all

if(isset($GLOBALS['ActiveCategory']) && $GLOBALS['ActiveCategory'] == $parentCatId) {
Find:

Code: Select all

$output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SideCategoryList");
Add after:

Code: Select all

}
Open: templates/master/Snippet/SideCategoryList.html

Find:

Code: Select all

<li class="%%GLOBAL_LastChildClass%%">
Replace with:

Code: Select all

<li class="%%GLOBAL_ActiveCategoryClass%% %%GLOBAL_LastChildClass%%">
Find and Cut:

Code: Select all

%%GLOBAL_SubCategoryList%%
Paste after:

Code: Select all

</li>
Notice! Category List Depth at Settings > Display Settings - Category List Depth should be greater than 1
Edited 22.12.2009.

Re: Active SideCategoryList

Posted: Tue Oct 20, 2009 6:51 pm
by Painstik
Some pictures to show how it works... for those who doesn't speak my english :D

No category is selected
Image Image


Category "Shop iPod" selected
Image Image


Category "Shop Mac" selected
Image Image


Subcategory "Notebook Cases" selected
Image Image

Re: Active SideCategoryList

Posted: Mon Nov 09, 2009 10:07 pm
by Martin
Nice... not implemented it myself but it's elegant enough :) ... thanks for sharing.

Re: Active SideCategoryList

Posted: Sat Dec 19, 2009 4:55 am
by usaccess608
I tried it a few times but nothing happened.
i am running 5.0.2 versions
need help thanks

Re: Active SideCategoryList

Posted: Sun Dec 20, 2009 1:15 pm
by Painstik
Are you sure you did it exactly how it says? This shouldn't have problems with any version of ISC...

Re: Active SideCategoryList

Posted: Mon Dec 21, 2009 3:24 pm
by netjet
Painstick,

Thank you for sharing.
I wanted to try it but the directory snippet in all the templates are empty. Maybe you meant /snippet/ located in templates/master/ ?

Re: Active SideCategoryList

Posted: Mon Dec 21, 2009 5:01 pm
by netjet
Same for me, I've done everything like you said (except for the .htm file which is in templates/master/snippet/ and not templates specific) but nothing changed...

Re: Active SideCategoryList

Posted: Tue Dec 22, 2009 11:07 am
by scyllar
Same for me, tried with caution, but end up failure.
1. the snippet folder is empty,
2. copy required files from _master folder to snippet folder then edit accordingly also failed,
Please kindly clarify. Any help is highly appreciated!!!

Re: Active SideCategoryList

Posted: Tue Dec 22, 2009 12:17 pm
by Painstik
Yes, you have to edit the snippet in master folder. I have a custom template, so I don't make changes in master. Copy the SideCategoryList.html snippet from master folder to your template snippet folder, and make that changes.


Edit: I found what i forgot to share with you, you have to remove %%GLOBAL_SubCategoryList%% from <li> and put it after the list of categories. I edited in first post.

Here is a complete SideCategoryList.php code, so you can check if everything is like this

Code: Select all

<?php

	CLASS ISC_SIDECATEGORYLIST_PANEL extends PANEL
	{
		public function SetPanelSettings()
		{
			$output = "";
			$categories = $GLOBALS['ISC_CLASS_DATA_STORE']->Read('RootCategories');

			if (!isset($categories[0])) {
				$this->DontDisplay = true;
				return;
			}

			foreach($categories[0] as $rootCat) {
				// If we don't have permission to view this category then skip
				if(!CustomerGroupHasAccessToCategory($rootCat['categoryid'])) {
					continue;
				}

				$GLOBALS['SubCategoryList'] = $this->GetSubCategory($categories, $rootCat['categoryid']);
				$GLOBALS['LastChildClass']='';
				$GLOBALS['CategoryName'] = isc_html_escape($rootCat['catname']);
				$GLOBALS['CategoryLink'] = CatLink($rootCat['categoryid'], $rootCat['catname'], true);
				
				if(isset($GLOBALS['ActiveCategory']) && $GLOBALS['ActiveCategory'] == $rootCat['categoryid']) {
						$GLOBALS['ActiveCategoryClass'] = "ActiveCategory";
					}
					else {
						$GLOBALS['ActiveCategoryClass'] = '';
					}
					
				$output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SideCategoryList");

			}

			if(!$output) {
				$this->DontDisplay = true;
				return;
			}

			$GLOBALS['SNIPPETS']['SideCategoryList'] = $output;
		}


		/**
		* get the html for sub category list
		*
		* @param array $categories the array of all categories in a tree structure
		* @param int $parentCatId the parent category ID of the sub category list
		*
		* return string the html of the sub category list
		*/
		private function GetSubCategory($categories, $parentCatId)
		{

			$output = '';
			//if there is sub category for this parent cat
			if (isset($categories[$parentCatId]) && !empty($categories[$parentCatId])) {
				$i=1;
				if(isset($GLOBALS['ActiveCategory']) && $GLOBALS['ActiveCategory'] == $parentCatId) {
				foreach ($categories[$parentCatId] as $subCat) {
					// If we don't have permission to view this category then skip
					if (!CustomerGroupHasAccessToCategory($subCat['categoryid'])) {
						continue;
					}
					$catLink = CatLink($subCat['categoryid'], $subCat['catname'], false);
					$catName = isc_html_escape($subCat['catname']);

					$GLOBALS['SubCategoryList'] = $this->GetSubCategory($categories, $subCat['categoryid']);

					//set the class for the last category of its parent category
					$GLOBALS['LastChildClass']='';
					if($i == count($categories[$parentCatId])) {
						$GLOBALS['LastChildClass']='LastChild';
					}
					if($i == 1) {
						$GLOBALS['LastChildClass']='FirstChild';
					}
					$i++;

					if(isset($GLOBALS['ActiveSubCategory']) && $GLOBALS['ActiveSubCategory'] == $subCat['categoryid']) {
						$GLOBALS['ActiveCategoryClass'] = "ActiveCategory";
					}
					else {
						$GLOBALS['ActiveCategoryClass'] = '';
					}
					
					
					$GLOBALS['CategoryName'] = $catName;
					$GLOBALS['CategoryLink'] = $catLink;
					$output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("SideCategoryList");
				}
				}
			}
			if ($output!='') {
				$output = '<ul>'.$output.'</ul>';
			}
			return $output;
		}
	}
?>

Re: Active SideCategoryList

Posted: Wed Dec 23, 2009 8:59 am
by scyllar
Many thanks! Tested and working now! :D