Forums / Templates, Stylesheets, Page Layout / How to make clicking a category display all its items under the category name??

How to make clicking a category display all its items under the category name??

Views: 6,270

Results 21 to 40 of 45
6 Feb 2013, 10:15 PM
#21
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

How to make clicking a category display all its items under the category name??

I experimented with setting category-subs-selected and category-products, respectively, to display: none, doing so leaves unwanted blaink lines instead of "collapsing" the product list under the category name.

I think what must be done is:

If the page is a category or product page, get the category ID
Then display only the Category ID's products under the category name
And display only the other categories
End

CSS won't do the trick and has nothing to do with things.
It has to be ZC logic that only retrieves and displays the products for the current category, be it a category or product page.

I'm starting a new thread with the above question, please respond to this thread or to the new thread.

Thank you, Tom

7 Feb 2013, 1:32 AM
#22
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

CSS will work if it has the right identifiers to work on. You are right that the output as built by stock Zen Cart or the Categories List Box needs a span to contain the indent and separator, and the break after the link, in order to completely collapse the unwanted links. All three of these elements can be eliminated, however, and replaced with CSS styling of correctly identified <a> elements. If I were doing this, I would strip all of those and do the layout with CSS style rules.

Since you have confirmed that $box_categories_array[$i]['category_id'] is empty for products, you should not still be using
COLOR="#FF0000"[/COLOR]
but the alternate from post #13:
(zen_get_products_category_id($products_id) == $cPath)
which will yield a true test and set $div_class where appropriate. If the span has $div_class, the <a> should not also have it.

7 Feb 2013, 2:07 AM
#23
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

I changed as you suggested but it still does not work as desired...

I set .category-subs-selected { color: blue; } after creating this line of code:

      // 2/6/13 new code to show/hide products
      $div_class='';
      if ($products_id){
          if (($products_id)&&(($box_categories_array[$i]['products_id']==$products_id) or (zen_get_products_category_id($products_id) == $cPath))){
              $div_class='category-subs-selected';
          }
      }else{ // category-top
          if(($current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id)){
              $div_class='category-subs-selected';
          }
      }

The category got selected UNTIL I removed $div_class from this code:

	$content .= '<span class="'. $div_class . '">'. $indent.$separator . '<a class="'. $a_class . ' " href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. $count . '</span><br />';

Then I created

	//add content
	$content .= '<span class="'. $div_class . '">'. $indent.$separator . '<a class="'. $a_class . ' ' . $div_class . ' " href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. $count . '</span><br />';

and the category-subs-selected CSS works...

BUT the PRODUCTS STILL do not get any classes that would toggle their display on and off, the above span class never ever gets anything set) which is why I think there must be something included to use ZC code or logic to do 'if this category is NOT selected do NOT show products under categories'

If this is CSS-driven why is it so difficult to get ZC to place the corresponding classes in place??

