2

I am wanting to be able to have three different styled drop downs in my Menu. I would like to be able to change the style type using a category attribute.

What I imagine is to be able to go to a category and select the type of dropdown style that will appear in the main navigation for the individual category if there are subcategories.

For example i have three links in my nav that each have three subcategories:

Link 1

  • List item
  • List item
  • List item

Link 2

  • List item
  • List item
  • List item

Link 3

  • List item
  • List item
  • List item

(They will be in a line but cant put them in a line in this post for some reason)

I want to be able to have Link 1's drop down to be a full page dropdown mega menu style, Link 2 to be an ordinary thinner styled dropdown and Link 3 to be a full size dropdown that can include images.

In the category section of the admin area I would like a new group to be added labeled Menu with a selector dropdown with the options:

  • Style 1
  • Style 2
  • Style 3

When you select one of the styles, in the Selector dropdown, the class or classes will change in the html for the Main Navigation on the frontend that will apply the different css styles to create the correct look for the selected category sub menu dropdown.

I have done the three styles in css and so far I can have which ever look i want by changing the class manually but can only have one or the other for all categories.

I have started to create the module for it but have hit a wall. Here is my mysql install code so far:

    <?php
$installer = $this;
$installer->startSetup();
$attribute  = array(
    'type'          =>  'text',
    'label'         =>  'Navigation Type',
    'input'         =>  'select',
    'global'        =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible'       =>  true,
    'required'      =>  false,
    'user_defined'  =>  true,
    'group'         =>  "Menu"
);
$installer->addAttribute('catalog_category', 'Navigation_Type_Select', $attribute);
$installer->endSetup();

This creates the Group tab and the Selector dropdown.

However I:

  1. Don't know how to populate the Selector dropdown options
  2. Don't know how to when the type is selected apply the class to the html

Any help would be greatly appreciated.

I apologise for the length of this question I wanted to be through in my explanation. Let me know if any one requires additional information.

********** UPDATE **********

I have managed to get the dropdown and the dropdown values working by doing the following:

Added Mypackage > Mymodule > Model > Source > Style.php

    <?php

class Mypackage_Mymodule_Model_Source_Style extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    public function getAllOptions()
    {
        $options = array(
            1 => 'Style 1',
            2 => 'Style 2',
            3 => 'Style 3'
        );

        return $options;
    }
}

?>

And edited the mysql-upgrade:

<?php
$installer = $this;
$installer->startSetup();
$attribute  = array(
    'type'              =>  'int',
    'label'             =>  'Menu Style',
    'backend'           => '',
    'visible_on_front'  => false,
    'input'             =>  'select',
    'source'            =>  'Mypackage_Mymodule_Model_Source_Style',
    'global'            =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible'           =>  true,
    'required'          =>  false,
    'user_defined'      =>  true,
    'default'           =>  "",
    'group'             =>  "Menu Style"
);
$installer->addAttribute('catalog_category', 'Menu_Style', $attribute);
$installer->endSetup();
?>

What I need to know how can I use this to change a class do I

a.) Set a script up to change the class depening on what option is selected. If so whats the best way

or

b.) Use php if statements in the html for the class depending on what option is selected.

or

c.) A better option?

Any help would be very much appreciated.

Thanks.

  • Can you get the value for the attribute which you saved? – Mujahidh Dec 13 '15 at 13:02
  • Yes and I am going to also update the question as i have advanced a little further please see edit in the original question. – Ads Dec 14 '15 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.