Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Magento Developers…Is this possible? 
 
Reben002
Member
 
Total Posts:  41
Joined:  2009-02-13
 

Hello there people

I’ve been struggling with inserting of a specific JavaScript. Basically i want a dropdown listbox to replace my navigation bar and i’ve been fighting with it for weeks now........

I want to get this simple look

This is what I’ve done:

1. I written down the java function at js/varien/dropdownmeny.js

function dropdownmeny() {
var URL document.menyform.listmeny.options[document.menyform.listmeny.selectedIndex].value;

[removed].href URL}

2.  In the default\default\layout\page.xml i added

<action method="addJs">
  <
script>varien/dropdown.js</script> 
  
</action>

3. Now people is the tricky part. What shall i write in catalog\navigation\top.phtml

<form name="menyform">
<
select name="listmeny" onChange="dropdownmeny()">

<
option selected value="Choose">Choose</option>

[color=gray]// For each topcategory I want a Dropdown list with subcategories !![/color]

<option value=" //What kind of php forech should i write here then????// ">Ananas</option>


</
select>
</
form>

//And as i said before I want it to create a dropdown for each topcategory with subcategories

Is this even possible???????????????? :D

Image Attachments
pad.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
LostDocs7
Member
 
Avatar
Total Posts:  31
Joined:  2008-12-03
 

Hi,

Try this code and examine its output. This is quick adaptation of vertical menu for your needs. It builds dropdown for each top level category.

<?php 
function showCategory$current_category$object$is_subcat ){
    
if( !$current_category->getIsActive() ){
        
return;
    
}
    
if ($is_subcat == true){
        
echo '<option value="'.$object->getCategoryUrl$current_category ).'">' $object->htmlEscape$current_category->getName() ) . '</option>';
    
}
    else{
        
echo $object->htmlEscape$current_category->getName() ) . '<br>';
    
}        
    
if ( ( $children $current_category->getChildren() ) && $children->count() ){
        
if ($is_subcat == false){
            
echo '<select>';
        
}
        
foreach ( $children as $child_category){
                showCategory
$child_category$objecttrue );
            
}
        
if ($is_subcat == false){
            
echo '</select><br><br>';
        
}
    }
}
$_categories
=$this->getStoreCategories();
foreach (
$_categories as $category){
    showCategory
$category$thisfalse );
}
?>

Of course you need to complete it to work with your custom JS

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

hi,

here is another example. see this post

http://www.magentocommerce.com/boards/viewthread/5500/

this code allows you to specify variable settings. For example only show drop if layered nav items >5

on my current site im using this code to good effect

http://www.getstuff.com.au/bathroom/basins/vanity-basins

hth
brendan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Reben002
Member
 
Total Posts:  41
Joined:  2009-02-13
 

Amazing LostDocs7 :D that script really worked flawless! And thanks for the other tips guys!

LostDocs7 or anyone, is it possible so add a special option class to the subcategories? I would bee perfect if they were more spaced to the right to make it more easy for the eye!

And if that’s possible, where should i put the subcategory option class in this script?

<?php 
function showCategory$current_category$object$is_subcat ){
    
if( !$current_category->getIsActive() ){
        
return;
    
}
    
if ($is_subcat == true){
        
echo '<option value="'.$object->getCategoryUrl$current_category ).'">' $object->htmlEscape$current_category->getName() ) . '</option>';
    
}
    else{
        
echo $object->htmlEscape$current_category->getName() ) . '<br>';
    
}        
    
if ( ( $children $current_category->getChildren() ) && $children->count() ){
        
if ($is_subcat == false){
            
echo '<select>';
        
}
        
foreach ( $children as $child_category){
                showCategory
$child_category$objecttrue );
            
}
        
if ($is_subcat == false){
            
echo '</select><br><br>';
        
}
    }
}
$_categories
=$this->getStoreCategories();
foreach (
$_categories as $category){
    showCategory
$category$thisfalse );
}
?>

This is what I ultimatly want to acheive

Image Attachments
padning.JPG
 
Magento Community Magento Community
Magento Community
Magento Community
 
LostDocs7
Member
 
Avatar
Total Posts:  31
Joined:  2008-12-03
 

Add you class name to the line where “option” tag is or “select”. Not sure what exactly you need.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Reben002
Member
 
Total Posts:  41
Joined:  2009-02-13
 

I would like to have some space at the subcategories from the left side like this:

Camera (top category)
Canon (subcategory)
Fuju(subcategory)
Nikon (subcategory)
Lasolite (subcategory)

Image Attachments
padning.JPG
 
Magento Community Magento Community
Magento Community
Magento Community
 
LostDocs7
Member
 
Avatar
Total Posts:  31
Joined:  2008-12-03
 

Try this code, I added to pad for each level

<?php 
function showCategory$current_category$object$level ){
    
if( !$current_category->getIsActive() ){
        
return;
    
}
    
if ($level 0){
        
echo '<option value="'.$object->getCategoryUrl$current_category ).'">' str_repeat('&nbsp;'$level) . $object->htmlEscape$current_category->getName() ) . '</option>';
    
}
    else{
        
echo $object->htmlEscape$current_category->getName() ) . '<br>';
    
}        
    
if ( ( $children $current_category->getChildren() ) && $children->count() ){
        
if ($level == 0){
            
echo '<select>';
        
}
        
foreach ( $children as $child_category){
                showCategory
$child_category$object$level++ );
            
}
        
if ($level == 0){
            
echo '</select><br><br>';
        
}
    }
}
$_categories
=$this->getStoreCategories();
foreach (
$_categories as $category){
    showCategory
$category$this);
}
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Reben002
Member
 
Total Posts:  41
Joined:  2009-02-13
 

Ok, but it came ut a little bit weird. There was a space for all subcategories, resulting to a pyrmaid-like dropdown, (see attached image).

Kamera(top categori)
Canon(subcategory level 1)
Fuji(subcategory level 1)
Nikon(subcategory level 1)

I’m lookning for each level to have the same space.  see attached image

Latest script

Kamera(top categori)
Canon(subcategory level 1)
Fuji(subcategory level 1)
Nikon(subcategory level 1)

That would be awesome!
Thanks for the awnsers man

Image Attachments
fel.JPG
 
Magento Community Magento Community
Magento Community
Magento Community
 
LostDocs7
Member
 
Avatar
Total Posts:  31
Joined:  2008-12-03
 

try this

<?php 
function showCategory$current_category$object$level ){
    
if( !$current_category->getIsActive() ){
        
return;
    
}
    
if ($level 0){
        
echo '<option value="'.$object->getCategoryUrl$current_category ).'">' str_repeat('&nbsp;&nbsp;'$level) . $object->htmlEscape$current_category->getName() ) . '</option>';
    
}
    else{
        
echo $object->htmlEscape$current_category->getName() ) . '<br>';
    
}        
    
if ( ( $children $current_category->getChildren() ) && $children->count() ){
        
if ($level == 0){
            
echo '<select>';
        
}
        $level
++;
        foreach ( 
$children as $child_category){
                showCategory
$child_category$object$level );
            
}
        
if ($level == 0){
            
echo '</select><br><br>';
        
}
    }
}
$_categories
=$this->getStoreCategories();
foreach (
$_categories as $category){
    showCategory
$category$this);
}
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Reben002
Member
 
Total Posts:  41
Joined:  2009-02-13
 

Nice!

Been a while, but got one question.
The navigation soultion is perfect but is there any possibility to add an sortby function? By that i mean if it is possible to when a category is chosen, other categories disapear and only categories with products remain?

Thanks bro ! :D

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top