FULL RELEVANT CODE (code for specials etc. not included):

  $content = "";
    $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";

  for ($i=0;$i<sizeof($box_categories_array);$i++) {
	 
	 //set selected style ($box_categories_array[$i]['current'] does not work)	
/*	 $div_class='';
	 if ($products_id){
		 if (($products_id)&&($box_categories_array[$i]['products_id']==$products_id)){
			 $div_class='category-subs-selected';
		 }
	 }else{
		 if(($current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id)){
			 $div_class='category-subs-selected';
		 }
	 }	 	 	*/

      // 2/6/13 new code to show/hide products
      $div_class='';
      if ($products_id){
          if (($products_id)&&(($box_categories_array[$i]['products_id']==$products_id) or (zen_get_products_category_id($products_id) == $cPath))){
              $div_class='category-subs-selected';
          }
      }else{ // category-top
          if(($current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id)){
              $div_class='category-subs-selected';
          }
      }
	
	// set top style
	if ($box_categories_array[$i]['top'] == 'true'){	
		$a_class = 'category-top';
	}elseif($box_categories_array[$i]['has_sub_cat']){
		$a_class = 'category-subs';
	}else{
		$a_class='category-products';
	}
	 // link to cat or prod
	if ($box_categories_array[$i]['is_product'] == true){
		$link = zen_href_link(FILENAME_PRODUCT_INFO, $box_categories_array[$i]['path']);
	}else{
		$link = zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']);
	}	
	//indent
	if($box_categories_array[$i]['is_product'] == true){
		$indent = str_repeat(CATEGORIES_SUBCATEGORIES_INDENT,  $box_categories_array[$i]['level']+1); 
	}else{
		$indent = str_repeat(CATEGORIES_SUBCATEGORIES_INDENT,  $box_categories_array[$i]['level']); 
	}
	//cat sub seperator
	if (($box_categories_array[$i]['level'] == 0)&&($box_categories_array[$i]['is_product'] == false)){
		$separator = '';
	}else{
		$separator = CATEGORIES_SEPARATOR_SUBS;
	}
	// count
	$count='';
	if (SHOW_COUNTS == 'true') {
		if($box_categories_array[$i]['is_product'] != true){
			$count = CATEGORIES_SEPARATOR.CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX ;
		}
	}
	//add content
	$content .= '<span class="'. $div_class . '">'. $indent.$separator . '<a class="'. $a_class . ' ' . $div_class . ' " href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. $count . '</span><br />';

  }

Finally, echo ' products_cat=' . zen_get_products_category_id($products_id); does not return any value.

Thank you, Tom

7 Feb 2013, 3:15 AM
#24
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

Stepping back to look at the whole file, $products_id will only be set if you are currently on a product info page, and equals the current page's product id, so that is mostly irrelevant for the styling you want.
Likewise, (zen_get_products_category_id($products_id) == $cPath) is useless for this test; you need to use
(zen_get_products_category_id($box_categories_array[$i]['products_id']) == $cPath)
to refer to the product being handled at this point in the loop.

