Its_SearchLog - Version 1.4.0

Version Notes

N / A

Download this release

Release Info

Developer Dominic Wetherall
Extension Its_SearchLog
Version 1.4.0
Comparing to
See all releases


Version 1.4.0

app/code/community/Its/SearchLog/Block/Adminhtml/Usersearches.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Its_SearchLog_Block_Adminhtml_Usersearches extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ //protected $_addButtonLabel = 'Add New Example';
6
+ public function __construct()
7
+ {
8
+ $this->_headerText = Mage::helper('searchlog')->__('List of Search Queries');
9
+ $this->_blockGroup = 'searchlog';
10
+ $this->_controller = 'adminhtml_usersearches';
11
+ parent::__construct();
12
+
13
+ }
14
+ protected function _prepareLayout()
15
+ {
16
+ $this->_removeButton ('add');
17
+ return parent::_prepareLayout();
18
+ }
19
+
20
+ }
app/code/community/Its/SearchLog/Block/Adminhtml/Usersearches/Grid.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Its_SearchLog_Block_Adminhtml_Usersearches_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('usersearches_Grid');
9
+ $this->setDefaultSort('entity_id');
10
+ $this->setDefaultDir('DESC');
11
+ $this->setSaveParametersInSession(true);
12
+ $this->setUseAjax(true);
13
+
14
+ }
15
+
16
+ protected function _prepareCollection()
17
+ {
18
+ $collection = Mage::getModel('searchlog/content')->getCollection();
19
+ $this->setCollection($collection);
20
+ return parent::_prepareCollection();
21
+ }
22
+
23
+
24
+ protected function _prepareColumns()
25
+ {
26
+ $this->addColumn('entity_id', array(
27
+ 'header' => Mage::helper('searchlog')->__('ID'),
28
+ 'align' =>'left !important',
29
+ 'width' => '10px',
30
+ 'index' => 'query_id',
31
+ 'type' => 'number',
32
+ ));
33
+
34
+ $this->addColumn('user_id', array(
35
+ 'header' => Mage::helper('searchlog')->__('User ID'),
36
+ 'align' =>'left',
37
+ 'index' => 'user_id',
38
+ 'width' => '50px',
39
+ 'type' => 'number',
40
+ ));
41
+
42
+
43
+ $this->addColumn('search_query', array(
44
+ 'header' => Mage::helper('searchlog')->__('Search Query'),
45
+ 'width' => '150px',
46
+ 'index' => 'query_text',
47
+ 'type' => 'text',
48
+ ));
49
+ $this->addColumn('items_found_per_search', array(
50
+ 'header' => Mage::helper('searchlog')->__('Items found per search'),
51
+ 'width' => '150px',
52
+ 'index' => 'item_count_per_result',
53
+ 'type' => 'number',
54
+ ));
55
+ $this->addColumn('searched_at', array(
56
+ 'header' => Mage::helper('searchlog')->__('Searched at'),
57
+ 'width' => '150px',
58
+ 'index' => 'date_time',
59
+ 'type' => 'datetime',
60
+ ));
61
+
62
+ return parent::_prepareColumns();
63
+ }
64
+
65
+ public function getGridUrl()
66
+ {
67
+ return $this->getUrl('*/*/grid', array('_current' => true,));
68
+ }
69
+
70
+ public function getRowUrl($row)
71
+ {
72
+
73
+ }
74
+ }
app/code/community/Its/SearchLog/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Its_SearchLog_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+
app/code/community/Its/SearchLog/Model/Content.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Its_SearchLog_Model_Content extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('searchlog/content');
9
+ }
10
+ }
app/code/community/Its/SearchLog/Model/Observer.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Its_SearchLog_Model_Observer {
4
+ //$observer contains data passed from when the event was triggered.
5
+ public function send_search_details($observer) {
6
+
7
+
8
+ // Check to see if the user is logged in
9
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
10
+
11
+ // Load the customer's id to later be added to the database.
12
+ $customer = Mage::getSingleton('customer/session')->getCustomer()->getData("entity_id");
13
+ // Filter all the main details we need from $observer.
14
+ $query = $observer->getEvent()->getDataObject();
15
+ /* This pull the date and time from the query. The date and time
16
+ from this event is a bit bizarre. If you search for something that you haven't
17
+ searched for before, then it will give you the correct time, but if you use a
18
+ search term that you have used before it uses the time from the last search and adds a random amount of seconds on to the time. The only reason this time is being used is to filter out the other event that gets fired.
19
+ */
20
+ $date_time = $query->getData("updated_at");
21
+ // This is the text that the user is searching for.
22
+ $query_string =$query->getData("query_text");
23
+ // Start of the filtering. As 2 events get fired one event usually doesn't contain the query term and at times it doesn't contain the date_time.
24
+ if (!empty($query_string) and (!empty($date_time))){
25
+ // Get the number of products the search has found.
26
+ $results_count =$query->getData("num_results");
27
+ // This date is what will be saved into the database. As it is the current timestamp.
28
+ $date = date('Y-m-d H:i:s');
29
+ // Created an array to put all name->values into.
30
+ $data = array('query_text'=>$query_string,
31
+ 'user_id'=>$customer,
32
+ 'item_count_per_result'=>$results_count,
33
+ 'date_time'=>$date);
34
+ // Below is the model we are using to access the corresponding mysql table to put the data into.
35
+ $model = Mage::getModel('searchlog/content')->setData($data);
36
+ //Its the below code that eventually saves the data to the database and if there are any problems it will throw an error.
37
+ try {
38
+ $model->save();
39
+
40
+ } catch (Exception $e){
41
+ echo $e->getMessage();
42
+ }
43
+ }
44
+
45
+ }
46
+
47
+ }
48
+ }
app/code/community/Its/SearchLog/Model/Resource/Content.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Its_SearchLog_Model_Resource_Content extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $this->_init('searchlog/content', 'entity_id');
8
+ }
9
+ }
app/code/community/Its/SearchLog/Model/Resource/Content/Collection.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Its_SearchLog_Model_Resource_Content_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('searchlog/content');
8
+ }
9
+ }
app/code/community/Its/SearchLog/Model/Resource/Setup.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class Its_SearchLog_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
4
+ {
5
+ }
app/code/community/Its/SearchLog/controllers/Adminhtml/SearchlogController.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Its_SearchLog_Adminhtml_SearchlogController extends Mage_Adminhtml_Controller_Action
5
+ {
6
+ public function indexAction()
7
+ {
8
+ $this->_title($this->__('Search Log'));
9
+ $this->loadLayout();
10
+ $this->_setActiveMenu('searchlog'); //The menu that is highlighted
11
+
12
+ $this->_addContent($this->getLayout()->createBlock('searchlog/adminhtml_usersearches'));
13
+
14
+ $this->renderLayout();
15
+ return $this;
16
+ }
17
+
18
+
19
+ public function saveAction()
20
+ {
21
+ $this->loadLayout();
22
+ $this->renderLayout();
23
+ return $this;
24
+ }
25
+
26
+ public function newAction()
27
+ {
28
+ $this->loadLayout();
29
+ $this->renderLayout();
30
+ return $this;
31
+ }
32
+
33
+ public function massDeleteAction()
34
+ {
35
+ $this->loadLayout();
36
+ $this->renderLayout();
37
+ return $this;
38
+ }
39
+
40
+
41
+ public function gridAction()
42
+ {
43
+ $this->loadLayout();
44
+ $this->getResponse()->setBody(
45
+ $this->getLayout()->createBlock('searchlog/adminhtml_usersearches_grid')->toHtml()
46
+ );
47
+ }
48
+
49
+ protected function _isAllowed()
50
+ {
51
+ return Mage::getSingleton('admin/session')->isAllowed( 'admin/searchlog' );
52
+ }
53
+
54
+ }
app/code/community/Its/SearchLog/etc/adminhtml.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <searchlog translate="title" module="searchlog">
5
+ <title>Search Results Log</title>
6
+ <sort_order>90</sort_order>
7
+ <action>adminhtml/searchlog</action>
8
+ </searchlog>
9
+ </menu>
10
+ <acl>
11
+ <resources>
12
+ <all>
13
+ <title>Allow Everything</title>
14
+ </all>
15
+ <admin>
16
+ <children>
17
+ <searchlog translate="title" module="searchlog">
18
+ <title>Search Log</title>
19
+ <sort_order>20</sort_order>
20
+ </searchlog>
21
+ </children>
22
+ </admin>
23
+ </resources>
24
+ </acl>
25
+
26
+
27
+ </config>
app/code/community/Its/SearchLog/etc/config.xml ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Its_SearchLog>
5
+ <version>1.0.0</version>
6
+ </Its_SearchLog>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <searchlog>
11
+ <class>Its_SearchLog_Helper</class>
12
+ </searchlog>
13
+ </helpers>
14
+ <blocks>
15
+ <searchlog>
16
+
17
+ <class>Its_SearchLog_Block</class>
18
+ </searchlog>
19
+ </blocks>
20
+ <models>
21
+ <searchlog>
22
+ <class>Its_SearchLog_Model</class>
23
+ <resourceModel>searchlog_resource</resourceModel>
24
+ </searchlog>
25
+ <searchlog_resource>
26
+ <class>Its_SearchLog_Model_Resource</class>
27
+ <entities>
28
+ <content>
29
+ <table>its_searchlog</table>
30
+ </content>
31
+ </entities>
32
+ </searchlog_resource>
33
+ </models>
34
+ <resources>
35
+ <searchlog_setup>
36
+ <setup>
37
+ <module>Its_SearchLog</module>
38
+ <class>Its_SearchLog_Model_Resource_Setup</class>
39
+ </setup>
40
+ <connection>
41
+ <use>core_setup</use>
42
+ </connection>
43
+ </searchlog_setup>
44
+ <searchlog_write>
45
+ <connection>
46
+ <use>core_write</use>
47
+ </connection>
48
+ </searchlog_write>
49
+ <searchlog_read>
50
+ <connection>
51
+ <use>core_read</use>
52
+ </connection>
53
+ </searchlog_read>
54
+
55
+ </resources>
56
+ <events>
57
+ <catalogsearch_query_save_before>
58
+ <observers>
59
+ <its_searchlog_model_observer>
60
+ <type>singleton</type>
61
+ <class>Its_SearchLog_Model_Observer</class>
62
+ <method>send_search_details</method>
63
+ </its_searchlog_model_observer>
64
+ </observers>
65
+ </catalogsearch_query_save_before>
66
+ </events>
67
+
68
+
69
+ </global>
70
+
71
+ <admin>
72
+ <routers>
73
+ <adminhtml>
74
+ <args>
75
+ <modules>
76
+ <searchlog before="Mage_Adminhtml">Its_SearchLog_Adminhtml</searchlog>
77
+ </modules>
78
+ </args>
79
+ </adminhtml>
80
+ </routers>
81
+ </admin>
82
+ <adminhtml>
83
+ <layout>
84
+ <updates>
85
+ <searchlog>
86
+ <file>itssearchlog.xml</file>
87
+ </searchlog>
88
+ </updates>
89
+ </layout>
90
+ </adminhtml>
91
+ </config>
app/code/community/Its/SearchLog/sql/searchlog_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+ $installer = $this;
6
+
7
+ $installer->startSetup();
8
+
9
+ $installer->run("
10
+
11
+ DROP TABLE IF EXISTS {$this->getTable('its_searchlog')};
12
+ CREATE TABLE {$this->getTable('its_searchlog')} (
13
+ `query_id` int(11) unsigned NOT NULL auto_increment,
14
+ `query_text` varchar(255) NOT NULL default '',
15
+ `user_id` varchar(255) NOT NULL default '',
16
+ `item_count_per_result` varchar(255) NOT NULL default '',
17
+ `date_time` varchar(255) NOT NULL default '',
18
+ PRIMARY KEY (`query_id`)
19
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20
+
21
+ ");
22
+
23
+ $installer->endSetup();
app/etc/modules/Its_SearchLog.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Its_SearchLog>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>1.0.0</version>
8
+ </Its_SearchLog>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Its_SearchLog</name>
4
+ <version>1.4.0</version>
5
+ <stability>stable</stability>
6
+ <license>Open Software License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The Search Log extension records the search query, quantity of items found and customer ID for logged in customers.</summary>
10
+ <description>This small module will record the following information when a logged in customer uses the search functionality in Magento:&#xD;
11
+ User ID&#xD;
12
+ Search Query&#xD;
13
+ Items found per search&#xD;
14
+ Date and Time of search&#xD;
15
+ &#xD;
16
+ Installation Instructions&#xD;
17
+ 1 &#x2013; Install the extension via Magento Connect.&#xD;
18
+ 2 &#x2013; Clear the cache&#xD;
19
+ 3 &#x2013; Log out of the admin area and log back in again.&#xD;
20
+ </description>
21
+ <notes>N / A</notes>
22
+ <authors><author><name>Dominic Wetherall</name><user>dominic_wetherall</user><email>dominic_wetherall@itspecialists.uk.com</email></author></authors>
23
+ <date>2015-07-28</date>
24
+ <time>09:21:49</time>
25
+ <contents><target name="magecommunity"><dir name="Its"><dir name="SearchLog"><dir name="Block"><dir name="Adminhtml"><dir name="Usersearches"><file name="Grid.php" hash="d9aa321b04e1e34cc184437f347c13d9"/></dir><file name="Usersearches.php" hash="1285158b8d6e3846f93bfc4b63677887"/></dir></dir><dir name="Helper"><file name="Data.php" hash="974dfa29a3fe379d67738f2de92369ef"/></dir><dir name="Model"><file name="Content.php" hash="2da62bad70ddf4de113774c115be9e9a"/><file name="Observer.php" hash="79b560ac2bf3b8d4f0389042d86dabdd"/><dir name="Resource"><dir name="Content"><file name="Collection.php" hash="f59e4b8291f0f2d3fac634efac3964db"/></dir><file name="Content.php" hash="7f077e33127b58e2719b35a244568336"/><file name="Setup.php" hash="bcd973f8b3ff46d82e98d2c0b13a1808"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="SearchlogController.php" hash="da9193baad5400260ea986e37b41c7b0"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="bd8748b65a26e6a2fc2485a0e3733f00"/><file name="config.xml" hash="16a2ffd86f8b9c7052880c2ddf21fc6e"/></dir><dir name="sql"><dir name="searchlog_setup"><file name="mysql4-install-1.0.0.php" hash="5fadc2b99a9cd516e9df005e0e060dbc"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Its_SearchLog.xml" hash="4d96f3ec177cfc80630041df265a1460"/></dir></target></contents>
26
+ <compatible/>
27
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
28
+ </package>