Search_Manipulation - Version 1.0.0

Version Notes

This extension supports sort the products on the basis of product rating in the product list page. We can set all the products to default rating. We can add our own rating on manage product page on Magento admin panel.

The search in the product list page depends on the product rating assigned to the product. The priority of the result is New, Best, Better, Good and Default.

Download this release

Release Info

Developer BrainSINS
Extension Search_Manipulation
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Exinent/Productattrupdate/Block/Adminhtml/System/Config/Form/Productattrupdate.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Exinent_Productattrupdate_Block_Adminhtml_System_Config_Form_Productattrupdate extends Mage_Adminhtml_Block_System_Config_Form_Field {
4
+
5
+ protected function _construct() {
6
+ parent::_construct();
7
+ $this->setTemplate('productattrupdate/system/config/button.phtml');
8
+ }
9
+
10
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
11
+ return $this->_toHtml();
12
+ }
13
+
14
+ public function getAjaxCheckUrl() {
15
+ return Mage::helper('adminhtml')->getUrl('productattrupdate/adminhtml_update/update');
16
+ }
17
+
18
+ public function getButtonHtml() {
19
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
20
+ ->setData(array(
21
+ 'id' => 'productattrupdate_button',
22
+ 'label' => $this->helper('adminhtml')->__('Sort Product Index'),
23
+ 'onclick' => 'javascript:check(); return false;'
24
+ ));
25
+
26
+ return $button->toHtml();
27
+ }
28
+
29
+ }
app/code/community/Exinent/Productattrupdate/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class Exinent_Productattrupdate_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ }
app/code/community/Exinent/Productattrupdate/Model/Observer.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Exinent_Productattrupdate_Model_Observer {
4
+
5
+ public function createupdatesortattributes(Varien_Event_Observer $observer) {
6
+ $productObject = $observer->getEvent()->getProduct();
7
+ $ratingInstance = $this->getCategoryAttrInstance($productObject->getRatingCategory());
8
+ $ratingCategoryLabel = $ratingInstance->getAttributeText('rating_category');
9
+ $productRatingInstance = $this->getRatingAttrInstance($productObject->getProductRating());
10
+ $productRatingLabel = $productRatingInstance->getAttributeText('product_rating');
11
+ if ($productObject->getRatingPriority() != null && $ratingCategoryLabel != 'Default') {
12
+ $categoryNumber = $this->getCategoryNumber($ratingCategoryLabel);
13
+ $ratingNumber = $categoryNumber + $productObject->getRatingPriority();
14
+ $attributeLabel = $this->getAttributeLableId($ratingNumber);
15
+
16
+ if ($attributeLabel == null) {
17
+
18
+ $this->createAttributeLableOption($ratingNumber);
19
+ $attributeLabel = $this->getAttributeLableId($ratingNumber);
20
+ $productObject->setProductRating($attributeLabel);
21
+ } else {
22
+
23
+ $productObject->setProductRating($attributeLabel);
24
+ }
25
+ } elseif ($productRatingLabel == null && $productObject->getRatingPriority() == null && $ratingCategoryLabel == 'Default') {
26
+ $defaultAttributeLable = $this->getAttributeLableId('60000');
27
+ $productObject->setProductRating($defaultAttributeLable);
28
+ } else {
29
+ $defaultAttributeLable = $this->getAttributeLableId('60000');
30
+ $productObject->setProductRating($defaultAttributeLable);
31
+ }
32
+ }
33
+
34
+ public function getAttributeLableId($ratingNumber) {
35
+ $attr = Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product', 'product_rating');
36
+ $color_label = $attr->getSource()->getOptionId($ratingNumber);
37
+ return $color_label;
38
+ }
39
+
40
+ public function createAttributeLableOption($ratingNumber) {
41
+ $attr_model = Mage::getModel('catalog/resource_eav_attribute');
42
+ $attr = $attr_model->loadByCode('catalog_product', 'product_rating');
43
+ $attr_id = $attr->getAttributeId();
44
+ $option = array();
45
+ $option['attribute_id'] = $attr_id;
46
+ $option['value'][0][0] = $ratingNumber;
47
+ $option['value'][0][1] = $ratingNumber;
48
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
49
+ $setup->addAttributeOption($option);
50
+ return;
51
+ }
52
+
53
+ public function getCategoryAttrInstance($attrid) {
54
+ $storeId = Mage::app()->getStore()->getStoreId();
55
+ $product = Mage::getModel('catalog/product')->setStoreId($storeId)->setRatingCategory($attrid);
56
+ return $product;
57
+ }
58
+
59
+ public function getRatingAttrInstance($attrid) {
60
+ $storeId = Mage::app()->getStore()->getStoreId();
61
+ $product = Mage::getModel('catalog/product')->setStoreId($storeId)->setProductRating($attrid);
62
+ return $product;
63
+ }
64
+
65
+ public function getCategoryNumber($ratingCategoryLabel) {
66
+ switch ($ratingCategoryLabel) {
67
+ case 'New':
68
+ return 10000;
69
+ case 'Best':
70
+ return 20000;
71
+ case 'Better':
72
+ return 30000;
73
+ case 'Good':
74
+ return 40000;
75
+ }
76
+ }
77
+
78
+ }
app/code/community/Exinent/Productattrupdate/controllers/Adminhtml/UpdateController.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Exinent_Productattrupdate_Adminhtml_UpdateController extends Mage_Adminhtml_Controller_Action {
4
+
5
+ public function updateAction() {
6
+ $collection = Mage::getModel('catalog/product')->getCollection();
7
+ foreach ($collection as $products) {
8
+ $product = Mage::getModel('catalog/product')->load($products->getId());
9
+ $attr = Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product', 'rating_category');
10
+ $color_label = $attr->getSource()->getOptionId("Default");
11
+ if ($product->getProductRating() == null) {
12
+ $product->setRatingCategory($color_label);
13
+ $product->setProductRating('60000');
14
+ $product->save();
15
+ }
16
+ }
17
+ }
18
+
19
+ }
app/code/community/Exinent/Productattrupdate/etc/adminhtml.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <acl>
3
+ <resources>
4
+ <admin>
5
+ <children>
6
+ <system>
7
+ <children>
8
+ <config>
9
+ <children>
10
+ <exinent translate="title" module="productattrupdate">
11
+ <title>Advance Search</title>
12
+ </exinent>
13
+ </children>
14
+ </config>
15
+ </children>
16
+ </system>
17
+ </children>
18
+ </admin>
19
+ </resources>
20
+ </acl>
21
+ </config>
app/code/community/Exinent/Productattrupdate/etc/config.xml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Exinent_Productattrupdate>
5
+ <version>1.1.1</version>
6
+ </Exinent_Productattrupdate>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <productattrupdate>
11
+ <class>Exinent_Productattrupdate_Helper</class>
12
+ </productattrupdate>
13
+ </helpers>
14
+ <blocks>
15
+ <productattrupdate>
16
+ <class>Exinent_Productattrupdate_Block</class>
17
+ </productattrupdate>
18
+ </blocks>
19
+ <models>
20
+ <productattrupdate>
21
+ <class>Exinent_Productattrupdate_Model</class>
22
+ <resourceModel>productattrupdate_mysql4</resourceModel>
23
+ </productattrupdate>
24
+ </models>
25
+ <events>
26
+ <catalog_product_save_before>
27
+ <observers>
28
+ <catalog_product_save_before_handler>
29
+ <type>model</type>
30
+ <class>productattrupdate/observer</class>
31
+ <method>createupdatesortattributes</method>
32
+ <args></args>
33
+ </catalog_product_save_before_handler>
34
+ </observers>
35
+ </catalog_product_save_before>
36
+ </events>
37
+ <resources>
38
+ <exinent_search_setup>
39
+ <setup>
40
+ <module>Exinent_Productattrupdate</module>
41
+ <class>Mage_Catalog_Model_Resource_Setup</class>
42
+ </setup>
43
+ <connection>
44
+ <use>core_setup</use>
45
+ </connection>
46
+ </exinent_search_setup>
47
+ <exinent_write>
48
+ <connection>
49
+ <use>core_write</use>
50
+ </connection>
51
+ </exinent_write>
52
+ <exinent_read>
53
+ <connection>
54
+ <use>core_read</use>
55
+ </connection>
56
+ </exinent_read>
57
+ </resources>
58
+ </global>
59
+ <admin>
60
+ <routers>
61
+ <productattrupdate>
62
+ <use>admin</use>
63
+ <args>
64
+ <module>Exinent_Productattrupdate</module>
65
+ <frontName>productattrupdate</frontName>
66
+ </args>
67
+ </productattrupdate>
68
+ </routers>
69
+ </admin>
70
+ </config>
app/code/community/Exinent/Productattrupdate/etc/system.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <sections>
4
+ <exinent translate="label" module="productattrupdate">
5
+ <label>Advance Search</label>
6
+ <tab>catalog</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>1000</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <frontend translate="label">
14
+ <label>Advance Search Index</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>100</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <mbcustomopt1 translate="label comment">
22
+ <label>Sort Product Rating Index</label>
23
+ <frontend_type>button</frontend_type>
24
+ <frontend_model>productattrupdate/adminhtml_system_config_form_productattrupdate</frontend_model>
25
+ <sort_order>10</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>0</show_in_store>
29
+ <comment>Set Default Product Rating.</comment>
30
+ </mbcustomopt1>
31
+ </fields>
32
+ </frontend>
33
+ </groups>
34
+ </exinent>
35
+ </sections>
36
+ </config>
app/code/community/Exinent/Productattrupdate/sql/exinent_search_setup/install-1.0.0.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
5
+ $installer->startSetup();
6
+
7
+ $setup->addAttribute('catalog_product', 'rating_category', array(
8
+ 'group' => 'General',
9
+ 'label' => 'Rating Category',
10
+ 'type' => 'varchar',
11
+ 'input' => 'select',
12
+ 'backend' => '',
13
+ 'frontend' => '',
14
+ 'source' => 'eav/entity_attribute_source_table',
15
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
16
+ 'visible' => true,
17
+ 'required' => true,
18
+ 'user_defined' => true,
19
+ 'searchable' => false,
20
+ 'filterable' => false,
21
+ 'comparable' => false,
22
+ 'visible_on_front' => false,
23
+ 'visible_in_advanced_search' => false,
24
+ 'is_html_allowed_on_front' => 1,
25
+ 'unique' => false,
26
+ 'apply_to' => 'simple,grouped,configurable,virtual,bundle,downloadable',
27
+ 'option' => array(
28
+ 'value' => array(
29
+ 0 => array(0 => 'Default', 1 => '60000'),
30
+
31
+ )
32
+
33
+ ),
34
+ ));
35
+
36
+
37
+ $attributeCode = 'rating_category';
38
+
39
+ $attributeModel = Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product', $attributeCode);
40
+ $attributeId = $attributeModel->getAttributeId();
41
+
42
+ $option['attribute_id'] = $attributeId;
43
+ $option['value']['New'][0] = 'New';
44
+ $option['value']['New'][1] = '10000';
45
+ $installer->addAttributeOption($option);
46
+
47
+ $option1['attribute_id'] = $attributeId;
48
+ $option1['value']['Best'][0] = 'Best';
49
+ $option1['value']['Best'][1] = '20000';
50
+ $installer->addAttributeOption($option1);
51
+
52
+ $option2['attribute_id'] = $attributeId;
53
+ $option2['value']['Better'][0] = 'Better';
54
+ $option2['value']['Better'][1] = '30000';
55
+ $installer->addAttributeOption($option2);
56
+
57
+ $option3['attribute_id'] = $attributeId;
58
+ $option3['value']['Good'][0] = 'Good';
59
+ $option3['value']['Good'][1] = '40000';
60
+ $installer->addAttributeOption($option3);
61
+
62
+ $installer->endSetup();
app/code/community/Exinent/Productattrupdate/sql/exinent_search_setup/upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
5
+ $installer->startSetup();
6
+
7
+ $setup->addAttribute('catalog_product', 'product_rating', array(
8
+ 'group' => 'General',
9
+ 'label' => 'Product Rating',
10
+ 'type' => 'int',
11
+ 'input' => 'select',
12
+ 'backend' => '',
13
+ 'frontend' => '',
14
+ //'source' => 'eav/entity_attribute_source_table',
15
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
16
+ 'visible' => true,
17
+ 'required' => false,
18
+ 'user_defined' => true,
19
+ 'searchable' => false,
20
+ 'filterable' => false,
21
+ 'comparable' => false,
22
+ 'visible_on_front' => false,
23
+ 'visible_in_advanced_search' => false,
24
+ 'is_html_allowed_on_front' => '0',
25
+ 'used_for_sort_by' => '1',
26
+ 'unique' => false,
27
+ 'apply_to' => 'simple,grouped,configurable,virtual,bundle,downloadable',
28
+ 'option' => array(
29
+ 'value' => array(
30
+ 0 => array(0 => '60000', 1 => '60000'),
31
+
32
+ )
33
+
34
+ ),
35
+
36
+ ));
37
+ $installer->endSetup();
38
+
39
+
app/code/community/Exinent/Productattrupdate/sql/exinent_search_setup/upgrade-1.1.0-1.1.1.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
5
+ $installer->startSetup();
6
+
7
+ $setup->addAttribute('catalog_product', 'rating_priority', array(
8
+ 'group' => 'General',
9
+ 'label' => 'Rating priority',
10
+ 'type' => 'text',
11
+ 'input' => 'text',
12
+ 'backend' => '',
13
+ 'frontend' => '',
14
+ //'source' => 'eav/entity_attribute_source_table',
15
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
16
+ 'visible' => true,
17
+ 'required' => true,
18
+ 'user_defined' => true,
19
+ 'searchable' => false,
20
+ 'filterable' => false,
21
+ 'comparable' => false,
22
+ 'visible_on_front' => false,
23
+ 'visible_in_advanced_search' => false,
24
+ 'is_html_allowed_on_front' => '0',
25
+ 'unique' => false,
26
+ 'used_for_sort_by' => '1',
27
+ 'apply_to' => 'simple,grouped,configurable,virtual,bundle,downloadable',
28
+
29
+
30
+ ));
31
+ $installer->endSetup();
app/design/adminhtml/default/default/template/productattrupdate/system/config/button.phtml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ //<![CDATA[
3
+ function check() {
4
+ new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
5
+ method: 'get',
6
+ onSuccess: function (transport) {
7
+
8
+ if (transport.responseText) {
9
+ alert('Checked')
10
+ }
11
+ }
12
+ });
13
+ }
14
+ //]]>
15
+ </script>
16
+
17
+ <?php echo $this->getButtonHtml() ?>
app/etc/modules/Exinent_Productattrupdate.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Exinent_Productattrupdate>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Exinent_Productattrupdate>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Search_Manipulation</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension allows you to sort the products on the basis of product rating in the product list page</summary>
10
+ <description>The Products in the product list page are sorted on the basis of product rating assigned to the product. We can assign product rating for each product from the Magento admin panel. Or we can add default product rating for all the products through Magento admin panel. Using this extension customer can track the best products in their search criteria. </description>
11
+ <notes>This extension supports sort the products on the basis of product rating in the product list page. We can set all the products to default rating. We can add our own rating on manage product page on Magento admin panel.&#xD;
12
+ &#xD;
13
+ The search in the product list page depends on the product rating assigned to the product. The priority of the result is New, Best, Better, Good and Default.</notes>
14
+ <authors><author><name>Exinent LLC</name><user>Developer</user><email>developer@exinent.com</email></author></authors>
15
+ <date>2015-02-19</date>
16
+ <time>10:51:59</time>
17
+ <contents><target name="magecommunity"><dir name="Exinent"><dir name="Productattrupdate"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><file name="Productattrupdate.php" hash="0adfb25cecfcc56da4ae4f300faff4fa"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="0ebef6f305203d2a11bedbfccb8b0516"/></dir><dir name="Model"><file name="Observer.php" hash="ba7dd68505426a285632aaf2ffbc6168"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="UpdateController.php" hash="0c22d9570511c13b0b49b901a1b2e3d7"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="66d3238c8e285afa3743c4d64e2629b8"/><file name="config.xml" hash="75028a05e4b5f84c3ad0b1bdf3f83603"/><file name="system.xml" hash="facf43a374d3c78a27eabfb8944c870c"/></dir><dir name="sql"><dir name="exinent_search_setup"><file name="install-1.0.0.php" hash="1a4def943164dcbb44fe1b65c30f994d"/><file name="upgrade-1.0.0-1.0.1.php" hash="a883d7b50aa1100863336b4fa74cc440"/><file name="upgrade-1.1.0-1.1.1.php" hash="74418a4185b1fee572f72661053ca45c"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="productattrupdate"><dir name="system"><dir name="config"><file name="button.phtml" hash="bfecb8625ebac406f5ab83fdc29ae310"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Exinent_Productattrupdate.xml" hash="ea8d9d5a373785c77914c51ff4f65412"/></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
20
+ </package>