Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added menu item type selection. Added category and external link types

  • Loading branch information...
commit 783c1fc72d7360e4a893f12b20347fe1a50f683e 1 parent 1e2c9da
@hws47a authored
View
1  .gitignore
@@ -0,0 +1 @@
+/.idea
View
15 README
@@ -1,16 +1,13 @@
A custom magento menu
Replace generated magento menu with own custom menu.
-Use admin page to add menu items (name, title, link, position)
+Use admin page to add menu items "Custom Modules -> Custom Menu"
-Also you can show in menu popup links to layered navigation for some attribute
-You can choose attribute and default category. In menu popup you will see
-all attribute options that you see in layered navigation for this category
+You can choose from this types of menu items:
+* Internal link (Example: about-us.html)
+* External link (Example: http://example.com)
+* Category (Select a category to show its link)
+* Attribute Values (Select a category and attribute, to show attribute values for this category from layered navigation)
-Usage:
-
-go to "Custom Modules -> Custom Menu" and add items to menu
-
-Install:
Read about installation in INSTALL file
View
11 app/code/local/VF/CustomMenu/Block/Adminhtml/Menu/Edit/Form.php
@@ -61,6 +61,15 @@ protected function _prepareForm()
'name' => 'label'
));
+ /** @var Varien_Data_Form_Element_Select */
+ var_dump(get_class($fieldSet->addField('type', 'select', array(
+ 'label' => $this->__('Type'),
+ 'class' => 'required-entry',
+ 'required' => 'true',
+ 'name' => 'type',
+ 'options' => VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::getValues()
+ ))));
+
$fieldSet->addField('url', 'text', array(
'label' => $this->__('Url'),
'class' => 'required-entry',
@@ -101,7 +110,7 @@ protected function _prepareForm()
}
$fieldSet->addField('default_category', 'select', array(
- 'label' => $this->__('Default Category'),
+ 'label' => $this->__('Category'),
'name' => 'default_category',
'note' => $this->__('Custom default category'),
'values' => $values
View
52 app/code/local/VF/CustomMenu/Block/Adminhtml/Menu/Grid.php
@@ -65,45 +65,39 @@ protected function _prepareCollection()
protected function _prepareColumns()
{
$this->addColumn('item_id', array(
- 'header' => $this->__('ID'),
- 'align' => 'right',
- 'width' => '50px',
- 'type' => 'int',
- 'index' => 'item_id'
+ 'header' => $this->__('ID'),
+ 'align' => 'right',
+ 'width' => '50px',
+ 'type' => 'int',
+ 'index' => 'item_id'
));
$this->addColumn('label', array(
- 'header' => $this->__('Label'),
- 'align' => 'left',
- 'index' => 'label'
+ 'header' => $this->__('Label'),
+ 'align' => 'left',
+ 'index' => 'label'
));
- $this->addColumn('url', array(
- 'header' => $this->__('Url'),
- 'align' => 'left',
- 'index' => 'url'
+ $this->addColumn('type', array(
+ 'header' => $this->__('Type'),
+ 'align' => 'left',
+ 'index' => 'type',
+ 'type' => 'options',
+ 'options' => VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::getValues()
));
- $this->addColumn('title', array(
- 'header' => $this->__('Title'),
- 'align' => 'left',
- 'index' => 'title'
- ));
-
- $this->addColumn('source_attribute', array(
- 'header' => $this->__('Source Attribute'),
- 'align' => 'left',
- 'width' => '50px',
- 'index' => 'source_attribute',
- 'type' => 'options',
- 'options' => Mage::getModel('menu/attribute')->getOptions()
+ $this->addColumn('info', array(
+ 'header' => $this->__('Info'),
+ 'align' => 'left',
+ 'index' => 'info',
+ 'renderer' => 'VF_CustomMenu_Block_Adminhtml_Menu_Grid_Renderer_Info'
));
$this->addColumn('position', array(
- 'header' => $this->__('Position'),
- 'align' => 'left',
- 'width' => '50px',
- 'index' => 'position'
+ 'header' => $this->__('Position'),
+ 'align' => 'left',
+ 'width' => '50px',
+ 'index' => 'position'
));
return parent::_prepareColumns();
View
66 app/code/local/VF/CustomMenu/Block/Adminhtml/Menu/Grid/Renderer/Info.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * VF extension for Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade
+ * the VF CustomMenu module to newer versions in the future.
+ * If you wish to customize the VF CustomMenu module for your needs
+ * please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category VF
+ * @package VF_CustomMenu
+ * @copyright Copyright (C) 2012 Vladimir Fishchenko (http://fishchenko.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+
+/**
+ * Menu Grid Info Renderer
+ *
+ * @category VF
+ * @package VF_CustomMenu
+ * @subpackage Block
+ * @author Vladimir Fishchenko <vladimir.fishchenko@gmail.com>
+ */
+class VF_CustomMenu_Block_Adminhtml_Menu_Grid_Renderer_Info
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
+{
+ /**
+ * Render information about menu item
+ *
+ * @param Varien_Object $row
+ * @return string
+ */
+ public function render(Varien_Object $row)
+ {
+ $helper = Mage::helper('menu');
+ switch ($row->getType()) {
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::LINK_INTERNAL:
+ return '<strong>' . $helper->__('Path') . ':</strong> ' . $row->getUrl();
+ break;
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::LINK_EXTERNAL:
+ return '<strong>' . $helper->__('Link') . ':</strong> ' . $row->getUrl();
+ break;
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::CATEGORY:
+ return '<strong>' . $helper->__('Category') . ':</strong> '
+ . Mage::getModel('catalog/category')->load($row->getDefaultCategory(), array('name'))->getName();
+ break;
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::ATTRIBUTE:
+ return '<strong>' . $helper->__('Attribute code') . ':</strong> '
+ . $row->getSourceAttribute()
+ . ' <strong>' . $helper->__('Category') . ':</strong> '
+ . Mage::getModel('catalog/category')->load($row->getDefaultCategory(), array('name'))->getName();
+ break;
+ default:
+ return '';
+ }
+ }
+}
View
27 app/code/local/VF/CustomMenu/Block/Navigation.php
@@ -74,16 +74,36 @@ public function getMenuItems()
public function getItemUrl(VF_CustomMenu_Model_Menu $item)
{
$url = ltrim($item->getUrl());
- return (strpos($url, 'javascript:') === false) ? Mage::getBaseUrl() . $url : $url;
+ switch ($item->getType()) {
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::LINK_INTERNAL:
+ return Mage::getBaseUrl() . $url;
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::LINK_EXTERNAL:
+ return $url;
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::CATEGORY:
+ return $item->getCategory()->getUrl();
+ case VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type::ATTRIBUTE:
+ return 'javascript:;';
+ default:
+ return $url;
+ }
}
+ /**
+ * get Dynamic block
+ * It's a attribute values or child categories
+ *
+ * @param VF_CustomMenu_Model_Menu $item
+ * @param int $itemNumber
+ * @return mixed
+ */
public function getDynamicBlock(VF_CustomMenu_Model_Menu $item, $itemNumber = null)
{
if (!$item->hasData('dynamic_block')) {
$block = '';
if ($item->getSourceAttribute()) {
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
- $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $item->getSourceAttribute());
+ $attribute = Mage::getSingleton('eav/config')
+ ->getAttribute('catalog_product', $item->getSourceAttribute());
/** @var $catalogIndexAttribute Mage_CatalogIndex_Model_Attribute */
$catalogIndexAttribute = Mage::getSingleton('catalogindex/attribute');
@@ -136,7 +156,8 @@ public function getDynamicBlock(VF_CustomMenu_Model_Menu $item, $itemNumber = nu
$href = $rootCategory->getUrl() . '?' . http_build_query($params['_query']);
}
- $block .= "<li{$class}><a href=\"{$href}\"><span>{$this->escapeHtml($_item['label'])}</span></a></li>";
+ $block .= "<li{$class}><a href=\"{$href}\">"
+ . "<span>{$this->escapeHtml($_item['label'])}</span></a></li>";
}
$block .= "</ul>\n";
}
View
10 app/code/local/VF/CustomMenu/Model/Attribute.php
@@ -32,6 +32,11 @@
*/
class VF_CustomMenu_Model_Attribute
{
+ /**
+ * get ln attributes
+ *
+ * @return array
+ */
public function getSourceAttributes()
{
$values = array(array('label' => '', 'value' => ''));
@@ -50,6 +55,11 @@ public function getSourceAttributes()
return array_values($values);
}
+ /**
+ * get as options
+ *
+ * @return array
+ */
public function getOptions()
{
$options = array();
View
15 app/code/local/VF/CustomMenu/Model/Menu.php
@@ -60,4 +60,19 @@ public function getDefaultCategoryId()
}
return $category;
}
+
+ /**
+ * @return Mage_Catalog_Model_Category
+ */
+ public function getCategory()
+ {
+ if (!$this->hasData('category_object')) {
+ $category = Mage::getModel('catalog/category');
+ if ($this->getDefaultCategory()) {
+ $category->load($this->getDefaultCategory());
+ }
+ $this->setData('category_object', $category);
+ }
+ return $this->getData('category_object');
+ }
}
View
55 app/code/local/VF/CustomMenu/Model/Resource/Menu/Attribute/Source/Type.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * VF extension for Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade
+ * the VF CustomMenu module to newer versions in the future.
+ * If you wish to customize the VF CustomMenu module for your needs
+ * please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category VF
+ * @package VF_CustomMenu
+ * @copyright Copyright (C) 2012 Vladimir Fishchenko (http://fishchenko.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+
+/**
+ * VF Custom Menu Item Types
+ *
+ * @category VF
+ * @package VF_CustomMenu
+ * @subpackage Model
+ * @author Vladimir Fishchenko <vladimir.fishchenko@gmail.com>
+ */
+class VF_CustomMenu_Model_Resource_Menu_Attribute_Source_Type
+{
+ const LINK_INTERNAL = 1;
+ const LINK_EXTERNAL = 2;
+ const CATEGORY = 3;
+ const ATTRIBUTE = 4;
+
+ /**
+ * Get Menu Item Type Values
+ *
+ * @return array
+ */
+ public static function getValues()
+ {
+ $helper = Mage::helper('menu');
+ return array(
+ self::LINK_INTERNAL => $helper->__('Link Internal'),
+ self::LINK_EXTERNAL => $helper->__('Link External'),
+ self::CATEGORY => $helper->__('Category'),
+ self::ATTRIBUTE => $helper->__('Attribute Values'),
+ );
+ }
+}
View
2  app/code/local/VF/CustomMenu/etc/config.xml
@@ -26,7 +26,7 @@
<config>
<modules>
<VF_CustomMenu>
- <version>0.2.1</version>
+ <version>0.2.2</version>
</VF_CustomMenu>
</modules>
<global>
View
40 app/code/local/VF/CustomMenu/sql/vf_custommenu_setup/mysql4-upgrade-0.2.1-0.2.2.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * VF extension for Magento
+ *
+ * Add type column to menu table
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade
+ * the VF CustomMenu module to newer versions in the future.
+ * If you wish to customize the VF CustomMenu module for your needs
+ * please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category VF
+ * @package VF_CustomMenu
+ * @copyright Copyright (C) 2012 Vladimir Fishchenko (http://fishchenko.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+
+/**
+ * @var $this Mage_Core_Model_Resource_Setup
+ */
+
+$installer = $this;
+$installer->startSetup();
+
+$installer->getConnection()->addColumn(
+ $installer->getTable('menu/menu'),
+ 'type',
+ 'tinyint(1) not null default 1'
+);
+
+$installer->endSetup();
View
3  app/design/adminhtml/default/default/layout/menu.xml
@@ -31,6 +31,9 @@
</adminhtml_menu_index>
<adminhtml_menu_edit>
+ <reference name="head">
+ <action method="addJs"><file>custom-menu/admin.js</file></action>
+ </reference>
<reference name="content">
<block type="menu/adminhtml_menu_edit" name="menu_edit_container" />
</reference>
View
38 js/custom-menu/admin.js
@@ -0,0 +1,38 @@
+function customMenuUpdateFields(type) {
+ type = parseInt(type);
+ switch (type) {
+ case 1: //link inner
+ case 2: //link external
+ $('url').up('tr').show();
+ $('url').addClassName('required-entry');
+ $('default_category').up('tr').hide();
+ $('default_category').removeClassName('required-entry');
+ $('source_attribute').up('tr').hide();
+ $('source_attribute').removeClassName('required-entry');
+ break;
+ case 3: //category
+ $('url').up('tr').hide();
+ $('url').removeClassName('required-entry');
+ $('default_category').up('tr').show();
+ $('default_category').addClassName('required-entry');
+ $('source_attribute').up('tr').hide();
+ $('source_attribute').removeClassName('required-entry');
+ break;
+ case 4: //attribute values
+ $('url').up('tr').hide();
+ $('url').removeClassName('required-entry');
+ $('default_category').up('tr').show();
+ $('default_category').addClassName('required-entry');
+ $('source_attribute').up('tr').show();
+ $('source_attribute').addClassName('required-entry');
+ break;
+ }
+}
+
+document.observe("dom:loaded", function() {
+ var type = $('type');
+ type.observe('change', function (evt){
+ customMenuUpdateFields(type.value);
+ });
+ customMenuUpdateFields(type.value);
+});
View
1  modman
@@ -2,3 +2,4 @@ app/code/local/VF/CustomMenu app/code/local/VF/CustomMenu
app/design/adminhtml/default/default/layout/menu.xml app/design/adminhtml/default/default/layout/menu.xml
app/design/frontend/base/default/template/menu app/design/frontend/base/default/template/menu
app/etc/modules/VF_CustomMenu.xml app/etc/modules/VF_CustomMenu.xml
+js/custom-menu js/custom-menu
Please sign in to comment.
Something went wrong with that request. Please try again.