Iwebics_LayeredCategory - Version 1.0.0

Version Notes

Out Layered Category extension gives you the maximum flexibility to set category wise layered navigation. Layered Category enables you to set different layered navigation for different category.You can also set default layered navigation from configuration settings.

Download this release

Release Info

Developer Iwebics
Extension Iwebics_LayeredCategory
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Iwebics/LayeredCategory/Block/Catalog/Category/Helper/Filterby/Available.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ class Iwebics_LayeredCategory_Block_Catalog_Category_Helper_Filterby_Available extends Varien_Data_Form_Element_Multiselect
10
+ {
11
+ /**
12
+ * Retrieve Element HTML fragment
13
+ *
14
+ * @return string
15
+ */
16
+ public function getElementHtml()
17
+ {
18
+ $disabled = false;
19
+ if (!$this->getValue()) {
20
+ $this->setData('disabled', 'disabled');
21
+ $disabled = true;
22
+ }
23
+ $html = parent::getElementHtml();
24
+ $htmlId = 'use_config_' . $this->getHtmlId();
25
+ $html .= '<input id="'.$htmlId.'" name="use_config[]" value="' . $this->getId() . '"';
26
+ $html .= ($disabled ? ' checked="checked"' : '');
27
+
28
+ if ($this->getReadonly()) {
29
+ $html .= ' disabled="disabled"';
30
+ }
31
+
32
+ $html .= ' onclick="toggleValueElements(this, this.parentNode);" class="checkbox" type="checkbox" />';
33
+
34
+ $html .= ' <label for="'.$htmlId.'" class="normal">'
35
+ . Mage::helper('adminhtml')->__('Use Config Settings').'</label>';
36
+ $html .= '<script type="text/javascript">toggleValueElements($(\''.$htmlId.'\'), $(\''.$htmlId.'\').parentNode);</script>';
37
+
38
+ return $html;
39
+ }
40
+ }
app/code/local/Iwebics/LayeredCategory/Helper/Data.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ class Iwebics_LayeredCategory_Helper_Data extends Mage_Core_Helper_Abstract
10
+ {
11
+ protected function getCurrentCategory()
12
+ {
13
+ return Mage::registry('current_category');
14
+ }
15
+ public function getAvailableFilter()
16
+ {
17
+ if($category = $this->getCurrentCategory()){
18
+ if($category->getAvailableFilterBy())
19
+ return $category->getAvailableFilterBy();
20
+ }
21
+ return explode(',',Mage::getStoreConfig('catalog/layered_navigation/default_layered_attribute'));
22
+ }
23
+ }
app/code/local/Iwebics/LayeredCategory/Model/Catalog/Category/Attribute/Backend/Filterby.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ class Iwebics_LayeredCategory_Model_Catalog_Category_Attribute_Backend_Filterby extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
10
+ {
11
+ /**
12
+ * Validate process
13
+ *
14
+ * @param Varien_Object $object
15
+ * @return bool
16
+ */
17
+ public function validate($object)
18
+ {
19
+ $attributeCode = $this->getAttribute()->getName();
20
+ $postDataConfig = ($object->getData('use_post_data_config'))? $object->getData('use_post_data_config') : array();
21
+
22
+ $isUseConfig = false;
23
+ if ($postDataConfig) {
24
+ $isUseConfig = in_array($attributeCode, $postDataConfig);
25
+ }
26
+
27
+ if ($this->getAttribute()->getIsRequired()) {
28
+ $attributeValue = $object->getData($attributeCode);
29
+ if ($this->getAttribute()->isValueEmpty($attributeValue)) {
30
+ if (is_array($attributeValue) && count($attributeValue)>0) {
31
+ } else {
32
+ if(!$isUseConfig) {
33
+ return false;
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ if ($this->getAttribute()->getIsUnique()) {
40
+ if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) {
41
+ $label = $this->getAttribute()->getFrontend()->getLabel();
42
+ Mage::throwException(Mage::helper('eav')->__('The value of attribute "%s" must be unique.', $label));
43
+ }
44
+ }
45
+
46
+
47
+
48
+ return true;
49
+ }
50
+
51
+ /**
52
+ * Before Attribute Save Process
53
+ *
54
+ * @param Varien_Object $object
55
+ * @return Mage_Catalog_Model_Category_Attribute_Backend_Sortby
56
+ */
57
+ public function beforeSave($object) {
58
+ $attributeCode = $this->getAttribute()->getName();
59
+ if ($attributeCode == 'available_filter_by') {
60
+ $data = $object->getData($attributeCode);
61
+ if (!is_array($data)) {
62
+ $data = array();
63
+ }
64
+ $object->setData($attributeCode, join(',', $data));
65
+ }
66
+ if (is_null($object->getData($attributeCode))) {
67
+ $object->setData($attributeCode, false);
68
+ }
69
+ return $this;
70
+ }
71
+
72
+ public function afterLoad($object) {
73
+ $attributeCode = $this->getAttribute()->getName();
74
+ if ($attributeCode == 'available_filter_by') {
75
+ $data = $object->getData($attributeCode);
76
+ if ($data) {
77
+ $object->setData($attributeCode, explode(',', $data));
78
+ }
79
+ }
80
+ return $this;
81
+ }
82
+ }
app/code/local/Iwebics/LayeredCategory/Model/Catalog/Category/Attribute/Source/Filterby.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ class Iwebics_LayeredCategory_Model_Catalog_Category_Attribute_Source_Filterby extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
10
+ {
11
+ protected $_usedForFilterBy;
12
+ /**
13
+ * Retrieve Catalog Config Singleton
14
+ *
15
+ * @return Mage_Catalog_Model_Config
16
+ */
17
+ protected function _getCatalogConfig() {
18
+ return Mage::getSingleton('catalog/config');
19
+ }
20
+
21
+ /**
22
+ * Retrieve All options
23
+ *
24
+ * @return array
25
+ */
26
+ public function getAllOptions()
27
+ {
28
+ if (is_null($this->_options)) {
29
+
30
+ foreach ($this->getAttributesUsedForFilterBy() as $attribute) {
31
+ $this->_options[] = array(
32
+ 'label' => Mage::helper('catalog')->__($attribute['frontend_label']),
33
+ 'value' => $attribute['attribute_code']
34
+ );
35
+ }
36
+ }
37
+ return $this->_options;
38
+ }
39
+
40
+ public function getAttributesUsedForFilterBy() {
41
+ if (is_null($this->_usedForFilterBy)) {
42
+ $this->_usedForFilterBy = array();
43
+ $entityType = Mage_Catalog_Model_Product::ENTITY;
44
+ $attributesData = $this->getAttributesUsedForFilterByData();
45
+ Mage::getSingleton('eav/config')
46
+ ->importAttributesData($entityType, $attributesData);
47
+ foreach ($attributesData as $attributeData) {
48
+ $attributeCode = $attributeData['attribute_code'];
49
+ $this->_usedForFilterBy[$attributeCode] = Mage::getSingleton('eav/config')
50
+ ->getAttribute($entityType, $attributeCode);
51
+ }
52
+ }
53
+ return $this->_usedForFilterBy;
54
+ }
55
+
56
+ protected function getAttributesUsedForFilterByData()
57
+ {
58
+ $resource = Mage::getModel('core/resource');
59
+ $readAdaptor = $resource->getConnection('core_read');
60
+
61
+ //$readAdaptor = $this->_getReadAdapter();
62
+ $storeLabelExpr = $readAdaptor->getCheckSql('al.value IS NULL', 'main_table.frontend_label','al.value');
63
+ $select = $readAdaptor->select()
64
+ ->from(array('main_table' => $resource->getTableName('eav/attribute')))
65
+ ->join(
66
+ array('additional_table' => $resource->getTableName('catalog/eav_attribute')),
67
+ 'main_table.attribute_id = additional_table.attribute_id',
68
+ array()
69
+ )
70
+ ->joinLeft(
71
+ array('al' => $resource->getTableName('eav/attribute_label')),
72
+ 'al.attribute_id = main_table.attribute_id AND al.store_id = 0',
73
+ array('store_label' => $storeLabelExpr)
74
+ )
75
+ ->where('main_table.entity_type_id = 4')
76
+ ->where('additional_table.is_filterable = ?', 1);
77
+
78
+ return $readAdaptor->fetchAll($select);
79
+ }
80
+ }
app/code/local/Iwebics/LayeredCategory/Model/Catalog/Layer.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ class Iwebics_LayeredCategory_Model_Catalog_Layer extends Mage_Catalog_Model_Layer
10
+ {
11
+ /**
12
+ * Add filters to attribute collection
13
+ *
14
+ * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection $collection
15
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection
16
+ */
17
+ protected function _prepareAttributeCollection($collection)
18
+ {
19
+ $availableFilter = Mage::helper('layeredcategory')->getAvailableFilter();
20
+
21
+ $collection ->addFieldToFilter('attribute_code',array('in'=>$availableFilter))
22
+ ->addIsFilterableFilter();
23
+ return $collection;
24
+ }
25
+ }
app/code/local/Iwebics/LayeredCategory/Model/Catalogsearch/Layer.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ class Iwebics_LayeredCategory_Model_Catalogsearch_Layer extends Mage_CatalogSearch_Model_Layer
10
+ {
11
+ /**
12
+ * Add filters to attribute collection
13
+ *
14
+ * @param Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection $collection
15
+ * @return Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection
16
+ */
17
+ protected function _prepareAttributeCollection($collection)
18
+ {
19
+ $availableFilter = Mage::helper('layeredcategory')->getAvailableFilter();
20
+
21
+ $collection ->addFieldToFilter('attribute_code',array('in'=>$availableFilter))
22
+ ->addIsFilterableInSearchFilter()
23
+ ->addVisibleFilter();
24
+ return $collection;
25
+ }
26
+ }
app/code/local/Iwebics/LayeredCategory/Model/System/Config/Source/Filterby.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ class Iwebics_LayeredCategory_Model_System_Config_Source_Filterby
10
+ {
11
+ protected $_options;
12
+ public function toOptionArray($isMultiselect=false)
13
+ {
14
+ if (!$this->_options) {
15
+ $this->_options = Mage::getModel('layeredcategory/catalog_category_attribute_source_filterby')->getAllOptions();
16
+ }
17
+
18
+ $options = $this->_options;
19
+ if(!$isMultiselect){
20
+ array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
21
+ }
22
+
23
+ return $options;
24
+ }
25
+ }
app/code/local/Iwebics/LayeredCategory/etc/config.xml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * @category Iwebics
7
+ * @package Iwebics_LayeredCategory
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Iwebics_LayeredCategory>
13
+ <version>0.0.1</version>
14
+ </Iwebics_LayeredCategory>
15
+ </modules>
16
+ <global>
17
+ <blocks>
18
+ <layeredcategory>
19
+ <class>Iwebics_LayeredCategory_Block</class>
20
+ </layeredcategory>
21
+ </blocks>
22
+ <models>
23
+ <layeredcategory>
24
+ <class>Iwebics_LayeredCategory_Model</class>
25
+ </layeredcategory>
26
+ <catalog>
27
+ <rewrite>
28
+ <layer>Iwebics_LayeredCategory_Model_Catalog_Layer</layer>
29
+ </rewrite>
30
+ </catalog>
31
+ <catalogsearch>
32
+ <rewrite>
33
+ <layer>Iwebics_LayeredCategory_Model_Catalogsearch_Layer</layer>
34
+ </rewrite>
35
+ </catalogsearch>
36
+ </models>
37
+ <helpers>
38
+ <layeredcategory>
39
+ <class>Iwebics_LayeredCategory_Helper</class>
40
+ </layeredcategory>
41
+ </helpers>
42
+ <resources>
43
+ <layeredcategory_setup>
44
+ <setup>
45
+ <module>Iwebics_LayeredCategory</module>
46
+ <class>Mage_Catalog_Model_Resource_Setup</class>
47
+ </setup>
48
+ </layeredcategory_setup>
49
+ </resources>
50
+ </global>
51
+ <default>
52
+ <catalog>
53
+ <layered_navigation><default_layered_attribute>price</default_layered_attribute></layered_navigation>
54
+ </catalog>
55
+ </default>
56
+ </config>
app/code/local/Iwebics/LayeredCategory/etc/system.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * @category Iwebics
7
+ * @package Iwebics_LayeredCategory
8
+ */
9
+ -->
10
+ <config>
11
+ <sections>
12
+ <catalog>
13
+ <groups>
14
+ <layered_navigation>
15
+ <fields>
16
+ <default_layered_attribute translate="label comment">
17
+ <label>Default Layered Attributes</label>
18
+ <frontend_type>multiselect</frontend_type>
19
+ <sort_order>25</sort_order>
20
+ <source_model>layeredcategory/system_config_source_filterby</source_model>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ <can_be_empty>0</can_be_empty>
25
+ </default_layered_attribute>
26
+ </fields>
27
+ </layered_navigation>
28
+ </groups>
29
+ </catalog>
30
+ </sections>
31
+ </config>
app/code/local/Iwebics/LayeredCategory/sql/layeredcategory_setup/mysql4-install-0.0.1.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Iwebics
6
+ * @package Iwebics_LayeredCategory
7
+ * @author CAB.
8
+ */
9
+ $installer = $this;
10
+ $installer->startSetup();
11
+ $entityTypeId = $installer->getEntityTypeId('catalog_category');
12
+ $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
13
+
14
+ $installer->addAttribute($entityTypeId, 'available_filter_by', array(
15
+ 'input' => 'multiselect',
16
+ 'type' => 'text',
17
+ 'label' => 'Available Product Listing Filter By',
18
+ 'source' => 'layeredcategory/catalog_category_attribute_source_filterby',
19
+ 'backend' => 'layeredcategory/catalog_category_attribute_backend_filterby',
20
+ 'required' => 1,
21
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
22
+ 'visible' => 1,
23
+ 'input_renderer'=> 'layeredcategory/catalog_category_helper_filterby_available',
24
+ ));
25
+ $installer->addAttributeToGroup(
26
+ $entityTypeId,
27
+ $attributeSetId,
28
+ 'Display Settings',
29
+ 'available_filter_by',
30
+ 35
31
+ );
32
+ $installer->endSetup();
app/etc/modules/Iwebics_LayeredCategory.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * @category Iwebics
7
+ * @package Iwebics_LayeredCategory
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Iwebics_LayeredCategory>
13
+ <active>true</active>
14
+ <codePool>local</codePool>
15
+ <depends>
16
+ <Mage_Catalog />
17
+ </depends>
18
+ </Iwebics_LayeredCategory>
19
+ </modules>
20
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Iwebics_LayeredCategory</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Out Layered Category extension gives you the maximum flexibility to set category wise layered navigation. Layered Category enables you to set different layered navigation for different category.You can also set default layered navigation from configuration settings.</summary>
10
+ <description>Out Layered Category extension gives you the maximum flexibility to set category wise layered navigation. Layered Category enables you to set different layered navigation for different category.You can also set default layered navigation from configuration settings.</description>
11
+ <notes>Out Layered Category extension gives you the maximum flexibility to set category wise layered navigation. Layered Category enables you to set different layered navigation for different category.You can also set default layered navigation from configuration settings.</notes>
12
+ <authors><author><name>Iwebics</name><user>iwebics</user><email>iwebicssolutions@gmail.com</email></author></authors>
13
+ <date>2013-02-14</date>
14
+ <time>12:58:29</time>
15
+ <contents><target name="magelocal"><dir name="Iwebics"><dir name="LayeredCategory"><dir name="Block"><dir name="Catalog"><dir name="Category"><dir name="Helper"><dir name="Filterby"><file name="Available.php" hash="9b68ba33510e540d6376207bceab41db"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="d9c63ec94a8d85d4422aebb963b6f230"/></dir><dir name="Model"><dir name="Catalog"><dir name="Category"><dir name="Attribute"><dir name="Backend"><file name="Filterby.php" hash="8bd7d677a2b90bc919d23c6288edadef"/></dir><dir name="Source"><file name="Filterby.php" hash="eea704ae6a6cf07af8d4ca537a94f95d"/></dir></dir></dir><file name="Layer.php" hash="3ede8f429a386681e20be68abf983545"/></dir><dir name="Catalogsearch"><file name="Layer.php" hash="38b823c08f5543e3f276500204b289cb"/></dir><dir name="System"><dir name="Config"><dir name="Source"><file name="Filterby.php" hash="d5972b5e1cba23be63584e05dabacd66"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="097bc4585ceedec02e44012fb69a2f2c"/><file name="system.xml" hash="474a215a816ae11f2b96f0006bdddb9c"/></dir><dir name="sql"><dir name="layeredcategory_setup"><file name="mysql4-install-0.0.1.php" hash="7a2c9dffecbd7ec315645dbd93179e77"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Iwebics_LayeredCategory.xml" hash="cef3f40f3d26cd7f867b2c15cb304cb3"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.7.0.2</max></package></required></dependencies>
18
+ </package>