Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Main Categories as a drop down list

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #61  
Old 09-14-2011, 08:10 AM
 
Jeremy Smith Jeremy Smith is offline
 

Senior Member
  
Join Date: Jan 2009
Posts: 167
 

Thumbs up Re: Main Categories as a drop down list

This is mainly for my own notes but I thought I would share this with you.

Here's some smarty logic to show you that works on the basis that if you don't select a root category, then the sub categories are disabled from being selected.

HTML Code:
{* $Id: categories.tpl,v 1.26.2.4 2008/07/22 07:58:28 ferz Exp $ *} {capture name=menu} {if $active_modules.Fancy_Categories ne ""} {assign var="fc_cellpadding" value="0"} {else} {if $config.General.root_categories eq "Y"} <form name="catForm">Manufacturer: <select name="rootCat" onChange="window.location=document.catForm.rootCat.options[document.catForm.rootCat.selectedIndex].value"> <option value="">Please select: </option> {foreach from=$categories item=c} {if $current_category.parentid lt "0"} <option value="home.php?cat={$c.categoryid}">{$c.category}</option> {elseif $current_category.parentid eq "0"} <option value="home.php?cat={$c.categoryid}" {if $current_category.categoryid eq $c.categoryid} selected {/if}>{$c.category}</option> {else} <option value="home.php?cat={$c.categoryid}" {if $current_category.parentid eq $c.categoryid} selected {/if}>{$c.category}</option> {/if} {/foreach} </select> Model: {if $current_category.parentid lt "0"} <select id="subCat" name="subCat" disabled> <option value=""></option> </select> {else} <select id="subCat" name="subCat"> <option value="#">Please select</option> {foreach from=$subcategories item=c key=catid} <option value="home.php?cat={$catid}">{$c.category}</option> {/foreach} </select> {/if} <input type="button" name="go" value="Select" onClick="window.location=document.catForm.subCat.options[document.catForm.subCat.selectedIndex].value"> </form> {else} {/if} {/if} {/capture} { include file="menuDropDown.tpl" menu_content=$smarty.capture.menu } </div> <div id="printerSearchBottom"></div>

But I have a problem, what if anyone wanted to select another printer model?

I mean at the moment when you go into a sub category on our site you can not then go into another sub category for that root category if that makes any sense?

Let me explain this a bit better, say I wanted to buy a Brother printer A's cartridges but then I would not see Printer B's cartridges as I have that printer also, I would then find that annoying and go to another site, if you're with me?

If there anyway of still showing all subcategories within a given root?

But also I wanted to be able to disable the select button based on if a sub category has been selected is there anyway of doing this or at least when a root category has been selected?

Bearing in mind we are using v4.1.11 here, any replies is much appreciated and hope this helps some people

Really all you do is look at your HTML source and your smarty tags output and compare them together if they equal each other the category id then show selected in the options value, if they don't then don't it's that simple.

See I tried this one here:

HTML Code:
<a href="#" target="_blank" title="" class="noborder"><img src="/skin1/images/eCommsStoreLocator.gif" border="0" style="margin-bottom:10px;"/></a> <div id="printerSearchTop"><h2>Printer Search</h2></div> <div id="printerSearchMiddle"> {* $Id: categories.tpl,v 1.26.2.4 2008/07/22 07:58:28 ferz Exp $ *} {capture name=menu} {if $active_modules.Fancy_Categories ne ""} {assign var="fc_cellpadding" value="0"} {else} {if $config.General.root_categories eq "Y"} <form name="catForm">Manufacturer: <select name="rootCat" onChange="window.location=document.catForm.rootCat.options[document.catForm.rootCat.selectedIndex].value"> <option value="">Please select: </option> {foreach from=$categories item=c} {if $current_category.parentid lt "0"} <option value="home.php?cat={$c.categoryid}">{$c.category}</option> {elseif $current_category.parentid eq "0"} <option value="home.php?cat={$c.categoryid}" {if $current_category.categoryid eq $c.categoryid} selected {/if}>{$c.category}</option> {else} <option value="home.php?cat={$c.categoryid}" {if $current_category.parentid eq $c.categoryid} selected {/if}>{$c.category}</option> {/if} {/foreach} </select> Model: {if $current_category.parentid lt "0"} <select id="subCat" name="subCat" disabled> <option value=""></option> </select> {else} <select id="subCat" name="subCat"> <option value="#">Please select</option> {foreach from=$subcategories item=c key=catid} <option value="home.php?cat={$catid}">{$c.category}</option> {/foreach} </select> {/if} {if $current_category.parentid gt "0"} <input type="button" name="go" value="Select" onClick="window.location=document.catForm.subCat.options[document.catForm.subCat.selectedIndex].value"> {else} <input type="button" name="go" value="Select" onClick="window.location=document.catForm.subCat.options[document.catForm.subCat.selectedIndex].value" disabled> {/if} </form> {else} {/if} {/if} {/capture} { include file="menuDropDown.tpl" menu_content=$smarty.capture.menu } </div> <div id="printerSearchBottom"></div>

But as soon as it gets to this point here:
HTML Code:
{if $current_category.parentid gt "0"} <input type="button" name="go" value="Select" onClick="window.location=document.catForm.subCat.options[document.catForm.subCat.selectedIndex].value"> {else} <input type="button" name="go" value="Select" onClick="window.location=document.catForm.subCat.options[document.catForm.subCat.selectedIndex].value" disabled> {/if}

It still disables the submit button, any help's appreciated,
Jeremy.
__________________
Version 4.1.11 on Linux (Fedora)
X-Cart Gold
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:14 PM.

   

 
X-Cart forums © 2001-2020