webspeaks_notifycustomer - Version 0.0.1

Version Notes

Notifycustomer for Magento released

Download this release

Release Info

Developer Arvind Bhardwaj
Extension webspeaks_notifycustomer
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

Files changed (39) hide show
  1. app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification.php +42 -0
  2. app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit.php +87 -0
  3. app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit/Form.php +52 -0
  4. app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit/Tab/Form.php +146 -0
  5. app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit/Tabs.php +74 -0
  6. app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Grid.php +253 -0
  7. app/code/local/Webspeaks/NotifyCustomer/Block/Notification/Link.php +38 -0
  8. app/code/local/Webspeaks/NotifyCustomer/Block/Notification/List.php +75 -0
  9. app/code/local/Webspeaks/NotifyCustomer/Block/Notification/View.php +37 -0
  10. app/code/local/Webspeaks/NotifyCustomer/Controller/Adminhtml/NotifyCustomer.php +60 -0
  11. app/code/local/Webspeaks/NotifyCustomer/Helper/Data.php +120 -0
  12. app/code/local/Webspeaks/NotifyCustomer/Helper/Notification.php +53 -0
  13. app/code/local/Webspeaks/NotifyCustomer/Model/Notification.php +172 -0
  14. app/code/local/Webspeaks/NotifyCustomer/Model/Resource/Notification.php +37 -0
  15. app/code/local/Webspeaks/NotifyCustomer/Model/Resource/Notification/Collection.php +105 -0
  16. app/code/local/Webspeaks/NotifyCustomer/Model/Resource/Setup.php +26 -0
  17. app/code/local/Webspeaks/NotifyCustomer/controllers/Adminhtml/Notifycustomer/NotificationController.php +403 -0
  18. app/code/local/Webspeaks/NotifyCustomer/controllers/NotificationController.php +253 -0
  19. app/code/local/Webspeaks/NotifyCustomer/etc/adminhtml.xml +58 -0
  20. app/code/local/Webspeaks/NotifyCustomer/etc/config.xml +124 -0
  21. app/code/local/Webspeaks/NotifyCustomer/etc/system.xml +60 -0
  22. app/code/local/Webspeaks/NotifyCustomer/sql/webspeaks_notifycustomer_setup/install-0.0.1.php +85 -0
  23. app/design/adminhtml/default/default/layout/webspeaks_notifycustomer.xml +60 -0
  24. app/design/frontend/base/default/layout/webspeaks_notifycustomer.xml +69 -0
  25. app/design/frontend/base/default/template/webspeaks_notifycustomer/notification/link.phtml +27 -0
  26. app/design/frontend/base/default/template/webspeaks_notifycustomer/notification/list.phtml +66 -0
  27. app/design/frontend/base/default/template/webspeaks_notifycustomer/notification/pop-message-item.phtml +30 -0
  28. app/design/frontend/base/default/template/webspeaks_notifycustomer/notification/view.phtml +34 -0
  29. app/etc/modules/Webspeaks_NotifyCustomer.xml +29 -0
  30. app/locale/en_US/template/email/ws_notify_customer.html +5 -0
  31. js/webspeaks/notifycustomer/adminhtml/notify.js +30 -0
  32. js/webspeaks/notifycustomer/jquery-1.10.2.min.js +6 -0
  33. js/webspeaks/notifycustomer/noconflict.js +27 -0
  34. js/webspeaks/notifycustomer/notifycustomer.js +77 -0
  35. package.xml +22 -0
  36. skin/frontend/base/default/webspeaks/notifycustomer/css/notifycustomer.css +119 -0
  37. skin/frontend/base/default/webspeaks/notifycustomer/img/button-close.png +0 -0
  38. skin/frontend/base/default/webspeaks/notifycustomer/img/email-icon.png +0 -0
  39. skin/frontend/base/default/webspeaks/notifycustomer/img/opc-ajax-loader.gif +0 -0