The whole test needs to be reconfigured: ```php
*/

  // 2/6/13 new code to show/hide products
  $div_class='category';//default to unselected cat tag
  if ($products_id && ($box_categories_array[$i]['products_id']==$products_id)) {//the current product page
          $div_class='category-product-selected';
  }elseif (zen_get_products_category_id($box_categories_array[$i]['products_id']) == $cPath){//a product under the current cat
          $div_class='category-selected-subs';
  }elseif ($box_categories_array[$i]['products_id']) {//any other product
          $div_class='category-product';
  }elseif (($current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id)){//current cat
          $div_class='category-parent-selected';
  }
I know you are only talking about hiding the non-current categories' products, but this will also allow you to highlight the current category and product if you want. With $div_class applied to the span (only) you can handle the basic issue with a rule for
.category-product {display: none;}
and you can highlight the current cat and product if you like with
.category-parent-selected a, .category-product-selected a {color: #ff0000;}
7 Feb 2013, 3:28 AM
#25
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

Ahhhh...thank you...I never would have been able to code that test!! :)

And your CSS reasoning now makes more/better sense :)

I will once again test this tomorrow -- I will like to see if the product span itself gets any css put to it...and if all the products in the category get the correct span...because for the code to work properly the entire product thingy including the <br /> tag must be inside the span or an ugly gap appears...which means the span code needs to have its closing </span> moved, this also requires testing...

Once it's done and working I encourage you to submit this as a new addon -- call it show-hide products sidebox or whatever you like...
You deserve the credit :) :)

Thank you, Tom

7 Feb 2013, 3:39 AM
#26
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

If I did submit it, it would be as an update to the existing mod, and labeled as allowing more flexible styling than the original. Hiding products would be only one possibility. The $div_class setting would need a bunch of tweaking to use on a multi-level category tree, and still wouldn't allow the kind of hierarchical styling that other mods do.

7 Feb 2013, 3:46 AM
#27
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

You could combine it with the Category Dressing mod to do the extra stuff like hierarchical, mult-level, and whatnot??
CDressing must already have multi-category and such stuff in it??
HTH Tom

7 Feb 2013, 6:50 AM
#28
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

Categories Dressing would need significant rework in its stock underpinnings (the class and module files that create the info to output) in order to include products. It would be a worthy project, though it would take more time and knowledge than I have right now. I am also aware that it is already quite complex, and the more features it has, the more stuff users need to wade through to set it up. It would have to be an invisible subsystem unless wanted.

7 Feb 2013, 1:32 PM
#29
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

gjh42:

Categories Dressing would need significant rework in its stock underpinnings (the class and module files that create the info to output) in order to include products. It would be a worthy project, though it would take more time and knowledge than I have right now. I am also aware that it is already quite complex, and the more features it has, the more stuff users need to wade through to set it up. It would have to be an invisible subsystem unless wanted.

OIC -- at least we will soon have something workable with this particular products endeavor.
Thank you, Tom

7 Feb 2013, 3:53 PM
#30
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

We are almost there...the new code you wrote functions properly -- almost...it does configure $div_class.
Unfortunately its logic is off somewhere.

Here is the new code (I renamed the styles and configured it for <li> instead of <span> because the indent/separator does not do word wrap, LI does word wrap...

Things I see happening:

  1. The styles don't apply unless they are also on the A tag as well as the LI tag, I don't yet know why...I don't think this is the code's fault.
  2. The logic doesn't apply properly somehow.

What should happen:

  1. click a category, show products within category, do not show other categories' products
  2. click any product within category, show products within the product's category
  3. click a new category, show its products, hide all other categories' products
  4. if the page is not a category or product page show no products

What happens with current code:

  1. product LI tags are not nested under category LI, I have not figured where/how to emplace the UL tags to properly nest the products under the category. The UL tag cannot be contained within $content because then every LI gets an UL which we don't want, even the default tpl_categories.php does not use UL tags...If you have any suggestions that would be great...

  2. classes don't work unless applied to the A tag -- I don't yet know why, I don't think this is the code/sidebox's fault though, I also don't know if this is something to do with Bootstrap, I'm not sure...even default tpl_categories.php applies classes to A tag...

Here is the current code, then I'll explain what actually happens upon clicking things :)

CSS CODE:

.category {color: green;}
.category-current-product-selected {color: blue;} /* is never used */
.category-selected-products {color: pink;}
.category-any-other-product {color: yellow; }
.category-current-category-selected {color: purple;}

Using colors is easier for initial testing, but I did test a little with display:none and noticed that using display:none leaves a gap between category names where the products would normally be...I think this is because display:none gets applied only to the A tag

PHP CODE:

  $content = "";
    $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";

  for ($i=0;$i<sizeof($box_categories_array);$i++) {
	 
      // 2/7/13 new code to show/hide products
      $div_class='category';//default to unselected cat tag
      if ($products_id && ($box_categories_array[$i]['products_id']==$products_id)) {//current product page
          $div_class='category-current-product-selected';
      }elseif (zen_get_products_category_id($box_categories_array[$i]['products_id']) == $cPath){//all products under current 

category
          $div_class='category-selected-products';
      }elseif ($box_categories_array[$i]['products_id']) {//any other product in other categories
          $div_class='category-any-other-product';
      }elseif (($current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id)){//current category
          $div_class='category-current-category-selected';
      }

      // some debug code
      //echo ' products_cat1=' . zen_get_products_category_id($products_id);
      echo ' products_cat=' . zen_get_products_category_id($box_categories_array[$i]['products_id']);


      // set top style
	if ($box_categories_array[$i]['top'] == 'true'){	
		$a_class = 'category-top';
	}elseif($box_categories_array[$i]['has_sub_cat']){
		$a_class = 'category-subs';
	}else{
		$a_class='category-products';
	}
	 // link to cat or prod
	if ($box_categories_array[$i]['is_product'] == true){
		$link = zen_href_link(FILENAME_PRODUCT_INFO, $box_categories_array[$i]['path']);
	}else{
		$link = zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']);
	}	
	//indent
	if($box_categories_array[$i]['is_product'] == true){
		$indent = str_repeat(CATEGORIES_SUBCATEGORIES_INDENT,  $box_categories_array[$i]['level']+1); 
	}else{
		$indent = str_repeat(CATEGORIES_SUBCATEGORIES_INDENT,  $box_categories_array[$i]['level']); 
	}
	//cat sub separator
	if (($box_categories_array[$i]['level'] == 0)&&($box_categories_array[$i]['is_product'] == false)){
		$separator = '';
	}else{
		$separator = CATEGORIES_SEPARATOR_SUBS;
	}
	// count
	$count='';
	if (SHOW_COUNTS == 'true') {
		if($box_categories_array[$i]['is_product'] != true){
			$count = CATEGORIES_SEPARATOR.CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . 

CATEGORIES_COUNT_SUFFIX ;
		}
	}
	//add content
      // this content line works, div_class only works on the a tag, why??
      $content .= '<li class="'. $div_class . '">'. '<a class="'. $div_class . ' " href="'. $link .'">'. 
$box_categories_array[$i]['name'] .'</a>'. $count . '</li>';
      //$content .='<ul>';
      // this correctly assigns class to li but the class does not work...
      //$content .= '<li class="'. $div_class . '">'. '<a href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. 
$count . '</li>';
      // this correctly assigns class but class does not apply, why?? also need an ul to nest these li elements
      //$content .= '<span class="'. $div_class . '"><li>'. '<a href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. $count . '</li></span>';
      // this content line works
	//$content .= '<span class="'. $div_class . '">'. $indent.$separator . '<a class="'. $a_class . ' ' . $div_class . ' " href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. $count . '</span><br />';
      // this content line does not work
    // $content .= '<span class="'. $div_class . '">'. $indent.$separator . '<a class="'. $a_class . ' ' . ' " href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. $count . '</span><br />';
      //$content .='</ul>';
  }

What happens when clicking links:

Click the home page header links:
all cats = pink (wrong, should be green)
all prods = yellow, should not appear, display: none not being used anywhere

Click category link containing products:
current cat name = purple (correct)
current cat prods = pink (correct)
other cats = green (correct)
product under other cats = yellow, should not appear

Click any product link within category (becomes current category by default):
current cat name = pink (wrong, should be purple)
current cat prods = yellow (wrong, should be pink)
other cats = pink (wrong, should be green)
product under other cats = yellow, should not appear

Click any category with no products (edge case, will not happen):
current cat name = purple (correct)
current cat prods = pink (correct)
other cats = green (correct)
product under other cats = yellow, should not appear

Click any other page link besides home page or cat/prod:
all cats = pink (wrong, should be green)
all prods = yellow, should not appear, display: none not being used anywhere

Does this make any sense?? Can send snapshots if you wish...
Not rushing this, customer (people at work) will be told it will be ready when it's ready

Thank you for reading this, Tom

7 Feb 2013, 5:11 PM
#31
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

Categories Dressing has some fairly complex logic to determine and apply correct <ul> nesting; the stock tpl_categories code (largely shared by category list box) does not inherently give any such information. All items are identical in hierarchical structure, only given some basic top/sub/selected classes. That is why I added the different $div_class tags, to at least determine what kind of link it is. There is no simple way to dynamically group products under a specific category.

The styles do not apply to the links because there are already rules for generic links, and you did not include the link element in your rules.
.category-parent-selected a, .category-product-selected a {color: #ff0000;}
will apply the color to the links (and not to the separators).

This test
(($current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id))
is supposed to exclude the case where no category is selected (home or non-cat/prod pages), but it apparently is not functioning correctly. Can you add a debug line
echo ' current-cat:'.$current_category_id.' processing-cat:'.$box_categories_array[$i]['category_id']."\n";//debug
in your debug area?
Then see what it says for differeny kinds of pages.

7 Feb 2013, 6:27 PM
#32
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

applied your requested debug code :)

output upon clicking first category with four products:
current-cat:1 processing-cat:1 current-cat:1 processing-cat: current-cat:1 processing-cat: current-cat:1 processing-cat: current-cat:1 processing-cat: current-cat:1 processing-cat:2 current-cat:1 processing-cat: current-cat:1 processing-cat:4 current-cat:1 processing-cat:3

output upon clicking one of the products within the first category with four products:

current-cat:0 processing-cat:1 current-cat:0 processing-cat: current-cat:0 processing-cat: current-cat:0 processing-cat: current-cat:0 processing-cat: current-cat:0 processing-cat:2 current-cat:0 processing-cat: current-cat:0 processing-cat:4 current-cat:0 processing-cat:3

output upon clicking third category which has no products: (yes, third category is ID #4)

current-cat:4 processing-cat:1 current-cat:4 processing-cat: current-cat:4 processing-cat: current-cat:4 processing-cat: current-cat:4 processing-cat: current-cat:4 processing-cat:2 current-cat:4 processing-cat: current-cat:4 processing-cat:4 current-cat:4 processing-cat:3

output upon clicking a non-prod non-cat page:

current-cat:0 processing-cat:1 current-cat:0 processing-cat: current-cat:0 processing-cat: current-cat:0 processing-cat: current-cat:0 processing-cat: current-cat:0 processing-cat:2 current-cat:0 processing-cat: current-cat:0 processing-cat:4 current-cat:0 processing-cat:3

debug code is placed immediately after the code which configures values for $div_class

also...

The styles do not apply to the links because there are already rules for generic links, and you did not include the link element in your rules.
.category-parent-selected a, .category-product-selected a {color: #ff0000;}
will apply the color to the links (and not to the separators).

The styles do apply to the LINKS (A) -- they just don't apply "correctly" -- i.e. the example colors they should get if the if-then logic to assign $div_class values works "correctly" -- they don't apply to the LI tags surrounding the links.

Logic we want (I think most people would want):

If home page or non-product or non-category page, show no products for any category.
If category page, show all active products for the category only.
If product page, show all active products for the product's category only.

Maybe there needs to be a preliminary test what kind page it is -- cat page?? prod page?? neither?? then do stuff based on this result...I just now realized we need a 'where product_status = active' test too, sigh...we should not include inactive items...

Is that simple enough?? I hope so!!

Do you have any suggestions for properly indenting the product names??
I will work on this part...
I have not yet tried using a <div> instead of a <span> around the LI tags...
Or the A tag could have its left margin messed with LOL based on if the CSS style for products

Thank you, Tom

7 Feb 2013, 6:46 PM
#33
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

Maybe an easier way to do the program logic is this:

If the page is not a prod or cat page, output only category links, nothing else.

If the page is a prod or cat page, output only the product links for that specific category below the category link per se, and for no other categories.
Then we only need two css tags, one for the category, one for the products...

Might be a little more complicated to write but the first case is easier now??

Thank you, Tom

7 Feb 2013, 7:00 PM
#34
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

Doing the above could also be generalized to sub-categories too.

Something in the code could have the administrator (person installing the addon) toggle whether to do subcats or products...

Thank you, Tom

7 Feb 2013, 7:40 PM
#35
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

output upon clicking one of the products within the first category with four products:

current-cat:0 processing-cat:1 This indicates that $current_category_id (a stock ZC variable) is null or 0 when you are on a product info page. There needs to be a different variable tested to get the category that holds the current product. The mod's original developer knew that $current_category_id didn't work (unless you are on a category page), but didn't figure out a substitute. In /includes/classes/category_list.php around line , find php // this doesn't work :( if($category_id == $current_category_id){ and replace with```php
// this doesn't work :(
//test gjh42 20130207
$current_category_id_list = $current_category_id? $current_category_id: ($products_id? zen_get_products_category_id($products_id): 0);
if($category_id == $current_category_id_list){

echo ' current='.$box_categories_array[$i]['current']; 
in your debug area to see how it works.
7 Feb 2013, 7:50 PM
#36
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

It works better with the added code...getting there.
Give me a few moments to compile the results, please...
Thank you, Tom

7 Feb 2013, 8:03 PM
#37
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

debug results after adding new code to /includes/classes/category_list.php
I thought it improved things but now I do not think so
More adjustment to the code logic??

output upon clicking first category with four products:
current-cat:1
processing-cat:1
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:2
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:4
current=
current-cat:1
processing-cat:3
current=

output upon clicking one of the products within the first category with four products:

current-cat:1
processing-cat:1
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:2
current=
current-cat:1
processing-cat:
current=
current-cat:1
processing-cat:4
current=
current-cat:1
processing-cat:3
current=

output upon clicking third category which has no products: (yes, third category is ID #4)

current-cat:4
processing-cat:1
current=
current-cat:4
processing-cat:
current=
current-cat:4
processing-cat:
current=
current-cat:4
processing-cat:
current=
current-cat:4
processing-cat:
current=
current-cat:4
processing-cat:2
current=
current-cat:4
processing-cat:
current=
current-cat:4
processing-cat:4
current=
current-cat:4
processing-cat:3
current=

output upon clicking a non-prod non-cat page:

current-cat:0
processing-cat:1
current=
current-cat:0
processing-cat:
current=
current-cat:0
processing-cat:
current=
current-cat:0
processing-cat:
current=
current-cat:0
processing-cat:
current=
current-cat:0
processing-cat:2
current=
current-cat:0
processing-cat:
current=
current-cat:0
processing-cat:4
current=
current-cat:0
processing-cat:3
current=

debug code is placed immediately after the code which configures values for $div_class

What happens when clicking links:

Click the home page header links:
all cats = pink (wrong, should be green)
all prods = yellow, should not appear, display: none not being used anywhere

Click category link containing products:
current cat name = purple (correct)
current cat prods = pink (correct)
other cats = green (correct)
product under other cats = yellow, should not appear eventually

Click any product link within category (becomes current category by default):
current cat name = pink (wrong, should be purple)
current cat prods = yellow (wrong, should be pink)
other cats = pink (wrong, should be green)
product under other cats = yellow, should not appear

Click any category with NO products (edge case, will not happen):
current cat name = purple (correct)
current cat prods = NONE (correct)
other cats = green (correct)
product under other cats = yellow, should not appear eventually

Click any other page link besides home page or cat/prod:
all cats = pink (wrong, should be green)
all prods = yellow, should not appear eventually

Thank you, Tom

7 Feb 2013, 8:44 PM
#38
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

Hmm... the test is still not getting the current cat. More debug may help explain where it's falling down:
echo ' current='.$box_categories_array[$i]['current'].' prid:'.$products_id.' zgprcid:'.zen_get_products_category_id($products_id)."\n";

Note that current= should give a value of true or false. False might be output as blank, which is what we see.

7 Feb 2013, 9:41 PM
#39
tlyczko avatar

tlyczko

Zen Follower

Join Date:
Dec 2003
Location:
UPstate NY
Posts:
398
Plugin Contributions:
1

Re: How to make clicking a category display all its items under the category name??

debug results after adding new debug code

home page opens: current-cat is 0, current, prid, zgprcid have no value
click category: current-cat=category ID, current, prid, zgprcid have no value
click a product: current-cat=category ID, current, prid, zgprcid have no value
click a non-prod/cate page: current-cat is 0, current, prid, zgprcid have no value

HTH

7 Feb 2013, 10:02 PM
#40
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How to make clicking a category display all its items under the category name??

That's just weird. On a product page, there should be a $products_id. The only thing I can think is that that variable hasn't been set yet when the class runs, though it only runs when called from the module file (well after header info is initialized).

It turns out that there is no $products_id variable on the product info page. Instead, main_template_vars.php sets $products_id_current, so that is the variable to use in all relevant places.
Another place where the original mod author messed up.

Note that $_GET['products_id'] is always available on the product info page, and that is probably why the author assumed that $products_id was the right variable to use.