left_layered_rating_filter - Version 0.1.0

Version Notes

Base upload of stable extension

Download this release

Release Info

Developer udogan
Extension left_layered_rating_filter
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Product/CatalogSearch/Block/Layer.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_CatalogSearch_Block_Layer extends Product_Filter_Block_Layer_View
3
+ {
4
+ /**
5
+ * Internal constructor
6
+ */
7
+ protected function _construct()
8
+ {
9
+ parent::_construct();
10
+ Mage::register('current_layer', $this->getLayer(), true);
11
+ }
12
+
13
+ /**
14
+ * Get attribute filter block name
15
+ *
16
+ * @deprecated after 1.4.1.0
17
+ *
18
+ * @return string
19
+ */
20
+ protected function _getAttributeFilterBlockName()
21
+ {
22
+ return 'catalogsearch/layer_filter_attribute';
23
+ }
24
+
25
+ /**
26
+ * Initialize blocks names
27
+ */
28
+ protected function _initBlocks()
29
+ {
30
+ parent::_initBlocks();
31
+
32
+ $this->_attributeFilterBlockName = 'catalogsearch/layer_filter_attribute';
33
+ }
34
+
35
+ /**
36
+ * Get layer object
37
+ *
38
+ * @return Mage_Catalog_Model_Layer
39
+ */
40
+ public function getLayer()
41
+ {
42
+ return Mage::getSingleton('catalogsearch/layer');
43
+ }
44
+
45
+ /**
46
+ * Check availability display layer block
47
+ *
48
+ * @return bool
49
+ */
50
+ public function canShowBlock()
51
+ {
52
+ $_isLNAllowedByEngine = Mage::helper('catalogsearch')->getEngine()->isLeyeredNavigationAllowed();
53
+ if (!$_isLNAllowedByEngine) {
54
+ return false;
55
+ }
56
+ $availableResCount = (int) Mage::app()->getStore()
57
+ ->getConfig(Mage_CatalogSearch_Model_Layer::XML_PATH_DISPLAY_LAYER_COUNT);
58
+
59
+ if (!$availableResCount
60
+ || ($availableResCount>=$this->getLayer()->getProductCollection()->getSize())) {
61
+ return parent::canShowBlock();
62
+ }
63
+ return false;
64
+ }
65
+ }
app/code/local/Product/CatalogSearch/etc/config.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <global>
4
+ <blocks>
5
+ <catalogsearch>
6
+ <rewrite>
7
+ <layer>Product_CatalogSearch_Block_Layer</layer>
8
+ </rewrite>
9
+ </catalogsearch>
10
+ </blocks>
11
+ </global>
12
+ </config>
app/code/local/Product/Filter/Block/Layer/Filter/Review.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_Filter_Block_Layer_Filter_Review extends Mage_Catalog_Block_Layer_Filter_Abstract
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->_filterModelName = 'filter/layer_filter_review';
8
+ $this->setTemplate("ratingfilter/layer/filter.phtml");
9
+ }
10
+
11
+ protected function _prepareFilter()
12
+ {
13
+ $this->_filter->setAttributeModel($this->getAttributeModel());
14
+ return $this;
15
+ }
16
+ }
17
+
app/code/local/Product/Filter/Block/Layer/View.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_Filter_Block_Layer_View extends Mage_Catalog_Block_Layer_View
3
+ {
4
+ protected $_reviewFilterBlockName;
5
+
6
+ protected function _initBlocks()
7
+ {
8
+ $this->_stateBlockName = 'catalog/layer_state';
9
+ $this->_categoryBlockName = 'catalog/layer_filter_category';
10
+ $this->_attributeFilterBlockName = 'catalog/layer_filter_attribute';
11
+ $this->_priceFilterBlockName = 'catalog/layer_filter_price';
12
+ $this->_decimalFilterBlockName = 'catalog/layer_filter_decimal';
13
+ $this->_reviewFilterBlockName = 'filter/layer_filter_review';
14
+ }
15
+
16
+ protected function _prepareLayout()
17
+ {
18
+ $stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
19
+ ->setLayer($this->getLayer());
20
+
21
+ $categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
22
+ ->setLayer($this->getLayer())
23
+ ->init();
24
+
25
+ $this->setChild('layer_state', $stateBlock);
26
+ $this->setChild('category_filter', $categoryBlock);
27
+
28
+ $filterableAttributes = $this->_getFilterableAttributes();
29
+ foreach ($filterableAttributes as $attribute) {
30
+ if ($attribute->getAttributeCode() == 'price') {
31
+ $filterBlockName = $this->_priceFilterBlockName;
32
+ } elseif ($attribute->getAttributeCode() == "review") {
33
+ $filterBlockName = $this->_reviewFilterBlockName;
34
+ } elseif ($attribute->getBackendType() == 'decimal') {
35
+ $filterBlockName = $this->_decimalFilterBlockName;
36
+ } else {
37
+ $filterBlockName = $this->_attributeFilterBlockName;
38
+ }
39
+
40
+ $this->setChild($attribute->getAttributeCode() . '_filter',
41
+ $this->getLayout()->createBlock($filterBlockName)
42
+ ->setLayer($this->getLayer())
43
+ ->setAttributeModel($attribute)
44
+ ->init());
45
+ }
46
+
47
+ $this->getLayer()->apply();
48
+
49
+ return $this;
50
+ }
51
+
52
+ protected function _getFilterableAttributes()
53
+ {
54
+ $attributes = $this->getData('_filterable_attributes');
55
+ if (is_null($attributes)) {
56
+ $attributes = $this->getLayer()->getFilterableAttributes();
57
+ $review = Mage::getSingleton("eav/config")->getAttribute("10", "review");
58
+ if ($attributes && $review) {
59
+ $attributes->addItem($review);
60
+ }
61
+ $this->setData('_filterable_attributes', $attributes);
62
+ }
63
+
64
+ return $attributes;
65
+ }
66
+ }
app/code/local/Product/Filter/Model/Layer/Filter/Review.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_Filter_Model_Layer_Filter_Review extends Mage_Catalog_Model_Layer_Filter_Abstract
3
+ {
4
+ protected $_resource;
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->_requestVar = 'review';
10
+ }
11
+
12
+ protected function _getResource()
13
+ {
14
+ if (is_null($this->_resource)) {
15
+ $this->_resource = Mage::getResourceModel('filter/layer_filter_review');
16
+ }
17
+ return $this->_resource;
18
+ }
19
+
20
+ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
21
+ {
22
+ $filter = $request->getParam($this->_requestVar);
23
+ if (is_array($filter)) {
24
+ return $this;
25
+ }
26
+ $text = $filter . " " . Mage::helper('catalog')->__("stars");
27
+ if ($filter) {
28
+ $this->_getResource()->applyFilterToCollection($this, $filter);
29
+ $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
30
+ $this->_items = array();
31
+ }
32
+ return $this;
33
+ }
34
+
35
+ protected function _getItemsData()
36
+ {
37
+ $attribute = $this->getAttributeModel();
38
+ $this->_requestVar = $attribute->getAttributeCode();
39
+
40
+ $key = $this->getLayer()->getStateKey().'_'.$this->_requestVar;
41
+ $data = $this->getLayer()->getAggregator()->getCacheData($key);
42
+
43
+ if ($data === null) {
44
+ $reviewSummaries = $this->_getResource()->getCount($this);
45
+ $data = array();
46
+ for ($i = 1; $i < 6; $i++) {
47
+ $filteredSummaries = array_filter($reviewSummaries, function($el) use ($i) {
48
+ return ((($i - 1) * 20) < $el["rating_summary"]) && ($el["rating_summary"] <= ($i * 20));
49
+ });
50
+
51
+ if ($filteredSummaries) {
52
+ $data[] = array(
53
+ 'label' => $i,
54
+ 'value' => $i,
55
+ 'count' => sizeof($filteredSummaries)
56
+ );
57
+ }
58
+ }
59
+
60
+ $tags = array(
61
+ Mage_Eav_Model_Entity_Attribute::CACHE_TAG.':'.$attribute->getId()
62
+ );
63
+
64
+ $tags = $this->getLayer()->getStateTags($tags);
65
+ $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags);
66
+ }
67
+ return $data;
68
+ }
69
+ }
app/code/local/Product/Filter/Model/Resource/Eav/Mysql4/Layer/Filter/Review.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Product_Filter_Model_Resource_Eav_Mysql4_Layer_Filter_Review extends Module_Catalog_Model_Resource_Layer_Filter_Review
3
+ {
4
+ }
app/code/local/Product/Filter/Model/Resource/Layer/Filter/Review.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_Filter_Model_Resource_Layer_Filter_Review extends Mage_Core_Model_Resource_Db_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('filter/review_summary', 'primary_id');
7
+ }
8
+
9
+ public function applyFilterToCollection($filter, $value)
10
+ {
11
+ $collection = $filter->getLayer()->getProductCollection();
12
+ $attribute = $filter->getAttributeModel();
13
+ $connection = $this->_getReadAdapter();
14
+ $tableAlias = $attribute->getAttributeCode() . '_idx';
15
+ $conditions = array(
16
+ "{$tableAlias}.entity_pk_value = e.entity_id",
17
+ $connection->quoteInto("{$tableAlias}.rating_summary > ?", (($value - 1) * 20)),
18
+ $connection->quoteInto("{$tableAlias}.rating_summary <= ?", ($value * 20)),
19
+ $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId())
20
+ );
21
+
22
+ $collection->getSelect()->join(
23
+ array($tableAlias => $this->getMainTable()),
24
+ implode(' AND ', $conditions),
25
+ array()
26
+ );
27
+
28
+ return $this;
29
+ }
30
+
31
+ public function getCount($filter)
32
+ {
33
+ $select = clone $filter->getLayer()->getProductCollection()->getSelect();
34
+ $select->reset(Zend_Db_Select::COLUMNS);
35
+ $select->reset(Zend_Db_Select::ORDER);
36
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
37
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
38
+
39
+ $connection = $this->_getReadAdapter();
40
+ $attribute = $filter->getAttributeModel();
41
+ $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
42
+ $conditions = array(
43
+ "{$tableAlias}.entity_pk_value = e.entity_id",
44
+ $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()),
45
+ );
46
+
47
+ $select
48
+ ->join(
49
+ array($tableAlias => $this->getMainTable()),
50
+ join(' AND ', $conditions),
51
+ array('rating_summary')
52
+ );
53
+
54
+ return $connection->fetchAll($select);
55
+ }
56
+ }
57
+
app/code/local/Product/Filter/etc/config.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Product_Filter>
5
+ <version>0.1.0</version>
6
+ </Product_Filter>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <filter>
11
+ <class>Product_Filter_Model</class>
12
+ <resourceModel>product_filter_resource</resourceModel>
13
+ </filter>
14
+ <product_filter_resource>
15
+ <class>Product_Filter_Model_Resource</class>
16
+ <entities>
17
+ <review_summary>
18
+ <table>review_entity_summary</table>
19
+ </review_summary>
20
+ </entities>
21
+ </product_filter_resource>
22
+ </models>
23
+ <blocks>
24
+ <filter>
25
+ <class>Product_Filter_Block</class>
26
+ </filter>
27
+ <catalog>
28
+ <rewrite>
29
+ <layer_view>Product_Filter_Block_Layer_View</layer_view>
30
+ </rewrite>
31
+ </catalog>
32
+ </blocks>
33
+ <resources>
34
+ <filter_setup>
35
+ <setup>
36
+ <module>Product_Filter</module>
37
+ </setup>
38
+ </filter_setup>
39
+ </resources>
40
+ </global>
41
+ </config>
app/code/local/Product/Filter/sql/filter_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $installer->run("INSERT INTO {$this->getTable('eav_attribute')} (entity_type_id, attribute_code, frontend_label) VALUES ('10', 'review', 'Review')");
5
+ $installer->endSetup();
app/design/frontend/base/default/template/ratingfilter/layer/filter.phtml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Template for filter items block
4
+ *
5
+ * @see Mage_Catalog_Block_Layer_Filter
6
+ */
7
+ ?>
8
+
9
+ <ol>
10
+ <?php foreach ($this->getItems() as $_item): ?>
11
+ <li>
12
+ <?php if ($_item->getCount() > 0): ?>
13
+ <input id="rating-filter" type="radio" name="rating-filter" style="float:left; margin-top:2px; margin-right: 5px;" onClick="setLocation(this.value)" value="<?php echo $this->urlEscape($_item->getUrl()) ?>">
14
+ <div class="ratings">
15
+ <div class="rating-box">
16
+ <div class="rating" style="width: <?php echo ($_item->getLabel() * 20) . '%' ?>"></div>
17
+ </div>
18
+ </div>
19
+ </input>
20
+ <?php endif; ?>
21
+ </li>
22
+ <?php endforeach ?>
23
+ </ol>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>left_layered_rating_filter</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Includes filter according to reviews with showing rating stars</summary>
10
+ <description>This extension makes available filtering products according to review points. In the left filter, rating stars are shown. It looks rating point while creating filter. For example in the layered navigation 3 stars image is filtering products which have rating point between 60 and 79.</description>
11
+ <notes>Base upload of stable extension</notes>
12
+ <authors><author><name>udogan</name><user>udogan</user><email>ugurdogann1905@gmail.com</email></author></authors>
13
+ <date>2012-10-14</date>
14
+ <time>08:18:59</time>
15
+ <contents><target name="magelocal"><dir name="Product"><dir name="CatalogSearch"><dir name="Block"><file name="Layer.php" hash="69d731d114921d18ec49114d98730d88"/></dir><dir name="etc"><file name="config.xml" hash="452762e46c27d76b5ec2d5ab967d60f5"/></dir></dir><dir name="Filter"><dir name="Block"><dir name="Layer"><dir name="Filter"><file name="Review.php" hash="34e53ebc5446182c0336afefbb29f450"/></dir><file name="View.php" hash="fc2ab71762c3e6dab6d5268c24d00313"/></dir></dir><dir name="Model"><dir name="Layer"><dir name="Filter"><file name="Review.php" hash="159a33deb1c0473efa54236c1429e467"/></dir></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><dir name="Layer"><dir name="Filter"><file name="Review.php" hash="b26f673b3aa37736bec8f4cae747ad87"/></dir></dir></dir></dir><dir name="Layer"><dir name="Filter"><file name="Review.php" hash="ccd79f5a8cacb0d0a51bacfc31bbe8a9"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="c2a2f05215c4e1762e886388da46d6d7"/></dir><dir name="sql"><dir name="filter_setup"><file name="mysql4-install-0.1.0.php" hash="f909ae575f390e3c4c4827521cc64d65"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="ratingfilter"><dir name="layer"><file name="filter.phtml" hash="c266878d3d22cc38a9909eb2b5842758"/></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7</max></package></required></dependencies>
18
+ </package>