app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification admin block
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Adminhtml_Notification extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+ /**
27
+ * constructor
28
+ *
29
+ * @access public
30
+ * @return void
31
+ * @author Ultimate Module Creator
32
+ */
33
+ public function __construct()
34
+ {
35
+ $this->_controller = 'adminhtml_notification';
36
+ $this->_blockGroup = 'webspeaks_notifycustomer';
37
+ parent::__construct();
38
+ $this->_headerText = Mage::helper('webspeaks_notifycustomer')->__('Notification');
39
+ $this->_updateButton('add', 'label', Mage::helper('webspeaks_notifycustomer')->__('New Notification'));
40
+
41
+ }
42
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification admin edit form
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Webspeaks
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+ /**
27
+ * constructor
28
+ *
29
+ * @access public
30
+ * @return void
31
+ * @author Webspeaks
32
+ */
33
+ public function __construct()
34
+ {
35
+ parent::__construct();
36
+ $this->_blockGroup = 'webspeaks_notifycustomer';
37
+ $this->_controller = 'adminhtml_notification';
38
+ $this->_updateButton(
39
+ 'save',
40
+ 'label',
41
+ Mage::helper('webspeaks_notifycustomer')->__('Send Notification')
42
+ );
43
+ $this->_updateButton(
44
+ 'delete',
45
+ 'label',
46
+ Mage::helper('webspeaks_notifycustomer')->__('Delete Notification')
47
+ );
48
+ /*$this->_addButton(
49
+ 'saveandcontinue',
50
+ array(
51
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Save And Continue Edit'),
52
+ 'onclick' => 'saveAndContinueEdit()',
53
+ 'class' => 'save',
54
+ ),
55
+ -100
56
+ );
57
+ $this->_formScripts[] = "
58
+ function saveAndContinueEdit() {
59
+ editForm.submit($('edit_form').action+'back/edit/');
60
+ }
61
+ ";*/
62
+
63
+ if ($this->getRequest()->getParam('id')) {
64
+ $this->_removeButton('save');
65
+ $this->_removeButton('reset');
66
+ }
67
+ }
68
+
69
+ /**
70
+ * get the edit form header
71
+ *
72
+ * @access public
73
+ * @return string
74
+ * @author Ultimate Module Creator
75
+ */
76
+ public function getHeaderText()
77
+ {
78
+ if (Mage::registry('current_notification') && Mage::registry('current_notification')->getId()) {
79
+ return Mage::helper('webspeaks_notifycustomer')->__(
80
+ "View Notification '%s'",
81
+ $this->escapeHtml(Mage::registry('current_notification')->getTitle())
82
+ );
83
+ } else {
84
+ return Mage::helper('webspeaks_notifycustomer')->__('Send Notification');
85
+ }
86
+ }
87
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit/Form.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification edit form
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+ /**
27
+ * prepare form
28
+ *
29
+ * @access protected
30
+ * @return Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Edit_Form
31
+ * @author Ultimate Module Creator
32
+ */
33
+ protected function _prepareForm()
34
+ {
35
+ $form = new Varien_Data_Form(
36
+ array(
37
+ 'id' => 'edit_form',
38
+ 'action' => $this->getUrl(
39
+ '*/*/save',
40
+ array(
41
+ 'id' => $this->getRequest()->getParam('id')
42
+ )
43
+ ),
44
+ 'method' => 'post',
45
+ 'enctype' => 'multipart/form-data'
46
+ )
47
+ );
48
+ $form->setUseContainer(true);
49
+ $this->setForm($form);
50
+ return parent::_prepareForm();
51
+ }
52
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit/Tab/Form.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification edit form tab
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+ /**
27
+ * prepare the form
28
+ *
29
+ * @access protected
30
+ * @return Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Edit_Tab_Form
31
+ * @author Ultimate Module Creator
32
+ */
33
+ protected function _prepareForm()
34
+ {
35
+ $form = new Varien_Data_Form();
36
+ $form->setHtmlIdPrefix('notification_');
37
+ $form->setFieldNameSuffix('notification');
38
+ $this->setForm($form);
39
+
40
+ $formValues = Mage::registry('current_notification')->getDefaultValues();
41
+ if (!is_array($formValues)) {
42
+ $formValues = array();
43
+ }
44
+ if (Mage::getSingleton('adminhtml/session')->getNotificationData()) {
45
+ $formValues = array_merge($formValues, Mage::getSingleton('adminhtml/session')->getNotificationData());
46
+ Mage::getSingleton('adminhtml/session')->setNotificationData(null);
47
+ } elseif (Mage::registry('current_notification')) {
48
+ $formValues = array_merge($formValues, Mage::registry('current_notification')->getData());
49
+ }
50
+
51
+ $fieldset = $form->addFieldset(
52
+ 'notification_form',
53
+ array('legend' => Mage::helper('webspeaks_notifycustomer')->__('Notification'))
54
+ );
55
+ $wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig();
56
+
57
+ $fieldset->addField(
58
+ 'title',
59
+ 'text',
60
+ array(
61
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Title'),
62
+ 'name' => 'title',
63
+ 'required' => true,
64
+ 'class' => 'required-entry',
65
+
66
+ )
67
+ );
68
+
69
+ $fieldset->addField(
70
+ 'message',
71
+ 'editor',
72
+ array(
73
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Message'),
74
+ 'name' => 'message',
75
+ 'config' => $wysiwygConfig,
76
+ 'required' => true,
77
+ 'class' => 'required-entry',
78
+
79
+ )
80
+ );
81
+
82
+ if (!$this->getRequest()->getParam('id')) {
83
+ $fieldset->addField(
84
+ 'customer_email',
85
+ 'text',
86
+ array(
87
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Customer Email'),
88
+ 'name' => 'customer_email',
89
+ 'required' => true,
90
+ 'class' => 'required-entry',
91
+
92
+ )
93
+ );
94
+
95
+ $element = $fieldset->addField('customer_query', 'text', array(
96
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Search Customer'),
97
+ 'name' => 'customer_query',
98
+ ));
99
+
100
+ $element->setAfterElementHtml("
101
+ <button type='button' id='find-customer-btn' data-url='".Mage::helper('adminhtml')->getUrl('adminhtml/notifycustomer_notification/customerfind')."'><span>".Mage::helper('webspeaks_notifycustomer')->__('Find').'</span></button>
102
+ ');
103
+
104
+ $element = $fieldset->addField('customer_id', 'select', array(
105
+ 'name' => 'customer_id',
106
+ 'style' => 'display: none',
107
+ ));
108
+
109
+ $fieldset->addField('send_email', 'select', array(
110
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Send email'),
111
+ 'values' => [
112
+ ['value' => '1', 'label' => 'Yes'],
113
+ ['value' => '0', 'label' => 'No']
114
+ ],
115
+ 'name' => 'send_email',
116
+ "class" => "required-entry",
117
+ "required" => true,
118
+ 'after_element_html' => '<p><small>'.Mage::helper('webspeaks_notifycustomer')->__('Also send email to customer.').'</small></p>',
119
+ ));
120
+
121
+ } else {
122
+ $customer = Mage::getModel('customer/customer')->load($formValues['customer_id']);
123
+ $fieldset->addField(
124
+ 'customer_email',
125
+ 'note',
126
+ array(
127
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Customer'),
128
+ 'text' => $customer->getData('firstname') . ' ' . $customer->getData('middlename') . ' ' . $customer->getData('lastname')
129
+ )
130
+ );
131
+
132
+ $fieldset->addField(
133
+ 'status',
134
+ 'note',
135
+ array(
136
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Status'),
137
+ 'text' => (!$formValues['status']) ? Mage::helper('webspeaks_notifycustomer')->__('Not read') : Mage::helper('webspeaks_notifycustomer')->__('Read')
138
+ )
139
+ );
140
+
141
+ }
142
+
143
+ $form->setValues($formValues);
144
+ return parent::_prepareForm();
145
+ }
146
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Edit/Tabs.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification admin edit tabs
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
25
+ {
26
+ /**
27
+ * Initialize Tabs
28
+ *
29
+ * @access public
30
+ * @author Ultimate Module Creator
31
+ */
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+ $this->setId('notification_tabs');
36
+ $this->setDestElementId('edit_form');
37
+ $this->setTitle(Mage::helper('webspeaks_notifycustomer')->__('Notification'));
38
+ }
39
+
40
+ /**
41
+ * before render html
42
+ *
43
+ * @access protected
44
+ * @return Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Edit_Tabs
45
+ * @author Ultimate Module Creator
46
+ */
47
+ protected function _beforeToHtml()
48
+ {
49
+ $this->addTab(
50
+ 'form_notification',
51
+ array(
52
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Notification'),
53
+ 'title' => Mage::helper('webspeaks_notifycustomer')->__('Notification'),
54
+ 'content' => $this->getLayout()->createBlock(
55
+ 'webspeaks_notifycustomer/adminhtml_notification_edit_tab_form'
56
+ )
57
+ ->toHtml(),
58
+ )
59
+ );
60
+ return parent::_beforeToHtml();
61
+ }
62
+
63
+ /**
64
+ * Retrieve notification entity
65
+ *
66
+ * @access public
67
+ * @return Webspeaks_NotifyCustomer_Model_Notification
68
+ * @author Ultimate Module Creator
69
+ */
70
+ public function getNotification()
71
+ {
72
+ return Mage::registry('current_notification');
73
+ }
74
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Adminhtml/Notification/Grid.php ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification admin grid block
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Grid extends Mage_Adminhtml_Block_Widget_Grid
25
+ {
26
+ /**
27
+ * constructor
28
+ *
29
+ * @access public
30
+ * @author Ultimate Module Creator
31
+ */
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+ $this->setId('notificationGrid');
36
+ $this->setDefaultSort('entity_id');
37
+ $this->setDefaultDir('ASC');
38
+ $this->setSaveParametersInSession(true);
39
+ $this->setUseAjax(true);
40
+ }
41
+
42
+ protected function _customerNameCondition($collection, $column) {
43
+
44
+ $filterValue = $column->getFilter()->getValue();
45
+ if(!is_null($filterValue)){
46
+ $filterValue = trim($filterValue);
47
+ $filterValue = preg_replace('/[\s]+/', ' ', $filterValue);
48
+
49
+ $whereArr = array();
50
+ $whereArr[] = $collection->getConnection()->quoteInto("ce1.value = ?", $filterValue);
51
+ $whereArr[] = $collection->getConnection()->quoteInto("ce2.value = ?", $filterValue);
52
+ $where = implode(' OR ', $whereArr);
53
+ $collection->getSelect()->where($where);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * prepare collection
59
+ *
60
+ * @access protected
61
+ * @return Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Grid
62
+ * @author Ultimate Module Creator
63
+ */
64
+ protected function _prepareCollection()
65
+ {
66
+ $collection = Mage::getModel('webspeaks_notifycustomer/notification')
67
+ ->getCollection()
68
+ ->addCustomerNameToSelect();
69
+
70
+ $this->setCollection($collection);
71
+ return parent::_prepareCollection();
72
+ }
73
+
74
+ /**
75
+ * prepare grid collection
76
+ *
77
+ * @access protected
78
+ * @return Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Grid
79
+ * @author Ultimate Module Creator
80
+ */
81
+ protected function _prepareColumns()
82
+ {
83
+ $this->addColumn(
84
+ 'entity_id',
85
+ array(
86
+ 'header' => Mage::helper('webspeaks_notifycustomer')->__('Id'),
87
+ 'index' => 'entity_id',
88
+ 'type' => 'number'
89
+ )
90
+ );
91
+ $this->addColumn(
92
+ 'title',
93
+ array(
94
+ 'header' => Mage::helper('webspeaks_notifycustomer')->__('Title'),
95
+ 'align' => 'left',
96
+ 'index' => 'title',
97
+ )
98
+ );
99
+ $this->addColumn(
100
+ 'customer_name',
101
+ array(
102
+ 'header' => Mage::helper('webspeaks_notifycustomer')->__('Customer'),
103
+ 'index' => 'customer_name',
104
+ 'type'=> 'text',
105
+ 'filter_condition_callback' => array($this, '_customerNameCondition')
106
+ )
107
+ );
108
+ $this->addColumn(
109
+ 'status',
110
+ array(
111
+ 'header' => Mage::helper('webspeaks_notifycustomer')->__('Read By Customer'),
112
+ 'index' => 'status',
113
+ 'type' => 'options',
114
+ 'options' => array(
115
+ '1' => Mage::helper('webspeaks_notifycustomer')->__('Yes'),
116
+ '0' => Mage::helper('webspeaks_notifycustomer')->__('No'),
117
+ )
118
+
119
+ )
120
+ );
121
+ $this->addColumn(
122
+ 'created_at',
123
+ array(
124
+ 'header' => Mage::helper('webspeaks_notifycustomer')->__('Created at'),
125
+ 'index' => 'created_at',
126
+ 'width' => '120px',
127
+ 'type' => 'datetime',
128
+ )
129
+ );
130
+ $this->addColumn(
131
+ 'action',
132
+ array(
133
+ 'header' => Mage::helper('webspeaks_notifycustomer')->__('Action'),
134
+ 'width' => '100',
135
+ 'type' => 'action',
136
+ 'getter' => 'getId',
137
+ 'actions' => array(
138
+ array(
139
+ 'caption' => Mage::helper('webspeaks_notifycustomer')->__('Edit'),
140
+ 'url' => array('base'=> '*/*/edit'),
141
+ 'field' => 'id'
142
+ )
143
+ ),
144
+ 'filter' => false,
145
+ 'is_system' => true,
146
+ 'sortable' => false,
147
+ )
148
+ );
149
+ $this->addExportType('*/*/exportCsv', Mage::helper('webspeaks_notifycustomer')->__('CSV'));
150
+ $this->addExportType('*/*/exportExcel', Mage::helper('webspeaks_notifycustomer')->__('Excel'));
151
+ $this->addExportType('*/*/exportXml', Mage::helper('webspeaks_notifycustomer')->__('XML'));
152
+ return parent::_prepareColumns();
153
+ }
154
+
155
+ /**
156
+ * prepare mass action
157
+ *
158
+ * @access protected
159
+ * @return Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Grid
160
+ * @author Ultimate Module Creator
161
+ */
162
+ protected function _prepareMassaction()
163
+ {
164
+ $this->setMassactionIdField('entity_id');
165
+ $this->getMassactionBlock()->setFormFieldName('notification');
166
+ $this->getMassactionBlock()->addItem(
167
+ 'delete',
168
+ array(
169
+ 'label'=> Mage::helper('webspeaks_notifycustomer')->__('Delete'),
170
+ 'url' => $this->getUrl('*/*/massDelete'),
171
+ 'confirm' => Mage::helper('webspeaks_notifycustomer')->__('Are you sure?')
172
+ )
173
+ );
174
+ $this->getMassactionBlock()->addItem(
175
+ 'status',
176
+ array(
177
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Change status'),
178
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
179
+ 'additional' => array(
180
+ 'status' => array(
181
+ 'name' => 'status',
182
+ 'type' => 'select',
183
+ 'class' => 'required-entry',
184
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Status'),
185
+ 'values' => array(
186
+ '1' => Mage::helper('webspeaks_notifycustomer')->__('Enabled'),
187
+ '0' => Mage::helper('webspeaks_notifycustomer')->__('Disabled'),
188
+ )
189
+ )
190
+ )
191
+ )
192
+ );
193
+ $this->getMassactionBlock()->addItem(
194
+ 'read',
195
+ array(
196
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Change Read By Customer'),
197
+ 'url' => $this->getUrl('*/*/massRead', array('_current'=>true)),
198
+ 'additional' => array(
199
+ 'flag_read' => array(
200
+ 'name' => 'flag_read',
201
+ 'type' => 'select',
202
+ 'class' => 'required-entry',
203
+ 'label' => Mage::helper('webspeaks_notifycustomer')->__('Read By Customer'),
204
+ 'values' => array(
205
+ '1' => Mage::helper('webspeaks_notifycustomer')->__('Yes'),
206
+ '0' => Mage::helper('webspeaks_notifycustomer')->__('No'),
207
+ )
208
+
209
+ )
210
+ )
211
+ )
212
+ );
213
+ return $this;
214
+ }
215
+
216
+ /**
217
+ * get the row url
218
+ *
219
+ * @access public
220
+ * @param Webspeaks_NotifyCustomer_Model_Notification
221
+ * @return string
222
+ * @author Ultimate Module Creator
223
+ */
224
+ public function getRowUrl($row)
225
+ {
226
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
227
+ }
228
+
229
+ /**
230
+ * get the grid url
231
+ *
232
+ * @access public
233
+ * @return string
234
+ * @author Ultimate Module Creator
235
+ */
236
+ public function getGridUrl()
237
+ {
238
+ return $this->getUrl('*/*/grid', array('_current'=>true));
239
+ }
240
+
241
+ /**
242
+ * after collection load
243
+ *
244
+ * @access protected
245
+ * @return Webspeaks_NotifyCustomer_Block_Adminhtml_Notification_Grid
246
+ * @author Ultimate Module Creator
247
+ */
248
+ protected function _afterLoadCollection()
249
+ {
250
+ $this->getCollection()->walk('afterLoad');
251
+ parent::_afterLoadCollection();
252
+ }
253
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Notification/Link.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification view block
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Webspeaks
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Notification_Link extends Mage_Core_Block_Template
25
+ {
26
+ public function getNotifBaseUrl()
27
+ {
28
+ return $this->getUrl('notifications/notification');
29
+ }
30
+
31
+ public function getUnreadCount()
32
+ {
33
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
34
+ return Mage::getModel('webspeaks_notifycustomer/notification')
35
+ ->getUnreadCount($customer->getData('entity_id'));
36
+ }
37
+
38
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Notification/List.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification list block
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Notification_List extends Mage_Core_Block_Template
25
+ {
26
+ /**
27
+ * initialize
28
+ *
29
+ * @access public
30
+ * @author Ultimate Module Creator
31
+ */
32
+ public function _construct()
33
+ {
34
+ parent::_construct();
35
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
36
+ $notifications = Mage::getResourceModel('webspeaks_notifycustomer/notification_collection')
37
+ ->addFieldTofilter('customer_id', $customer->getId())
38
+ ->setOrder('entity_id', 'DESC')
39
+ ;
40
+ $notifications->setOrder('title', 'asc');
41
+ $this->setNotifications($notifications);
42
+ }
43
+
44
+ /**
45
+ * prepare the layout
46
+ *
47
+ * @access protected
48
+ * @return Webspeaks_NotifyCustomer_Block_Notification_List
49
+ * @author Ultimate Module Creator
50
+ */
51
+ protected function _prepareLayout()
52
+ {
53
+ parent::_prepareLayout();
54
+ $pager = $this->getLayout()->createBlock(
55
+ 'page/html_pager',
56
+ 'webspeaks_notifycustomer.notification.html.pager'
57
+ )
58
+ ->setCollection($this->getNotifications());
59
+ $this->setChild('pager', $pager);
60
+ $this->getNotifications()->load();
61
+ return $this;
62
+ }
63
+
64
+ /**
65
+ * get the pager html
66
+ *
67
+ * @access public
68
+ * @return string
69
+ * @author Ultimate Module Creator
70
+ */
71
+ public function getPagerHtml()
72
+ {
73
+ return $this->getChildHtml('pager');
74
+ }
75
+ }
app/code/local/Webspeaks/NotifyCustomer/Block/Notification/View.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification view block
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Block_Notification_View extends Mage_Core_Block_Template
25
+ {
26
+ /**
27
+ * get the current notification
28
+ *
29
+ * @access public
30
+ * @return mixed (Webspeaks_NotifyCustomer_Model_Notification|null)
31
+ * @author Ultimate Module Creator
32
+ */
33
+ public function getCurrentNotification()
34
+ {
35
+ return Mage::registry('current_notification');
36
+ }
37
+ }
app/code/local/Webspeaks/NotifyCustomer/Controller/Adminhtml/NotifyCustomer.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * module base admin controller
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Controller_Adminhtml_NotifyCustomer extends Mage_Adminhtml_Controller_Action
25
+ {
26
+ /**
27
+ * upload file and get the uploaded name
28
+ *
29
+ * @access public
30
+ * @param string $input
31
+ * @param string $destinationFolder
32
+ * @param array $data
33
+ * @return string
34
+ * @author Ultimate Module Creator
35
+ */
36
+ protected function _uploadAndGetName($input, $destinationFolder, $data)
37
+ {
38
+ try {
39
+ if (isset($data[$input]['delete'])) {
40
+ return '';
41
+ } else {
42
+ $uploader = new Varien_File_Uploader($input);
43
+ $uploader->setAllowRenameFiles(true);
44
+ $uploader->setFilesDispersion(true);
45
+ $uploader->setAllowCreateFolders(true);
46
+ $result = $uploader->save($destinationFolder);
47
+ return $result['file'];
48
+ }
49
+ } catch (Exception $e) {
50
+ if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
51
+ throw $e;
52
+ } else {
53
+ if (isset($data[$input]['value'])) {
54
+ return $data[$input]['value'];
55
+ }
56
+ }
57
+ }
58
+ return '';
59
+ }
60
+ }
app/code/local/Webspeaks/NotifyCustomer/Helper/Data.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * NotifyCustomer default helper
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Helper_Data extends Mage_Core_Helper_Abstract
25
+ {
26
+ /**
27
+ * convert array to options
28
+ *
29
+ * @access public
30
+ * @param $options
31
+ * @return array
32
+ * @author Ultimate Module Creator
33
+ */
34
+ public function convertOptions($options)
35
+ {
36
+ $converted = array();
37
+ foreach ($options as $option) {
38
+ if (isset($option['value']) && !is_array($option['value']) &&
39
+ isset($option['label']) && !is_array($option['label'])) {
40
+ $converted[$option['value']] = $option['label'];
41
+ }
42
+ }
43
+ return $converted;
44
+ }
45
+
46
+ public function getCustomerArray($q = false, $customerId = false, $addressId = false)
47
+ {
48
+ $model = Mage::getSingleton('customer/customer');
49
+ $result = $model->getCollection()
50
+ ->addAttributeToSelect(array('entity_id', 'firstname', 'email'))
51
+ ->addAttributeToFilter(
52
+ array(
53
+ array('attribute'=>'firstname', 'like' => "%$q%"),
54
+ array('attribute'=>'lastname', 'like' => "%$q%"),
55
+ array('attribute'=>'email', 'like' => "%$q%"),
56
+ )
57
+ )
58
+ ;
59
+
60
+ $data = [];
61
+ foreach($result as $r) {
62
+ $data[] = [
63
+ 'name' => $r->getData('firstname') . ' ' . $r->getData('lastname') . ' (' . $r->getData('email') . ')',
64
+ 'email' => $r->getData('email'),
65
+ 'id' => $r->getData('entity_id'),
66
+ ];
67
+ }
68
+
69
+ return $data;
70
+ }
71
+
72
+ public function findCustomer($q)
73
+ {
74
+ $customers = $this->getCustomerArray($q);
75
+ return $customers;
76
+ }
77
+
78
+ public function findCustomerByEmail($email)
79
+ {
80
+ $model = Mage::getSingleton('customer/customer');
81
+ $result = $model->getCollection()
82
+ ->addAttributeToFilter('email', $email)
83
+ ->getFirstItem();
84
+ echo $result->getSelect();
85
+ return $result;
86
+ }
87
+
88
+ public function sendEmailToCustomer($data)
89
+ {
90
+ $emailTemplate = Mage::getModel('core/email_template')->loadDefault('ws_notify_customer_eml');
91
+ $from_email = Mage::getStoreConfig('trans_email/ident_general/email'); //fetch sender email Admin
92
+ $from_name = Mage::getStoreConfig('trans_email/ident_general/name'); //fetch sender name Admin
93
+
94
+ $emailTemplateVariables = array();
95
+ $emailTemplateVariables['body'] = $data['message'];
96
+
97
+ //Appending the Custom Variables to Template.
98
+ $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
99
+
100
+ //Sending E-Mail to Customers.
101
+ $mail = Mage::getModel('core/email')
102
+ ->setToName($data['customer_email'])
103
+ ->setToEmail($data['customer_email'])
104
+ ->setBody($processedTemplate)
105
+ ->setSubject($data['title'])
106
+ ->setFromEmail($from_email)
107
+ ->setFromName($from_name)
108
+ ->setType('html');
109
+
110
+ try {
111
+ //E-Mail Send
112
+ $mail->send();
113
+ }
114
+ catch(Exception $error)
115
+ {
116
+ Mage::getSingleton('core/session')->addError($error->getMessage());
117
+ return false;
118
+ }
119
+ }
120
+ }
app/code/local/Webspeaks/NotifyCustomer/Helper/Notification.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification helper
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Helper_Notification extends Mage_Core_Helper_Abstract
25
+ {
26
+
27
+ /**
28
+ * get the url to the notifications list page
29
+ *
30
+ * @access public
31
+ * @return string
32
+ * @author Ultimate Module Creator
33
+ */
34
+ public function getNotificationsUrl()
35
+ {
36
+ if ($listKey = Mage::getStoreConfig('webspeaks_notifycustomer/notification/url_rewrite_list')) {
37
+ return Mage::getUrl('', array('_direct'=>$listKey));
38
+ }
39
+ return Mage::getUrl('webspeaks_notifycustomer/notification/index');
40
+ }
41
+
42
+ /**
43
+ * check if breadcrumbs can be used
44
+ *
45
+ * @access public
46
+ * @return bool
47
+ * @author Ultimate Module Creator
48
+ */
49
+ public function getUseBreadcrumbs()
50
+ {
51
+ return Mage::getStoreConfigFlag('webspeaks_notifycustomer/notification/breadcrumbs');
52
+ }
53
+ }
app/code/local/Webspeaks/NotifyCustomer/Model/Notification.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification model
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Model_Notification extends Mage_Core_Model_Abstract
25
+ {
26
+ /**
27
+ * Entity code.
28
+ * Can be used as part of method name for entity processing
29
+ */
30
+ const ENTITY = 'webspeaks_notifycustomer_notification';
31
+ const CACHE_TAG = 'webspeaks_notifycustomer_notification';
32
+
33
+ /**
34
+ * Prefix of model events names
35
+ *
36
+ * @var string
37
+ */
38
+ protected $_eventPrefix = 'webspeaks_notifycustomer_notification';
39
+
40
+ /**
41
+ * Parameter name in event
42
+ *
43
+ * @var string
44
+ */
45
+ protected $_eventObject = 'notification';
46
+
47
+ /**
48
+ * constructor
49
+ *
50
+ * @access public
51
+ * @return void
52
+ * @author Webspeaks
53
+ */
54
+ public function _construct()
55
+ {
56
+ parent::_construct();
57
+ $this->_init('webspeaks_notifycustomer/notification');
58
+ }
59
+
60
+ /**
61
+ * before save notification
62
+ *
63
+ * @access protected
64
+ * @return Webspeaks_NotifyCustomer_Model_Notification
65
+ * @author Webspeaks
66
+ */
67
+ protected function _beforeSave()
68
+ {
69
+ parent::_beforeSave();
70
+ $now = Mage::getSingleton('core/date')->gmtDate();
71
+ if ($this->isObjectNew()) {
72
+ $this->setCreatedAt($now);
73
+ }
74
+ $this->setUpdatedAt($now);
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * get the url to the notification details page
80
+ *
81
+ * @access public
82
+ * @return string
83
+ * @author Webspeaks
84
+ */
85
+ public function getNotificationUrl()
86
+ {
87
+ return Mage::getUrl('webspeaks_notifycustomer/notification/view', array('id'=>$this->getId()));
88
+ }
89
+
90
+ /**
91
+ * get the notification Message
92
+ *
93
+ * @access public
94
+ * @return string
95
+ * @author Webspeaks
96
+ */
97
+ public function getMessage()
98
+ {
99
+ $message = $this->getData('message');
100
+ $helper = Mage::helper('cms');
101
+ $processor = $helper->getBlockTemplateProcessor();
102
+ $html = $processor->filter($message);
103
+ return $html;
104
+ }
105
+
106
+ /**
107
+ * save notification relation
108
+ *
109
+ * @access public
110
+ * @return Webspeaks_NotifyCustomer_Model_Notification
111
+ * @author Webspeaks
112
+ */
113
+ protected function _afterSave()
114
+ {
115
+ return parent::_afterSave();
116
+ }
117
+
118
+ /**
119
+ * get default values
120
+ *
121
+ * @access public
122
+ * @return array
123
+ * @author Webspeaks
124
+ */
125
+ public function getDefaultValues()
126
+ {
127
+ $values = array();
128
+ $values['status'] = 1;
129
+ return $values;
130
+ }
131
+
132
+ /**
133
+ * Get customer unread count
134
+ *
135
+ * @access public
136
+ * @return array
137
+ * @author Webspeaks
138
+ */
139
+ public function getUnreadCount($customer_id)
140
+ {
141
+ $notifications = Mage::getResourceModel('webspeaks_notifycustomer/notification_collection');
142
+ $notifications->addFieldToFilter('status', 0)
143
+ ->addFieldToFilter('customer_id', $customer_id);
144
+ return $notifications->getSize();
145
+ }
146
+
147
+ /**
148
+ * Get customer notifications
149
+ *
150
+ * @access public
151
+ * @return array
152
+ * @author Webspeaks
153
+ */
154
+ public function getCustomerNotifications($customer_id, $count=null, $fields=[])
155
+ {
156
+ $notifications = Mage::getResourceModel('webspeaks_notifycustomer/notification_collection');
157
+
158
+ if (count($fields)) {
159
+ $notifications->addFieldToSelect($fields);
160
+ }
161
+
162
+ $notifications->addFieldToFilter('customer_id', $customer_id);
163
+
164
+ if ($count) {
165
+ $notifications->setPageSize($count)->setCurPage(1);
166
+ }
167
+
168
+ $notifications->setOrder('entity_id', 'DESC');
169
+ return $notifications;
170
+ }
171
+
172
+ }
app/code/local/Webspeaks/NotifyCustomer/Model/Resource/Notification.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification resource model
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Ultimate Module Creator
23
+ */
24
+ class Webspeaks_NotifyCustomer_Model_Resource_Notification extends Mage_Core_Model_Resource_Db_Abstract
25
+ {
26
+
27
+ /**
28
+ * constructor
29
+ *
30
+ * @access public
31
+ * @author Ultimate Module Creator
32
+ */
33
+ public function _construct()
34
+ {
35
+ $this->_init('webspeaks_notifycustomer/notification', 'entity_id');
36
+ }
37
+ }
app/code/local/Webspeaks/NotifyCustomer/Model/Resource/Notification/Collection.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Webspeaks_NotifyCustomer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Webspeaks
13
+ * @package Webspeaks_NotifyCustomer
14
+ * @copyright Copyright (c) 2016
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Notification collection resource model
19
+ *
20
+ * @category Webspeaks
21
+ * @package Webspeaks_NotifyCustomer
22
+ * @author Webspeaks
23
+ */
24
+ class Webspeaks_NotifyCustomer_Model_Resource_Notification_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
25
+ {
26
+ protected $_joinedFields = array();
27
+
28
+ /**
29
+ * constructor
30
+ *
31
+ * @access public
32
+ * @return void
33
+ * @author Webspeaks
34
+ */
35
+ protected function _construct()
36
+ {
37
+ parent::_construct();
38
+ $this->_init('webspeaks_notifycustomer/notification');
39
+ }
40
+
41
+ /**
42
+ * get notifications as array
43
+ *
44
+ * @access protected
45
+ * @param string $valueField
46
+ * @param string $labelField
47
+ * @param array $additional
48
+ * @return array
49
+ * @author Webspeaks
50
+ */
51
+ protected function _toOptionArray($valueField='entity_id', $labelField='title', $additional=array())
52
+ {
53
+ return parent::_toOptionArray($valueField, $labelField, $additional);
54
+ }
55
+
56
+ /**
57
+ * get options hash
58
+ *
59
+ * @access protected
60
+ * @param string $valueField
61
+ * @param string $labelField
62
+ * @return array
63
+ * @author Webspeaks
64
+ */
65
+ protected function _toOptionHash($valueField='entity_id', $labelField='title')
66
+ {
67
+ return parent::_toOptionHash($valueField, $labelField);
68
+ }
69
+
70
+ /**
71
+ * Get SQL for get record count.
72
+ * Extra GROUP BY strip added.
73
+ *
74
+ * @access public
75
+ * @return Varien_Db_Select