Active SideCategoryList

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
Painstik
Posts: 122
Joined: Sun Jul 19, 2009 1:19 pm
Location: Croatia

Active SideCategoryList

Post 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.
Last edited by Painstik on Wed Dec 23, 2009 1:27 pm, edited 4 times in total.
Need custom coding for Interspire Shopping Cart? Contact me
Painstik
Posts: 122
Joined: Sun Jul 19, 2009 1:19 pm
Location: Croatia

Re: Active SideCategoryList

Post 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
Need custom coding for Interspire Shopping Cart? Contact me
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Active SideCategoryList

Post by Martin »

Nice... not implemented it myself but it's elegant enough :) ... thanks for sharing.
usaccess608
Posts: 12
Joined: Tue Jul 28, 2009 2:41 pm

Re: Active SideCategoryList

Post by usaccess608 »

I tried it a few times but nothing happened.
i am running 5.0.2 versions
need help thanks
Painstik
Posts: 122
Joined: Sun Jul 19, 2009 1:19 pm
Location: Croatia

Re: Active SideCategoryList

Post by Painstik »

Are you sure you did it exactly how it says? This shouldn't have problems with any version of ISC...
Need custom coding for Interspire Shopping Cart? Contact me
netjet
Posts: 74
Joined: Tue Nov 03, 2009 12:03 pm

Re: Active SideCategoryList

Post 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/ ?
netjet
Posts: 74
Joined: Tue Nov 03, 2009 12:03 pm

Re: Active SideCategoryList

Post 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...
scyllar
Posts: 7
Joined: Tue Dec 22, 2009 11:01 am

Re: Active SideCategoryList

Post 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!!!
Painstik
Posts: 122
Joined: Sun Jul 19, 2009 1:19 pm
Location: Croatia

Re: Active SideCategoryList

Post 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;
		}
	}
?>
Need custom coding for Interspire Shopping Cart? Contact me
scyllar
Posts: 7
Joined: Tue Dec 22, 2009 11:01 am

Re: Active SideCategoryList

Post by scyllar »

Many thanks! Tested and working now! :D
Post Reply