Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Pre-select a subcategory

Pre-select a subcategory

Views: 1,604

Results 1 to 11 of 11
9 Apr 2011, 5:43 AM
#1
atozstore avatar

atozstore

New Zenner

Join Date:
Mar 2011
Posts:
27
Plugin Contributions:
0

Pre-select a subcategory

Hi all Zenners,

I have a top level category that hold no product, it only hold other categories. I'm trying to select the top subcategory when a user clicks on this top level category. Is there any option already built-in? or do I need to intercept the execution in the code and manipulate it in there? For example in this screenshot, I want to select the most recently added (Jan 14 2011) subcategory when the user click on Promotions category. Please help. Thank you.

11 Apr 2011, 6:49 PM
#2
atozstore avatar

atozstore

New Zenner

Join Date:
Mar 2011
Posts:
27
Plugin Contributions:
0

Re: Pre-select a subcategory

Update:

After reading thru the code I figured out where I can intercept the code and modified it to best suits my needs. In case anyone interested.

the file is includes/templates/MY TEMPLATE/sideboxes/tpl_categories.php around line 35

if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
// skip if this is for the document box (==3)
} else {
/////////////////////////////1.1/////////////////////////
if($box_categories_array[$i]['has_sub_cat'] && $new_style == 'category-top' ){

	  if($ul_close=='NO'){
	    $content =$content.'</ul></li>';
		$ul_close='YES';
	  }
	  $ul_close='NO';
	  if ($box_categories_array[$i]['name'] == '* PROMOTIONS *')
	  {
		$sub = get_latest_child();
		$content .= '<li><a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '_' . $sub . '">';
	  }
	  else
	  {
		$content .= '<li><a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
	  }
	  $content .= $box_categories_array[$i]['name'];
	 
	  $content =$content.'</a><ul>';
  }

function get_latest_child()
{
global $db;
$sql = 'Select * from zen_categories where parent_id = 5 order by sort_order limit 1';
$result = $db->Execute($sql);
return $result->fields['categories_id'];

}

12 Apr 2011, 4:20 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Pre-select a subcategory

In the Configuration ... Layout Settings ... you can configure it to Always Open to a specific Category on your Home page:

Categories - Always Open to Show SubCategories
Always Show Categories and SubCategories
0= off, just show Top Categories
1= on, Always show Categories and SubCategories when selected

Then set the Category with the cPath for:

Main Page - Opens with Category
0= Top Level Categories
Or enter the Category ID#
Note: Sub Categories can also be used Example: 3_10

12 Apr 2011, 4:47 PM
#4
atozstore avatar

atozstore

New Zenner

Join Date:
Mar 2011
Posts:
27
Plugin Contributions:
0

Re: Pre-select a subcategory

Ajeh:

In the Configuration ... Layout Settings ... you can configure it to Always Open to a specific Category on your Home page:

Then set the Category with the cPath for:

Ajeh,

Thanks for your help. That would works, but because the subcategory id is dynamically changed via an importing script that would make the cPath id becomes old. Also that would mean that the homepage would be populated with produts found in this subcategory right? if that's the case then it won't work because I only want to show the products when the user click on PROMOTIONS.

However, this approach is much better if you can show me how to programatically change the cPath to subcategory when my script adds a new subcategory. Thanks.

12 Apr 2011, 4:49 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Pre-select a subcategory

What if you used the PROMOTIONS Category and then the user can pick what ever Categories are in it?

12 Apr 2011, 4:53 PM
#6
gjh42 avatar

gjh42

Black Belt

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

Re: Pre-select a subcategory

The very unusual functionality of showing the latest-added subcategory of one particular top category when that is clicked can really only be done by the type of custom coding you posted above.

Others should note that the OP started from a custom mod version of tpl_categories.php, and a stock version of the file will look very different.

12 Apr 2011, 7:41 PM
#7
atozstore avatar

atozstore

New Zenner

Join Date:
Mar 2011
Posts:
27
Plugin Contributions:
0

Re: Pre-select a subcategory

Ajeh:

What if you used the PROMOTIONS Category and then the user can pick what ever Categories are in it?

Yes this is how the default works, it would list all subcats and the user can click on the subcats themselves, but because the subcats listing is too small, and I chose to use date as the title, at first look it looks like an error, so I choose to populate the page with the latest deals added to the database.
the modified code worked as intended. Thanks for your help.

12 Apr 2011, 7:46 PM
#8
atozstore avatar

atozstore

New Zenner

Join Date:
Mar 2011
Posts:
27
Plugin Contributions:
0

Re: Pre-select a subcategory

gjh42:

The very unusual functionality of showing the latest-added subcategory of one particular top category when that is clicked can really only be done by the type of custom coding you posted above.

Others should note that the OP started from a custom mod version of tpl_categories.php, and a stock version of the file will look very different.

Thanks for the clarification and comments.

12 Apr 2011, 9:24 PM
#9
atozstore avatar

atozstore

New Zenner

Join Date:
Mar 2011
Posts:
27
Plugin Contributions:
0

Re: Pre-select a subcategory

Hi again,

The code above works most of the time, but when I clear cookie the link becomes like this
index.php?main_page=index&cPath=5&zenid=a9a6d04fcbf670a151bce972f8e9bb99_19

Instead of something like this
index.php?main_page=index&cPath=5_15

What is the zenid parameter for? it seems that some other part of the code generates that link and put it underneath the PROMOTION category. Any pointer is appreciated.

13 Apr 2011, 1:30 AM
#10
gjh42 avatar

gjh42

Black Belt

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

Re: Pre-select a subcategory

Zenid is the session id which keeps track of the individual customer's settings, cart contents, etc. It has to appear on the first page visit, but if cookies are enabled, it is thereafter passed by cookie and not in the URL.

13 Apr 2011, 5:45 AM
#11
atozstore avatar

atozstore

New Zenner

Join Date:
Mar 2011
Posts:
27
Plugin Contributions:
0

Re: Pre-select a subcategory

gjh42:

Zenid is the session id which keeps track of the individual customer's settings, cart contents, etc. It has to appear on the first page visit, but if cookies are enabled, it is thereafter passed by cookie and not in the URL.

gjh42,

Thanks, I noticed that I concatenated the subcat to the main cat after Zen added the cookie, that's why it produces unexpected results. I already correct the problem by moving the cookie to the end of the string.