NthMobile_EasyWebShopSMS - Version 1.0.1

Version Notes

First release

Download this release

Release Info

Developer NTH
Extension NthMobile_EasyWebShopSMS
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (45) hide show
  1. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmsabandonedcarts.php +49 -0
  2. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmsabandonedcarts/Grid.php +235 -0
  3. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmslogs.php +18 -0
  4. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmslogs/Grid.php +162 -0
  5. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmssaleabandonedcarts.php +49 -0
  6. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmssaleabandonedcarts/Grid.php +247 -0
  7. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/System/Config/Log/Log.php +58 -0
  8. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/System/Config/Log/Reset.php +71 -0
  9. app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/System/Config/Section/Details.php +50 -0
  10. app/code/community/NthMobile/EasyWebShopSMS/Helper/Data.php +185 -0
  11. app/code/community/NthMobile/EasyWebShopSMS/Model/Abandonedcart/Collection.php +313 -0
  12. app/code/community/NthMobile/EasyWebShopSMS/Model/Bulkclient.php +32 -0
  13. app/code/community/NthMobile/EasyWebShopSMS/Model/Config.php +74 -0
  14. app/code/community/NthMobile/EasyWebShopSMS/Model/Easywebshopsms.php +15 -0
  15. app/code/community/NthMobile/EasyWebShopSMS/Model/Logger/Factory.php +37 -0
  16. app/code/community/NthMobile/EasyWebShopSMS/Model/Logger/Logger.php +59 -0
  17. app/code/community/NthMobile/EasyWebShopSMS/Model/Notifier.php +481 -0
  18. app/code/community/NthMobile/EasyWebShopSMS/Model/Observer.php +150 -0
  19. app/code/community/NthMobile/EasyWebShopSMS/Model/Resource/Easywebshopsms.php +14 -0
  20. app/code/community/NthMobile/EasyWebShopSMS/Model/Resource/Easywebshopsms/Collection.php +14 -0
  21. app/code/community/NthMobile/EasyWebShopSMS/Model/Resource/Setup.php +5 -0
  22. app/code/community/NthMobile/EasyWebShopSMS/Model/Resources/Setup.php +5 -0
  23. app/code/community/NthMobile/EasyWebShopSMS/controllers/Adminhtml/EasywebshopsmsabandonedcartsController.php +72 -0
  24. app/code/community/NthMobile/EasyWebShopSMS/controllers/Adminhtml/EasywebshopsmslogsController.php +35 -0
  25. app/code/community/NthMobile/EasyWebShopSMS/controllers/Adminhtml/EasywebshopsmssaleabandonedcartsController.php +73 -0
  26. app/code/community/NthMobile/EasyWebShopSMS/controllers/ApiController.php +78 -0
  27. app/code/community/NthMobile/EasyWebShopSMS/controllers/TestController.php +37 -0
  28. app/code/community/NthMobile/EasyWebShopSMS/etc/config.xml +197 -0
  29. app/code/community/NthMobile/EasyWebShopSMS/etc/system.xml +509 -0
  30. app/code/community/NthMobile/EasyWebShopSMS/sql/NthMobile_EasyWebShopSMS_setup/install-1.0.0.php +101 -0
  31. app/code/community/NthMobile/EasyWebShopSMS/sql/NthMobile_EasyWebShopSMS_setup/upgrade-1.0.0-1.0.1.php +18 -0
  32. app/code/community/NthMobile/EasyWebShopSMS/sql/easywebshopsms_customer/install-1.0.0.php +42 -0
  33. app/design/adminhtml/base/default/layout/nthmobile_easywebshopsms.xml +20 -0
  34. app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/abandonedcarts/list.phtml +12 -0
  35. app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/system/config/log/log.phtml +71 -0
  36. app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/system/config/log/reset.phtml +19 -0
  37. app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/system/config/section/details.phtml +43 -0
  38. app/design/frontend/base/default/layout/nthmobile_easywebshopsms.xml +40 -0
  39. app/design/frontend/base/default/template/nthmobile/easywebshopsms/form/edit.phtml +8 -0
  40. app/design/frontend/base/default/template/nthmobile/easywebshopsms/form/register.phtml +7 -0
  41. app/design/frontend/base/default/template/nthmobile/easywebshopsms/onepage/info/mobile_number.phtml +11 -0
  42. app/etc/modules/NthMobile_EasyWebShopSMS.xml +32 -0
  43. package.xml +39 -0
  44. skin/adminhtml/base/default/images/nthmobile/easywebshopsms/logo.jpg +0 -0
  45. skin/adminhtml/base/default/js/nthmobile/easywebshopsms/smscounter.js +59 -0
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmsabandonedcarts.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class NthMobile_EasyWebShopSMS_Block_Adminhtml_Abandonedcarts
5
+ */
6
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmsabandonedcarts extends Mage_Adminhtml_Block_Widget_Grid_Container
7
+ {
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct()
12
+ {
13
+ $this->_controller = 'adminhtml_easywebshopsmsabandonedcarts';
14
+ $this->_blockGroup = 'easywebshopsms';
15
+ $this->_headerText = Mage::helper('easywebshopsms')->__('Abandoned Carts (Applied delay: %s days)', Mage::getStoreConfig('abandonedcartsconfig/options/notify_delay'));
16
+ parent::__construct();
17
+ $this->_removeButton('add');
18
+ $this->_addButton('notify', array(
19
+ 'label' => Mage::helper('easywebshopsms')->__('Send SMS notifications to ALL'),
20
+ 'onclick' => "setLocation('".$this->getUrl('*/*/notifyAll', array('store' => $this->getRequest()->getParam('store', 0)))."')",
21
+ ));
22
+ $this->setTemplate('nthmobile/easywebshopsms/abandonedcarts/list.phtml');
23
+ }
24
+
25
+ /**
26
+ * Prepare the layout
27
+ */
28
+ protected function _prepareLayout()
29
+ {
30
+ // Display store switcher if system has more one store
31
+ if (!Mage::app()->isSingleStoreMode())
32
+ {
33
+ $this->setChild('store_switcher', $this->getLayout()->createBlock('adminhtml/store_switcher')
34
+ ->setUseConfirm(false)
35
+ ->setSwitchUrl($this->getUrl('*/*/*', array('store' => null)))
36
+ );
37
+ }
38
+ return parent::_prepareLayout();
39
+ }
40
+
41
+ /**
42
+ * Getter for the store switcher HTML
43
+ */
44
+ public function getStoreSwitcherHtml()
45
+ {
46
+ return $this->getChildHtml('store_switcher');
47
+ }
48
+
49
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmsabandonedcarts/Grid.php ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class NthMobile_EasyWebShopSMS_Block_Adminhtml_Abandonedcarts_Grid
5
+ */
6
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmsabandonedcarts_Grid extends Mage_Adminhtml_Block_Widget_Grid
7
+ {
8
+
9
+ /**
10
+ * @return NthMobile_EasyWebShopSMS_Model_Config
11
+ */
12
+ public function getConfig()
13
+ {
14
+ return Mage::getModel('easywebshopsms/config');
15
+ }
16
+
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this->setId('easywebshopsmsabandonedcartsGrid');
22
+ $this->setDefaultSort('cart_updated_at');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setUseAjax(true);
26
+ }
27
+
28
+ /**
29
+ * @return mixed
30
+ */
31
+ protected function _getStore()
32
+ {
33
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
34
+ return Mage::app()->getStore($storeId);
35
+ }
36
+
37
+ protected function _prepareCollection()
38
+ {
39
+
40
+ // Delay
41
+ $delay = $this->getConfig()->getNotifDelay();
42
+
43
+ // Default store and website
44
+ $defaults = $this->_getDefaultStoreAndWebsite();
45
+
46
+ // Store and website from the multistore switcher
47
+ $store = $this->_getStore();
48
+ if ($storeId = $store->getId())
49
+ {
50
+ $defaults = array(
51
+ $storeId,
52
+ Mage::getModel('core/store')->load($storeId)->getWebsiteId()
53
+ );
54
+ }
55
+
56
+ $collection = Mage::getModel('NthMobile_EasyWebShopSMS_Model_Abandonedcart_Collection')->getCollection($delay, $defaults[0], $defaults[1]);
57
+ //Mage::log((string) $collection->getSelect());
58
+ // Group by to have a nice grid
59
+ if (Mage::helper('catalog/product_flat')->isEnabled()) {
60
+ $collection->getSelect()->columns(
61
+ array(
62
+ 'product_ids' => 'GROUP_CONCAT(e.entity_id)',
63
+ 'product_names' => 'GROUP_CONCAT(catalog_flat.name)',
64
+ 'product_prices' => 'SUM(catalog_flat.price)'
65
+ )
66
+ );
67
+ } else {
68
+ $collection->getSelect()->columns(
69
+ array(
70
+ 'product_ids' => 'GROUP_CONCAT(e.entity_id)',
71
+ 'product_names' => 'GROUP_CONCAT(catalog_name.value)',
72
+ 'product_prices' => 'SUM(catalog_price.value)'
73
+ )
74
+ );
75
+ }
76
+ $collection->getSelect()->group('customer_mobile_number_attribute.value');
77
+
78
+ $this->setCollection($collection);
79
+ return parent::_prepareCollection();
80
+ }
81
+
82
+ protected function _prepareColumns()
83
+ {
84
+ $this->addColumn('customer_mobile_number', array(
85
+ 'header' => Mage::helper('easywebshopsms')->__('Customer Mobile'),
86
+ 'index' => 'customer_mobile_number',
87
+ 'filter_index' => 'customer_mobile_number_attribute.value',
88
+ 'filter_condition_callback' => array($this, 'filterCallback')
89
+ ));
90
+
91
+ $this->addColumn('customer_firstname', array(
92
+ 'header' => Mage::helper('easywebshopsms')->__('Customer Firstname'),
93
+ 'index' => 'customer_firstname',
94
+ 'filter_condition_callback' => array($this, 'filterCallback')
95
+ ));
96
+
97
+ $this->addColumn('customer_lastname', array(
98
+ 'header' => Mage::helper('easywebshopsms')->__('Customer Lastname'),
99
+ 'index' => 'customer_lastname',
100
+ 'filter_condition_callback' => array($this, 'filterCallback')
101
+ ));
102
+
103
+ $this->addColumn('product_ids', array(
104
+ 'header' => Mage::helper('easywebshopsms')->__('Product Ids'),
105
+ 'index' => 'product_ids',
106
+ 'filter_index' => "e.entity_id",
107
+ 'filter_condition_callback' => array($this, 'filterEqualCallback')
108
+ ));
109
+
110
+ $this->addColumn('product_names', array(
111
+ 'header' => Mage::helper('easywebshopsms')->__('Product Names'),
112
+ 'index' => 'product_names',
113
+ 'filter_index' => (Mage::helper('catalog/product_flat')->isEnabled() ? "catalog_flat.name" : "catalog_name.value"),
114
+ 'filter_condition_callback' => array($this, 'filterEqualCallback')
115
+ ));
116
+
117
+ $this->addColumn('product_prices', array(
118
+ 'header' => Mage::helper('easywebshopsms')->__('Cart Total'),
119
+ 'index' => 'product_prices',
120
+ 'filter' => false,
121
+ 'type' => 'price',
122
+ 'currency_code' => $this->_getStore()->getBaseCurrency()->getCode(),
123
+ ));
124
+
125
+ // Output format for the start and end dates
126
+ $outputFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
127
+
128
+ $this->addColumn('cart_updated_at', array(
129
+ 'header' => Mage::helper('easywebshopsms')->__('Cart Updated At'),
130
+ 'index' => 'cart_updated_at',
131
+ 'type' => 'datetime',
132
+ 'format' => $outputFormat,
133
+ 'default' => ' -- ',
134
+ 'filter_index' => 'quote_table.updated_at',
135
+ 'filter_condition_callback' => array($this, 'filterDateCallback')
136
+ ));
137
+
138
+ return parent::_prepareColumns();
139
+ }
140
+
141
+ /**
142
+ * @return $this
143
+ */
144
+ protected function _prepareMassaction()
145
+ {
146
+ $this->setMassactionIdField('customer_mobile_number');
147
+ $this->getMassactionBlock()->setFormFieldName('easywebshopsmsabandonedcarts');
148
+
149
+ $this->getMassactionBlock()->addItem('notify', array(
150
+ 'label' => Mage::helper('easywebshopsms')->__('Send notification'),
151
+ 'url' => $this->getUrl('*/*/notify', array('store' => $this->getRequest()->getParam('store', 0)))
152
+ ));
153
+
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * @return array
159
+ */
160
+ protected function _getDefaultStoreAndWebsite()
161
+ {
162
+ foreach (Mage::app()->getWebsites() as $website) {
163
+ // Get the website id
164
+ $websiteId = $website->getWebsiteId();
165
+ foreach ($website->getGroups() as $group) {
166
+ $stores = $group->getStores();
167
+ foreach ($stores as $store) {
168
+
169
+ // Get the store id
170
+ $storeId = $store->getStoreId();
171
+ break 3;
172
+ }
173
+ }
174
+ }
175
+ return array($storeId, $websiteId);
176
+ }
177
+
178
+ /**
179
+ * @return string
180
+ */
181
+ public function getGridUrl()
182
+ {
183
+ return $this->getUrl('*/*/grid', array('current' => true, 'store' => $this->getRequest()->getParam('store', 0)));
184
+ }
185
+
186
+ /**
187
+ * @param $collection
188
+ * @param $column
189
+ */
190
+ public function filterCallback($collection, $column)
191
+ {
192
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
193
+ $value = $column->getFilter()->getValue();
194
+ if(!empty($value)) {
195
+ $collection->getSelect()->where("$field like ?", '%' . $value . '%');
196
+ }
197
+ }
198
+
199
+ /**
200
+ * @param $collection
201
+ * @param $column
202
+ */
203
+ public function filterEqualCallback($collection, $column)
204
+ {
205
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
206
+ $value = $column->getFilter()->getValue();
207
+ if(!empty($value)) {
208
+ $collection->getSelect()->where("$field = ?", $value);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * @param $collection
214
+ * @param $column
215
+ */
216
+ public function filterDateCallback($collection, $column)
217
+ {
218
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
219
+ $value = $column->getFilter()->getValue();
220
+ if(!empty($value)) {
221
+ $where = "";
222
+ if(!empty($value['from'])){
223
+ $where .= "$field > '" . $value['from']->toString('Y-MM-dd HH:mm:ss') . "'";
224
+ }
225
+ if(!empty($value['to'])){
226
+ if(!empty($where)) {
227
+ $where .= " AND ";
228
+ }
229
+ $where .= "$field < '" . $value['to']->toString('Y-MM-dd HH:mm:ss') . "'";
230
+ }
231
+ $collection->getSelect()->where($where);
232
+ }
233
+ }
234
+
235
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmslogs.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 31.5.2016.
6
+ * Time: 10:03
7
+ */
8
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmslogs extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ $this->_controller = 'adminhtml_easywebshopsmslogs';
13
+ $this->_blockGroup = 'easywebshopsms';
14
+ $this->_headerText = Mage::helper('easywebshopsms')->__('Message Log');
15
+ parent::__construct();
16
+ $this->_removeButton('add');
17
+ }
18
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmslogs/Grid.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmslogs_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+
8
+ parent::__construct();
9
+ $this->setId('easywebshopsmslogsGrid');
10
+ // This is the primary key of the database
11
+ $this->setDefaultSort('easywebshopsms_id');
12
+ $this->setDefaultDir('ASC');
13
+ $this->setSaveParametersInSession(true);
14
+ $this->setUseAjax(true);
15
+ }
16
+
17
+ protected function _prepareCollection()
18
+ {
19
+ $collection = Mage::getModel('easywebshopsms/easywebshopsms')->getCollection();
20
+ $fn = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
21
+ $ln = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
22
+ $collection->getSelect()
23
+ ->join(array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.customer_id', array('firstname' => 'value'))
24
+ ->where('ce1.attribute_id='.$fn->getAttributeId())
25
+ ->join(array('ce2' => 'customer_entity_varchar'), 'ce2.entity_id=main_table.customer_id', array('lastname' => 'value'))
26
+ ->where('ce2.attribute_id='.$ln->getAttributeId())
27
+ ->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS customer_name"));
28
+ $this->setCollection($collection);
29
+ return parent::_prepareCollection();
30
+ }
31
+
32
+ protected function _prepareColumns()
33
+ {
34
+ $this->addColumn('id', array(
35
+ 'header' => Mage::helper('easywebshopsms')->__('ID'),
36
+ 'align' =>'right',
37
+ 'width' => '50px',
38
+ 'index' => 'id',
39
+ 'filter_condition_callback' => array($this, 'filterEqualCallback')
40
+ ));
41
+
42
+
43
+ $this->addColumn('customer_name', array(
44
+ 'header' => Mage::helper('easywebshopsms')->__('Customer'),
45
+ 'align' =>'left',
46
+ 'width' => '250px',
47
+ 'index' => 'customer_name',
48
+ 'filter_index' => "CONCAT(`ce1`.`value`, ' ',`ce2`.`value`)",
49
+ 'filter_condition_callback' => array($this, 'filterCallback')
50
+ ));
51
+
52
+ $this->addColumn('event_name', array(
53
+ 'header' => Mage::helper('easywebshopsms')->__('Event'),
54
+ 'align' => 'left',
55
+ 'width' => '150px',
56
+ 'type' => 'varchar',
57
+ 'default' => '--',
58
+ 'index' => 'event_name',
59
+ 'filter_condition_callback' => array($this, 'filterCallback')
60
+ ));
61
+
62
+ $this->addColumn('log_time', array(
63
+ 'header' => Mage::helper('easywebshopsms')->__('Log Time'),
64
+ 'align' => 'left',
65
+ 'width' => '120px',
66
+ 'type' => 'datetime',
67
+ 'default' => '--',
68
+ 'index' => 'log_time',
69
+ 'filter_condition_callback' => array($this, 'filterDateCallback')
70
+ ));
71
+
72
+
73
+ $this->addColumn('sms_origin', array(
74
+
75
+ 'header' => Mage::helper('easywebshopsms')->__('SMS Origin'),
76
+ 'align' => 'left',
77
+ 'width' => '80px',
78
+ 'index' => 'sms_origin',
79
+ 'type' => 'varchar',
80
+ 'filter_condition_callback' => array($this, 'filterCallback')
81
+
82
+ ));
83
+ $this->addColumn('mobile_number', array(
84
+
85
+ 'header' => Mage::helper('easywebshopsms')->__('Mobile Number'),
86
+ 'align' => 'left',
87
+ 'width' => '80px',
88
+ 'index' => 'mobile_number',
89
+ 'type' => 'varchar',
90
+ 'filter_condition_callback' => array($this, 'filterCallback')
91
+
92
+ ));
93
+ $this->addColumn('message_text', array(
94
+
95
+ 'header' => Mage::helper('easywebshopsms')->__('Message Text'),
96
+ 'align' => 'left',
97
+ 'index' => 'message_text',
98
+ 'type' => 'varchar',
99
+ 'filter_condition_callback' => array($this, 'filterCallback')
100
+
101
+ ));
102
+
103
+ return parent::_prepareColumns();
104
+ }
105
+
106
+ public function getGridUrl()
107
+ {
108
+ return $this->getUrl('*/*/grid', array('_current'=>true));
109
+ }
110
+
111
+
112
+ /**
113
+ * @param $collection
114
+ * @param $column
115
+ */
116
+ public function filterCallback($collection, $column)
117
+ {
118
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
119
+ $value = $column->getFilter()->getValue();
120
+ if(!empty($value)) {
121
+ $collection->getSelect()->where("$field like ?", '%' . $value . '%');
122
+ }
123
+ }
124
+
125
+ /**
126
+ * @param $collection
127
+ * @param $column
128
+ */
129
+ public function filterEqualCallback($collection, $column)
130
+ {
131
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
132
+ $value = $column->getFilter()->getValue();
133
+ if(!empty($value)) {
134
+ $collection->getSelect()->where("$field = ?", $value);
135
+ }
136
+ }
137
+
138
+ /**
139
+ * @param $collection
140
+ * @param $column
141
+ */
142
+ public function filterDateCallback($collection, $column)
143
+ {
144
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
145
+ $value = $column->getFilter()->getValue();
146
+ if(!empty($value)) {
147
+ $where = "";
148
+ if(!empty($value['from'])){
149
+ $where .= "$field > '" . $value['from']->toString('Y-MM-dd HH:mm:ss') . "'";
150
+ }
151
+ if(!empty($value['to'])){
152
+ if(!empty($where)) {
153
+ $where .= " AND ";
154
+ }
155
+ $where .= "$field < '" . $value['to']->toString('Y-MM-dd HH:mm:ss') . "'";
156
+ }
157
+ $collection->getSelect()->where($where);
158
+ }
159
+ }
160
+
161
+
162
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmssaleabandonedcarts.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmssaleabandonedcarts
5
+ */
6
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmssaleabandonedcarts extends Mage_Adminhtml_Block_Widget_Grid_Container
7
+ {
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct()
12
+ {
13
+ $this->_controller = 'adminhtml_easywebshopsmssaleabandonedcarts';
14
+ $this->_blockGroup = 'easywebshopsms';
15
+ $this->_headerText = Mage::helper('easywebshopsms')->__('Sale Abandoned Carts to ALL');
16
+ parent::__construct();
17
+ $this->_removeButton('add');
18
+ $this->_addButton('notify', array(
19
+ 'label' => Mage::helper('easywebshopsms')->__('Send notifications'),
20
+ 'onclick' => "setLocation('".$this->getUrl('*/*/notifyAll', array('store' => $this->getRequest()->getParam('store', 0)))."')",
21
+ ));
22
+ $this->setTemplate('nthmobile/easywebshopsms/abandonedcarts/list.phtml');
23
+ }
24
+
25
+ /**
26
+ * Prepare the layout
27
+ */
28
+ protected function _prepareLayout()
29
+ {
30
+ // Display store switcher if system has more one store
31
+ if (!Mage::app()->isSingleStoreMode())
32
+ {
33
+ $this->setChild('store_switcher', $this->getLayout()->createBlock('adminhtml/store_switcher')
34
+ ->setUseConfirm(false)
35
+ ->setSwitchUrl($this->getUrl('*/*/*', array('store' => null)))
36
+ );
37
+ }
38
+ return parent::_prepareLayout();
39
+ }
40
+
41
+ /**
42
+ * Getter for the store switcher HTML
43
+ */
44
+ public function getStoreSwitcherHtml()
45
+ {
46
+ return $this->getChildHtml('store_switcher');
47
+ }
48
+
49
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/Easywebshopsmssaleabandonedcarts/Grid.php ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmssaleabandonedcarts_Grid
5
+ */
6
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_Easywebshopsmssaleabandonedcarts_Grid extends Mage_Adminhtml_Block_Widget_Grid
7
+ {
8
+
9
+ /**
10
+ * @return NthMobile_EasyWebShopSMS_Model_Config
11
+ */
12
+ public function getConfig()
13
+ {
14
+ return Mage::getModel('easywebshopsms/config');
15
+ }
16
+
17
+ /**
18
+ *
19
+ */
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+ $this->setId('easywebshopsmssaleabandonedcartsGrid');
24
+ $this->setDefaultSort('cart_updated_at');
25
+ $this->setDefaultDir('DESC');
26
+ $this->setSaveParametersInSession(true);
27
+ $this->setUseAjax(true);
28
+ }
29
+
30
+ /**
31
+ * @return mixed
32
+ */
33
+ protected function _getStore()
34
+ {
35
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
36
+ return Mage::app()->getStore($storeId);
37
+ }
38
+
39
+ protected function _prepareCollection()
40
+ {
41
+ // Default store and website
42
+ $defaults = $this->_getDefaultStoreAndWebsite();
43
+
44
+ // Store and website from the multistore switcher
45
+ $store = $this->_getStore();
46
+ if ($storeId = $store->getId())
47
+ {
48
+ $defaults = array(
49
+ $storeId,
50
+ Mage::getModel('core/store')->load($storeId)->getWebsiteId()
51
+ );
52
+ }
53
+
54
+ $collection = Mage::getModel('NthMobile_EasyWebShopSMS_Model_Abandonedcart_Collection')->getSalesCollection($defaults[0], $defaults[1]);
55
+
56
+ // Group by to have a nice grid
57
+ $collection->getSelect()->group('customer_mobile_number_attribute.value');
58
+
59
+ if (Mage::helper('catalog/product_flat')->isEnabled()) {
60
+ $collection->getSelect()->columns(
61
+ array(
62
+ 'product_ids' => 'GROUP_CONCAT(e.entity_id)',
63
+ 'product_names' => 'GROUP_CONCAT(catalog_flat.name)',
64
+ 'product_prices' => 'SUM(quote_items.price)',
65
+ 'product_special_prices' => 'SUM(IFNULL(catalog_flat.special_price,quote_items.price))',
66
+ )
67
+ );
68
+
69
+ $collection->getSelect()->having("SUM(quote_items.price) < SUM(IFNULL(catalog_flat.special_price,quote_items.price))");
70
+ } else {
71
+ $collection->getSelect()->columns(
72
+ array(
73
+ 'product_ids' => 'GROUP_CONCAT(e.entity_id)',
74
+ 'product_names' => 'GROUP_CONCAT(catalog_name.value)',
75
+ 'product_prices' => 'SUM(quote_items.price)',
76
+ 'product_special_prices' => 'SUM(IFNULL(catalog_sprice.value,quote_items.price))',
77
+ )
78
+ );
79
+
80
+ $collection->getSelect()->having("SUM(quote_items.price) > SUM(IFNULL(catalog_sprice.value,quote_items.price))");
81
+ }
82
+
83
+ $this->setCollection($collection);
84
+ return parent::_prepareCollection();
85
+ }
86
+
87
+ protected function _prepareColumns()
88
+ {
89
+ $this->addColumn('customer_mobile_number', array(
90
+ 'header' => Mage::helper('easywebshopsms')->__('Customer Mobile'),
91
+ 'index' => 'customer_mobile_number',
92
+ 'filter_index' => 'customer_mobile_number_attribute.value',
93
+ 'filter_condition_callback' => array($this, 'filterCallback')
94
+ ));
95
+
96
+ $this->addColumn('customer_firstname', array(
97
+ 'header' => Mage::helper('easywebshopsms')->__('Customer Firstname'),
98
+ 'index' => 'customer_firstname',
99
+ 'filter_condition_callback' => array($this, 'filterCallback')
100
+ ));
101
+
102
+ $this->addColumn('customer_lastname', array(
103
+ 'header' => Mage::helper('easywebshopsms')->__('Customer Lastname'),
104
+ 'index' => 'customer_lastname',
105
+ 'filter_condition_callback' => array($this, 'filterCallback')
106
+ ));
107
+
108
+ $this->addColumn('product_ids', array(
109
+ 'header' => Mage::helper('easywebshopsms')->__('Product Ids'),
110
+ 'index' => 'product_ids',
111
+ 'filter_index' => "e.entity_id",
112
+ 'filter_condition_callback' => array($this, 'filterEqualCallback')
113
+ ));
114
+
115
+ $this->addColumn('product_names', array(
116
+ 'header' => Mage::helper('easywebshopsms')->__('Product Names'),
117
+ 'index' => 'product_names',
118
+ 'filter_index' => (Mage::helper('catalog/product_flat')->isEnabled() ? "catalog_flat.name" : "catalog_name.value"),
119
+ 'filter_condition_callback' => array($this, 'filterEqualCallback')
120
+ ));
121
+
122
+ $this->addColumn('product_prices', array(
123
+ 'header' => Mage::helper('easywebshopsms')->__('Cart Regular Total'),
124
+ 'index' => 'product_prices',
125
+ 'filter' => false,
126
+ 'type' => 'price',
127
+ 'currency_code' => $this->_getStore()->getBaseCurrency()->getCode(),
128
+ ));
129
+
130
+ $this->addColumn('product_special_prices', array(
131
+ 'header' => Mage::helper('easywebshopsms')->__('Cart Sale Total'),
132
+ 'index' => 'product_special_prices',
133
+ 'filter' => false,
134
+ 'type' => 'price',
135
+ 'currency_code' => $this->_getStore()->getBaseCurrency()->getCode(),
136
+ ));
137
+
138
+ // Output format for the start and end dates
139
+ $outputFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
140
+
141
+ $this->addColumn('cart_updated_at', array(
142
+ 'header' => Mage::helper('easywebshopsms')->__('Cart Updated At'),
143
+ 'index' => 'cart_updated_at',
144
+ 'type' => 'datetime',
145
+ 'format' => $outputFormat,
146
+ 'default' => ' -- ',
147
+ 'filter_index' => 'quote_table.updated_at',
148
+ 'filter_condition_callback' => array($this, 'filterDateCallback')
149
+ ));
150
+
151
+ return parent::_prepareColumns();
152
+ }
153
+
154
+ /**
155
+ * @return $this
156
+ */
157
+ protected function _prepareMassaction()
158
+ {
159
+ $this->setMassactionIdField('customer_mobile_number');
160
+ $this->getMassactionBlock()->setFormFieldName('easywebshopsmssalebandonedcarts');
161
+
162
+ $this->getMassactionBlock()->addItem('notify', array(
163
+ 'label' => Mage::helper('easywebshopsms')->__('Send notification'),
164
+ 'url' => $this->getUrl('*/*/notify', array('store' => $this->getRequest()->getParam('store', 0)))
165
+ ));
166
+
167
+ return $this;
168
+ }
169
+
170
+ /**
171
+ * @return array
172
+ */
173
+ protected function _getDefaultStoreAndWebsite()
174
+ {
175
+ foreach (Mage::app()->getWebsites() as $website) {
176
+ // Get the website id
177
+ $websiteId = $website->getWebsiteId();
178
+ foreach ($website->getGroups() as $group) {
179
+ $stores = $group->getStores();
180
+ foreach ($stores as $store) {
181
+
182
+ // Get the store id
183
+ $storeId = $store->getStoreId();
184
+ break 3;
185
+ }
186
+ }
187
+ }
188
+ return array($storeId, $websiteId);
189
+ }
190
+
191
+ /**
192
+ * @return string
193
+ */
194
+ public function getGridUrl()
195
+ {
196
+ return $this->getUrl('*/*/grid', array('current' => true, 'store' => $this->getRequest()->getParam('store', 0)));
197
+ }
198
+
199
+ /**
200
+ * @param $collection
201
+ * @param $column
202
+ */
203
+ public function filterCallback($collection, $column)
204
+ {
205
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
206
+ $value = $column->getFilter()->getValue();
207
+ if(!empty($value)) {
208
+ $collection->getSelect()->where("$field like ?", '%' . $value . '%');
209
+ }
210
+ }
211
+
212
+ /**
213
+ * @param $collection
214
+ * @param $column
215
+ */
216
+ public function filterEqualCallback($collection, $column)
217
+ {
218
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
219
+ $value = $column->getFilter()->getValue();
220
+ if(!empty($value)) {
221
+ $collection->getSelect()->where("$field = ?", $value);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * @param $collection
227
+ * @param $column
228
+ */
229
+ public function filterDateCallback($collection, $column)
230
+ {
231
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
232
+ $value = $column->getFilter()->getValue();
233
+ if(!empty($value)) {
234
+ $where = "";
235
+ if(!empty($value['from'])){
236
+ $where .= "$field > '" . $value['from']->toString('Y-MM-dd HH:mm:ss') . "'";
237
+ }
238
+ if(!empty($value['to'])){
239
+ if(!empty($where)) {
240
+ $where .= " AND ";
241
+ }
242
+ $where .= "$field < '" . $value['to']->toString('Y-MM-dd HH:mm:ss') . "'";
243
+ }
244
+ $collection->getSelect()->where($where);
245
+ }
246
+ }
247
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/System/Config/Log/Log.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
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/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Renderer for sub-heading in fieldset
30
+ *
31
+ * @author Magento Core Team <core@magentocommerce.com>
32
+ */
33
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_System_Config_Log_Log
34
+ extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
35
+ {
36
+
37
+ /**
38
+ * @var string
39
+ */
40
+ protected $_template = 'nthmobile/easywebshopsms/system/config/log/log.phtml';
41
+
42
+
43
+ /**
44
+ * Render element html
45
+ *
46
+ * @param Varien_Data_Form_Element_Abstract $element
47
+ * @return string
48
+ */
49
+ public function render(Varien_Data_Form_Element_Abstract $element)
50
+ {
51
+ return $this->toHtml();
52
+ }
53
+
54
+ public function getLogFile()
55
+ {
56
+ return Mage::helper('easywebshopsms')->getLogFile();
57
+ }
58
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/System/Config/Log/Reset.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
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/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_System_Config_Log_Reset extends Mage_Adminhtml_Block_System_Config_Form_Field
28
+ {
29
+
30
+ protected $_template = 'nthmobile/easywebshopsms/system/config/log/reset.phtml';
31
+
32
+ /**
33
+ * Return element html
34
+ *
35
+ * @param Varien_Data_Form_Element_Abstract $element
36
+ * @return string
37
+ */
38
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
39
+ {
40
+ return $this->_toHtml();
41
+ }
42
+
43
+ /**
44
+ * Return ajax url for button
45
+ *
46
+ * @return string
47
+ */
48
+ public function getAjaxCheckUrl()
49
+ {
50
+ return Mage::helper('adminhtml')->getUrl('easywebshopsms/adminhtml_easywebshopsmslogs/resetLogFile');
51
+ }
52
+
53
+
54
+ /**
55
+ * Generate button html
56
+ *
57
+ * @return string
58
+ */
59
+ public function getButtonHtml()
60
+ {
61
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
62
+ ->setData(array(
63
+ 'id' => 'easywebshopsms_button',
64
+ 'label' => $this->helper('adminhtml')->__('Reset LOG'),
65
+ 'onclick' => 'javascript:resetLogFile(); return false;'
66
+ ));
67
+
68
+ return $button->toHtml();
69
+ }
70
+
71
+ }
app/code/community/NthMobile/EasyWebShopSMS/Block/Adminhtml/System/Config/Section/Details.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class NthMobile_EasyWebShopSMS_Block_Adminhtml_System_Config_Section_Details
5
+ extends Mage_Adminhtml_Block_Abstract
6
+ implements Varien_Data_Form_Element_Renderer_Interface
7
+ {
8
+ /**
9
+ * @var string
10
+ */
11
+ protected $_template = 'nthmobile/easywebshopsms/system/config/section/details.phtml';
12
+
13
+ /**
14
+ * @return string
15
+ */
16
+ public function getSupportLink()
17
+ {
18
+ return 'http://easyshopsms.nthmobile.com';
19
+ }
20
+
21
+ public function getSignUpUrl()
22
+ {
23
+ return 'http://easyshopsms.nthmobile.com';
24
+ }
25
+
26
+ /**
27
+ * Checks if the account details have not been filled in
28
+ *
29
+ * @return bool
30
+ */
31
+ public function accountDetailsNotFilledIn()
32
+ {
33
+ return (empty(Mage::getStoreConfig('easywebshopsms/api_connection/api_host'))
34
+ || empty(Mage::getStoreConfig('easywebshopsms/api_connection/api_user'))
35
+ || empty(Mage::getStoreConfig('easywebshopsms/api_connection/api_pass'))
36
+ || empty(Mage::getStoreConfig('easywebshopsms/api_connection/api_port'))
37
+ );
38
+ }
39
+
40
+ /**
41
+ * @param Varien_Data_Form_Element_Abstract $element
42
+ *
43
+ * @return string
44
+ */
45
+ public function render(Varien_Data_Form_Element_Abstract $element)
46
+ {
47
+ return $this->toHtml();
48
+ }
49
+
50
+ }
app/code/community/NthMobile/EasyWebShopSMS/Helper/Data.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NthMobile_EasyWebShopSMS_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ protected $logFileName = 'easywebshopsms.log';
7
+
8
+ /**
9
+ * Log data
10
+ * @param string|object|array data to log
11
+ */
12
+ public function log($text, $contextData = array())
13
+ {
14
+ if(!is_null($contextData) && is_array($contextData)) {
15
+ $text .= "__CTX__".json_encode($contextData);
16
+ }
17
+ $text .= "__EOL__";
18
+ Mage::log($text, null, $this->logFileName, true);
19
+ }
20
+
21
+ public function getLogFile()
22
+ {
23
+ $logDir = Mage::getBaseDir('var') . DS . 'log';
24
+ $logFile = $logDir . DS . $this->logFileName;
25
+ return $logFile;
26
+ }
27
+
28
+ public function registerEvent($data, $text)
29
+ {
30
+
31
+ $origin = Mage::getModel('easywebshopsms/config')->getSmsOrigin();
32
+
33
+ $client = Mage::getModel('easywebshopsms/bulkclient')->getClient();
34
+ $customer = Mage::getSingleton('customer/session');
35
+ $customer_id = array_get($data,'customer_id', array_get($data,'data.customer_id', null));
36
+
37
+ if ($customer_id == null && $customer->isLoggedIn()) {
38
+ $customer_id = $customer->getId();
39
+ }
40
+
41
+ if($customer_id != null) {
42
+ $customerData = Mage::getModel('customer/customer')->load($customer_id); //->getData(); //@XXX use getData to get Array of data
43
+
44
+ $msisdn = $customerData->getMobileNumber();
45
+
46
+ $text = $this->prepareMessage($text, $data);
47
+ $logData = [
48
+ 'customer_id' => $customerData->getId(),
49
+ 'event_name' => $data['event'],
50
+ 'sms_origin' => $origin,
51
+ 'mobile_number' => $msisdn,
52
+ 'message_text' => $text,
53
+ 'time' => time()
54
+ ];
55
+ $this->log("[SMS] From: $origin, To: $msisdn :: $text" , $logData);
56
+
57
+ if(Mage::getModel('easywebshopsms/config')->getDryRun()) {
58
+ return true;
59
+ }
60
+ if(empty($msisdn)) {
61
+ return false;
62
+ }
63
+ $response = $client->textMessage()->send($origin, $msisdn, $text, [
64
+ // Handle notification with this URL. Notification is POST request
65
+ 'status_url' => Mage::app()->getStore()->getUrl('/easywebshopsms/api/handleBulkSmsNotification')
66
+ ]);
67
+
68
+ if ($response->isOk()) {
69
+
70
+ $textMessage = $response->resource();
71
+
72
+ $inputData = [
73
+ 'customer_id' => $customerData->getId(),
74
+ 'event_name' => $data['event'],
75
+ 'log_time' => Mage::getModel('core/date')->date('Y-m-d H:i:s'),
76
+ 'sms_origin' => $origin,
77
+ 'mobile_number' => $msisdn,
78
+ 'message_text' => $text,
79
+ 'sms_status_code'=> $textMessage->smsId()
80
+ ];
81
+
82
+ /*
83
+ *sms_sent = integer (0 || 1)
84
+ * sms_status_code = integer(Gatewway status code)
85
+ * sms_status_message = string (200)
86
+ * */
87
+
88
+ Mage::getModel('easywebshopsms/easywebshopsms')
89
+ ->setData($inputData)
90
+ ->save();
91
+
92
+ return true;
93
+ } else {
94
+ $error = $response->error();
95
+
96
+ /*$message = $error->message;
97
+ $code = $error->code;*/
98
+ }
99
+ }
100
+ return false;
101
+ }
102
+
103
+ public function getOrderData($order)
104
+ {
105
+ //getting last tracking number
106
+ $tracking = Mage::getResourceModel('sales/order_shipment_track_collection')->setOrderFilter($order)->getData();
107
+
108
+ if (!empty($tracking)) {
109
+ $last = count($tracking)-1;
110
+ $last_tracking_number = $tracking[$last]['track_number'];
111
+ } else
112
+ $last_tracking_number = 'no_tracking';
113
+
114
+ //getting order data to generate message template
115
+ $messageOrderData['order']['number'] = $order->getIncrement_id();
116
+ $messageOrderData['order']['status'] = $order->getOrigData('status');
117
+ $messageOrderData['order']['status_new'] = $order->getData('status');
118
+ $messageOrderData['tracking']['number'] = $last_tracking_number;
119
+ $messageOrderData['storename'] = Mage::getModel('easywebshopsms/config')->getStoreName();
120
+ $messageOrderData['customer_id'] = $order->getCustomerId();
121
+
122
+ return $messageOrderData;
123
+ }
124
+
125
+ public function prepareMessage($text, $data)
126
+ {
127
+ $newText = $this->sprintargs($text,$this->array_flatten($data));
128
+ return $newText;
129
+ }
130
+
131
+ public function prepareEventData($eventName, $data)
132
+ {
133
+ $customer = Mage::getSingleton('customer/session');
134
+ $customerData = [];
135
+ if ($customer->isLoggedIn()) {
136
+ $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData();
137
+ }
138
+
139
+ $prepared = [
140
+ 'event' => $eventName,
141
+ 'customer' => $customerData,
142
+ 'data' => $data
143
+ ];
144
+
145
+ return $prepared;
146
+ }
147
+
148
+ public function sprintargs($str = '', $vars = [], $charStart = '{', $charEnd = '}')
149
+ {
150
+ if (!$str) {
151
+ return '';
152
+ }
153
+ if (count($vars) > 0) {
154
+ foreach ($vars as $k => $v) {
155
+ $str = str_replace($charStart . $k . $charEnd, $v, $str);
156
+ }
157
+ }
158
+ return $str;
159
+ }
160
+
161
+ public function array_flatten($array, $prefix = '')
162
+ {
163
+ $result = [];
164
+ if (is_null($array)) {
165
+ return $result;
166
+ }
167
+ if (is_object($array)) {
168
+ $array = json_decode(json_encode($array), true);
169
+ }
170
+ if (!is_array($array)) {
171
+ return $result;
172
+ }
173
+ foreach ($array as $key => $value) {
174
+ if (!is_scalar($value) && !is_null($value)) {
175
+ $result = array_merge($result, $this->array_flatten($value, "$prefix$key."));
176
+ } else {
177
+ $result["$prefix$key"] = (is_null($value)) ? "" : $value;
178
+ }
179
+ }
180
+
181
+ return $result;
182
+ }
183
+
184
+ }
185
+
app/code/community/NthMobile/EasyWebShopSMS/Model/Abandonedcart/Collection.php ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class NthMobile_EasyWebShopSMS_Model_Abandonedcart_Collection
5
+ */
6
+ class NthMobile_EasyWebShopSMS_Model_Abandonedcart_Collection {
7
+
8
+ /**
9
+ * @param $delay
10
+ * @param $storeId
11
+ * @param $websiteId
12
+ * @param $mobiles
13
+ * @return mixed
14
+ */
15
+ public function getCollection($delay, $storeId, $websiteId, $mobiles = array())
16
+ {
17
+ // Get the product collection
18
+ $collection = Mage::getResourceModel('catalog/product_collection')->setStore($storeId);
19
+
20
+ // Get the attribute id for the status attribute
21
+ $eavAttribute = Mage::getModel('eav/entity_attribute');
22
+ $statusId = $eavAttribute->getIdByCode('catalog_product', 'status');
23
+ $nameId = $eavAttribute->getIdByCode('catalog_product', 'name');
24
+ $priceId = $eavAttribute->getIdByCode('catalog_product', 'price');
25
+ $mobileNumberEav = Mage::getModel('eav/config')->getAttribute('customer', 'mobile_number');
26
+
27
+ $mobileNumberEavId = $mobileNumberEav->getId();
28
+ // Normal join condition
29
+ $mobilesJoin = sprintf('customer_mobile_number_attribute.value IS NOT NULL AND customer_mobile_number_attribute.attribute_id = "%s" AND customer_mobile_number_attribute.entity_type_id = %s', $mobileNumberEavId, 1);
30
+ $quoteJoin = sprintf('quote_items.quote_id = quote_table.entity_id AND quote_table.items_count > 0 AND quote_table.is_active = 1 AND quote_table.easywebshopsms_abandoned_notified = 0 AND quote_table.updated_at < "%s" AND quote_table.store_id = %s', $delay, $storeId);
31
+
32
+ // In case an array of emails has been specified
33
+ if (!empty($mobiles)) {
34
+ $mobilesJoin = sprintf('%s AND customer_mobile_number_attribute.value IN (%s)', $mobilesJoin, '"' . implode('", "', $mobiles) . '"');
35
+ }
36
+
37
+ // If flat catalog is enabled
38
+ if (Mage::helper('catalog/product_flat')->isEnabled())
39
+ {
40
+ // First collection: carts with products that became on sale
41
+ // Join the collection with the required tables
42
+ $collection->getSelect()
43
+ ->reset(Zend_Db_Select::COLUMNS)
44
+ ->columns(array('e.entity_id AS product_id',
45
+ 'e.sku',
46
+ 'catalog_flat.name as product_name',
47
+ 'catalog_flat.price as product_price',
48
+ 'quote_table.entity_id as cart_id',
49
+ 'quote_table.updated_at as cart_updated_at',
50
+ 'quote_table.easywebshopsms_abandoned_notified as has_been_notified',
51
+ 'customer_mobile_number_attribute.value as customer_mobile_number',
52
+ 'quote_table.customer_firstname as customer_firstname',
53
+ 'quote_table.customer_lastname as customer_lastname',
54
+ 'customer.group_id as customer_group',
55
+ 'customer.entity_id as customer_id'
56
+ )
57
+ )
58
+ ->joinInner(
59
+ array('quote_items' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote_item')),
60
+ 'quote_items.product_id = e.entity_id AND quote_items.price > 0.00',
61
+ null)
62
+ ->joinInner(
63
+ array('catalog_flat' => Mage::getSingleton("core/resource")->getTableName('catalog_product_flat_'.$storeId)),
64
+ 'catalog_flat.entity_id = e.entity_id',
65
+ null)
66
+ ->joinInner(
67
+ array('catalog_enabled' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_int')),
68
+ 'catalog_enabled.entity_id = e.entity_id AND catalog_enabled.attribute_id = '.$statusId.' AND catalog_enabled.value = 1',
69
+ null)
70
+ ->joinInner(
71
+ array('inventory' => Mage::getSingleton("core/resource")->getTableName('cataloginventory_stock_status')),
72
+ 'inventory.product_id = e.entity_id AND inventory.stock_status = 1 AND website_id = '.$websiteId,
73
+ null)
74
+ ->joinInner(
75
+ array('quote_table' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote')),
76
+ $quoteJoin,
77
+ null)
78
+ ->joinInner(
79
+ array('customer' => Mage::getSingleton("core/resource")->getTableName('customer_entity')),
80
+ 'quote_table.customer_id = customer.entity_id',
81
+ null)
82
+ ->joinInner(
83
+ array('customer_mobile_number_attribute' => $mobileNumberEav->getBackendTable()),
84
+ 'customer.entity_id = customer_mobile_number_attribute.entity_id',
85
+ null)
86
+ ->where($mobilesJoin)
87
+ ->order('quote_table.updated_at DESC');
88
+ }
89
+ else
90
+ {
91
+ // First collection: carts with products that became on sale
92
+ // Join the collection with the required tables
93
+ $collection->getSelect()
94
+ ->reset(Zend_Db_Select::COLUMNS)
95
+ ->columns(array('e.entity_id AS product_id',
96
+ 'e.sku',
97
+ 'catalog_name.value as product_name',
98
+ 'catalog_price.value as product_price',
99
+ 'quote_table.entity_id as cart_id',
100
+ 'quote_table.updated_at as cart_updated_at',
101
+ 'quote_table.easywebshopsms_abandoned_notified as has_been_notified',
102
+ 'customer_mobile_number_attribute.value as customer_mobile_number',
103
+ 'quote_table.customer_firstname as customer_firstname',
104
+ 'quote_table.customer_lastname as customer_lastname',
105
+ 'customer.group_id as customer_group',
106
+ 'customer.entity_id as customer_id'
107
+ )
108
+ )
109
+ // Name
110
+ ->joinInner(
111
+ array('catalog_name' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_varchar')),
112
+ "catalog_name.entity_id = e.entity_id AND catalog_name.attribute_id = $nameId",
113
+ null)
114
+ // Price
115
+ ->joinInner(
116
+ array('catalog_price' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_decimal')),
117
+ "catalog_price.entity_id = e.entity_id AND catalog_price.attribute_id = $priceId",
118
+ null)
119
+ ->joinInner(
120
+ array('quote_items' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote_item')),
121
+ 'quote_items.product_id = e.entity_id AND quote_items.price > 0.00',
122
+ null)
123
+ ->joinInner(
124
+ array('quote_table' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote')),
125
+ $quoteJoin,
126
+ null)
127
+ ->joinInner(
128
+ array('catalog_enabled' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_int')),
129
+ 'catalog_enabled.entity_id = e.entity_id AND catalog_enabled.attribute_id = '.$statusId.' AND catalog_enabled.value = 1',
130
+ null)
131
+ ->joinInner(
132
+ array('inventory' => Mage::getSingleton("core/resource")->getTableName('cataloginventory_stock_status')),
133
+ 'inventory.product_id = e.entity_id AND inventory.stock_status = 1 AND website_id = '.$websiteId,
134
+ null)
135
+ ->joinInner(
136
+ array('customer' => Mage::getSingleton("core/resource")->getTableName('customer_entity')),
137
+ 'quote_table.customer_id = customer.entity_id',
138
+ null)
139
+ ->joinInner(
140
+ array('customer_mobile_number_attribute' => $mobileNumberEav->getBackendTable()),
141
+ 'customer.entity_id = customer_mobile_number_attribute.entity_id',
142
+ null)
143
+ ->where($mobilesJoin)
144
+ ->order('quote_table.updated_at DESC');
145
+ }
146
+
147
+ return $collection;
148
+ }
149
+
150
+ public function getSalesCollection($storeId, $websiteId, $mobiles = array())
151
+ {
152
+ // Get the product collection
153
+ $collection = Mage::getResourceModel('catalog/product_collection')->setStore($storeId);
154
+
155
+ // Get the attribute id for the status attribute
156
+ $eavAttribute = Mage::getModel('eav/entity_attribute');
157
+ $statusId = $eavAttribute->getIdByCode('catalog_product', 'status');
158
+ $nameId = $eavAttribute->getIdByCode('catalog_product', 'name');
159
+ $priceId = $eavAttribute->getIdByCode('catalog_product', 'price');
160
+ $spriceId = $eavAttribute->getIdByCode('catalog_product', 'special_price');
161
+ $spfromId = $eavAttribute->getIdByCode('catalog_product', 'special_from_date');
162
+ $sptoId = $eavAttribute->getIdByCode('catalog_product', 'special_to_date');
163
+
164
+ $mobileNumberEav = Mage::getModel('eav/config')->getAttribute('customer', 'mobile_number');
165
+
166
+ $mobileNumberEavId = $mobileNumberEav->getId();
167
+ // Normal join condition
168
+ $mobilesJoin = sprintf('customer_mobile_number_attribute.value IS NOT NULL AND customer_mobile_number_attribute.attribute_id = %s AND customer_mobile_number_attribute.entity_type_id = %s', $mobileNumberEavId, 1);
169
+
170
+ // Normal join condition
171
+ $quoteJoin = sprintf('quote_items.quote_id = quote_table.entity_id AND quote_table.items_count > 0 AND quote_table.is_active = 1 AND quote_table.easywebshopsms_abandoned_sale_notified = 0 AND quote_table.store_id = %s', $storeId);
172
+
173
+ // In case an array of emails has been specified
174
+ if (!empty($mobiles)) {
175
+ $mobilesJoin = sprintf('%s AND customer_mobile_number_attribute.value IN (%s)', $mobilesJoin, '"' . implode('", "', $mobiles) . '"');
176
+ }
177
+
178
+ // If flat catalog is enabled
179
+ if (Mage::helper('catalog/product_flat')->isEnabled())
180
+ {
181
+ // First collection: carts with products that became on sale
182
+ // Join the collection with the required tables
183
+ $collection->getSelect()
184
+ ->reset(Zend_Db_Select::COLUMNS)
185
+ ->columns(array('e.entity_id AS product_id',
186
+ 'e.sku',
187
+ 'catalog_flat.name as product_name',
188
+ 'catalog_flat.price as product_price',
189
+ 'catalog_flat.special_price as product_special_price',
190
+ 'catalog_flat.special_from_date as product_special_from_date',
191
+ 'catalog_flat.special_to_date as product_special_to_date',
192
+ 'quote_table.entity_id as cart_id',
193
+ 'quote_table.updated_at as cart_updated_at',
194
+ 'quote_table.easywebshopsms_abandoned_sale_notified as has_been_notified',
195
+ 'quote_items.price as product_price_in_cart',
196
+ 'customer_mobile_number_attribute.value as customer_mobile_number',
197
+ 'quote_table.customer_firstname as customer_firstname',
198
+ 'quote_table.customer_lastname as customer_lastname',
199
+ 'customer.group_id as customer_group',
200
+ 'customer.entity_id as customer_id'
201
+ )
202
+ )
203
+ ->joinInner(
204
+ array('quote_items' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote_item')),
205
+ 'quote_items.product_id = e.entity_id AND quote_items.price > 0.00',
206
+ null)
207
+ ->joinInner(
208
+ array('quote_table' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote')),
209
+ $quoteJoin,
210
+ null)
211
+ ->joinInner(
212
+ array('catalog_flat' => Mage::getSingleton("core/resource")->getTableName('catalog_product_flat_'.$storeId)),
213
+ 'catalog_flat.entity_id = e.entity_id',
214
+ null)
215
+ ->joinInner(
216
+ array('catalog_enabled' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_int')),
217
+ 'catalog_enabled.entity_id = e.entity_id AND catalog_enabled.attribute_id = '.$statusId.' AND catalog_enabled.value = 1',
218
+ null)
219
+ ->joinInner(
220
+ array('inventory' => Mage::getSingleton("core/resource")->getTableName('cataloginventory_stock_status')),
221
+ 'inventory.product_id = e.entity_id AND inventory.stock_status = 1 AND inventory.website_id = '.$websiteId,
222
+ null)
223
+ ->joinInner(
224
+ array('customer' => Mage::getSingleton("core/resource")->getTableName('customer_entity')),
225
+ 'quote_table.customer_id = customer.entity_id',
226
+ null)
227
+ ->joinInner(
228
+ array('customer_mobile_number_attribute' => $mobileNumberEav->getBackendTable()),
229
+ 'customer.entity_id = customer_mobile_number_attribute.entity_id',
230
+ null)
231
+ ->where($mobilesJoin)
232
+ ->order('quote_table.updated_at DESC');
233
+ }
234
+ else
235
+ {
236
+ // First collection: carts with products that became on sale
237
+ // Join the collection with the required tables
238
+ $collection->getSelect()
239
+ ->reset(Zend_Db_Select::COLUMNS)
240
+ ->columns(array('e.entity_id AS product_id',
241
+ 'e.sku',
242
+ 'catalog_name.value as product_name',
243
+ 'catalog_price.value as product_price',
244
+ 'catalog_sprice.value as product_special_price',
245
+ 'catalog_spfrom.value as product_special_from_date',
246
+ 'catalog_spto.value as product_special_to_date',
247
+ 'quote_table.entity_id as cart_id',
248
+ 'quote_table.updated_at as cart_updated_at',
249
+ 'quote_table.easywebshopsms_abandoned_sale_notified as has_been_notified',
250
+ 'quote_items.price as product_price_in_cart',
251
+ 'customer_mobile_number_attribute.value as customer_mobile_number',
252
+ 'quote_table.customer_firstname as customer_firstname',
253
+ 'quote_table.customer_lastname as customer_lastname',
254
+ 'customer.group_id as customer_group',
255
+ 'customer.entity_id as customer_id'
256
+ )
257
+ )
258
+ // Name
259
+ ->joinInner(
260
+ array('catalog_name' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_varchar')),
261
+ "catalog_name.entity_id = e.entity_id AND catalog_name.attribute_id = $nameId",
262
+ null)
263
+ // Price
264
+ ->joinInner(
265
+ array('catalog_price' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_decimal')),
266
+ "catalog_price.entity_id = e.entity_id AND catalog_price.attribute_id = $priceId",
267
+ null)
268
+ // Special Price
269
+ ->joinInner(
270
+ array('catalog_sprice' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_decimal')),
271
+ "catalog_sprice.entity_id = e.entity_id AND catalog_sprice.attribute_id = $spriceId",
272
+ null)
273
+ // Special From Date
274
+ ->joinInner(
275
+ array('catalog_spfrom' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_datetime')),
276
+ "catalog_spfrom.entity_id = e.entity_id AND catalog_spfrom.attribute_id = $spfromId",
277
+ null)
278
+ // Special To Date
279
+ ->joinInner(
280
+ array('catalog_spto' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_datetime')),
281
+ "catalog_spto.entity_id = e.entity_id AND catalog_spto.attribute_id = $sptoId",
282
+ null)
283
+ ->joinInner(
284
+ array('quote_items' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote_item')),
285
+ 'quote_items.product_id = e.entity_id AND quote_items.price > 0.00',
286
+ null)
287
+ ->joinInner(
288
+ array('quote_table' => Mage::getSingleton("core/resource")->getTableName('sales_flat_quote')),
289
+ $quoteJoin,
290
+ null)
291
+ ->joinInner(
292
+ array('catalog_enabled' => Mage::getSingleton("core/resource")->getTableName('catalog_product_entity_int')),
293
+ 'catalog_enabled.entity_id = e.entity_id AND catalog_enabled.attribute_id = '.$statusId.' AND catalog_enabled.value = 1',
294
+ null)
295
+ ->joinInner(
296
+ array('inventory' => Mage::getSingleton("core/resource")->getTableName('cataloginventory_stock_status')),
297
+ 'inventory.product_id = e.entity_id AND inventory.stock_status = 1 AND inventory.website_id = '.$websiteId,
298
+ null)
299
+ ->joinInner(
300
+ array('customer' => Mage::getSingleton("core/resource")->getTableName('customer_entity')),
301
+ 'quote_table.customer_id = customer.entity_id',
302
+ null)
303
+ ->joinInner(
304
+ array('customer_mobile_number_attribute' => $mobileNumberEav->getBackendTable()),
305
+ 'customer.entity_id = customer_mobile_number_attribute.entity_id',
306
+ null)
307
+ ->where($mobilesJoin)
308
+ ->order('quote_table.updated_at DESC');
309
+ }
310
+
311
+ return $collection;
312
+ }
313
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Bulkclient.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NthMobile_EasyWebShopSMS_Model_Bulkclient
4
+ {
5
+ private $client;
6
+
7
+ public function __construct()
8
+ {
9
+ $this->client = new \Samurai\BulkSms\BulkSms(
10
+ Mage::getStoreConfig('easywebshopsms/api_connection/api_uri'),
11
+ Mage::getStoreConfig('easywebshopsms/api_connection/api_user'),
12
+ Mage::getStoreConfig('easywebshopsms/api_connection/api_pass'),
13
+ Mage::getStoreConfig('easywebshopsms/api_connection/api_port'),
14
+ '',
15
+ [
16
+ 'timeout' => 10
17
+ ]
18
+ );
19
+
20
+ $this->client->setLogger(NthMobile_EasyWebShopSMS_Model_Logger_Factory::getInstance());
21
+
22
+ return $this;
23
+ }
24
+
25
+ /**
26
+ * @return \Samurai\BulkSms\BulkSms
27
+ */
28
+ public function getClient()
29
+ {
30
+ return $this->client;
31
+ }
32
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Config.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class NthMobile_EasyWebShopSMS_Model_Config
5
+ {
6
+
7
+ public function getStoreName()
8
+ {
9
+ return Mage::getStoreConfig('easywebshopsms/api_connection/storename');
10
+ }
11
+
12
+ public function getSmsOrigin()
13
+ {
14
+ return Mage::getStoreConfig('easywebshopsms/api_connection/sms_origin');
15
+ }
16
+
17
+ public function getNotifDelay()
18
+ {
19
+ $delay = Mage::getStoreConfig('easywebshopsms/abandoned_notifications/notify_delay');
20
+ return date('Y-m-d H:i:s', time() - $delay * 24 * 3600);
21
+ }
22
+
23
+ /**
24
+ * @return mixed
25
+ */
26
+ public function getCustomerGroupsLimitation()
27
+ {
28
+ return explode(',',Mage::getStoreConfig('easywebshopsms/abandoned_notifications/customer_groups'));
29
+ }
30
+
31
+ /**
32
+ * checks if EasyWebShopSMS API module is enabled
33
+ * @return boolean
34
+ */
35
+ public function isApiEnabled()
36
+ {
37
+ return (Mage::getStoreConfig('easywebshopsms/api_connection/active')==0) ? false : true;
38
+ }
39
+
40
+ public function isEventActive($eventConfig, $configGroup = "message_configuration")
41
+ {
42
+ $configGroup = $this->_resolveConfigGroup($configGroup);
43
+
44
+ return (Mage::getStoreConfig('easywebshopsms/'.$configGroup.$eventConfig)==0) ? false : true;
45
+ }
46
+
47
+ public function getDryRun()
48
+ {
49
+ return (Mage::getStoreConfig('easywebshopsms/api_connection/dry_run')==1);
50
+ }
51
+
52
+ /**
53
+ * getting SMS templates from config
54
+ * @return string
55
+ */
56
+ public function getEventMessageTemplate($eventConfig, $configGroup = "message_configuration")
57
+ {
58
+
59
+ $configGroup = $this->_resolveConfigGroup($configGroup);
60
+ if($this->isApiEnabled() && $this->isEventActive($eventConfig, $configGroup)) {
61
+ return Mage::getStoreConfig('easywebshopsms/'.$configGroup.$eventConfig.'_text_message');
62
+ }
63
+ return "";
64
+ }
65
+
66
+ private function _resolveConfigGroup($group)
67
+ {
68
+ if(empty($group)) {
69
+ return "";
70
+ }
71
+ $group = trim($group, "\\ /");
72
+ return $group."/";
73
+ }
74
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Easywebshopsms.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 30.5.2016.
6
+ * Time: 14:37
7
+ */
8
+ class NthMobile_EasyWebShopSMS_Model_Easywebshopsms extends Mage_Core_Model_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('easywebshopsms/easywebshopsms');
14
+ }
15
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Logger/Factory.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Psr\Log\LoggerInterface;
4
+
5
+
6
+ class NthMobile_EasyWebShopSMS_Model_Logger_Factory
7
+ {
8
+ /**
9
+ * Esendex Log File
10
+ */
11
+ const LOG_FILE = 'nthmobile_easywebshopsms.log';
12
+
13
+ /**
14
+ * @var LoggerInterface
15
+ */
16
+ static $logger;
17
+
18
+ /**
19
+ * @return NthMobile_EasyWebShopSMS_Model_Logger_Logger
20
+ */
21
+ public static function getInstance()
22
+ {
23
+ if (static::$logger) {
24
+ return static::$logger;
25
+ }
26
+
27
+ $file = sprintf('%s/%s', Mage::getBaseDir('log'), static::LOG_FILE);
28
+ $logger = new Zend_Log(new Zend_Log_Writer_Stream($file));
29
+
30
+ if (!Mage::getStoreConfig('easywebshopsms/api_connection/debug_mode')) {
31
+ $logger->addFilter(new Zend_Log_Filter_Priority(Zend_Log::CRIT));
32
+ }
33
+
34
+ static::$logger = new NthMobile_EasyWebShopSMS_Model_Logger_Logger($logger);
35
+ return static::$logger;
36
+ }
37
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Logger/Logger.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Psr\Log\AbstractLogger;
4
+ use Psr\Log\LogLevel;
5
+
6
+
7
+ class NthMobile_EasyWebShopSMS_Model_Logger_Logger extends AbstractLogger
8
+ {
9
+
10
+ /**
11
+ * Map PSR Log Level to Zend Log Level
12
+ *
13
+ * @var array
14
+ */
15
+ private $logMap = [
16
+ LogLevel::ALERT => Zend_Log::ALERT,
17
+ LogLevel::CRITICAL => Zend_Log::CRIT,
18
+ LogLevel::DEBUG => Zend_Log::DEBUG,
19
+ LogLevel::EMERGENCY => Zend_Log::EMERG,
20
+ LogLevel::ERROR => Zend_Log::ERR,
21
+ LogLevel::INFO => Zend_Log::INFO,
22
+ LogLevel::NOTICE => Zend_Log::NOTICE,
23
+ LogLevel::WARNING => Zend_Log::WARN,
24
+ ];
25
+
26
+ /**
27
+ * @var Zend_Log
28
+ */
29
+ private $logger;
30
+
31
+ /**
32
+ * @param Zend_Log $logger
33
+ */
34
+ public function __construct(Zend_Log $logger)
35
+ {
36
+ $this->logger = $logger;
37
+ }
38
+
39
+ /**
40
+ * Logs with an arbitrary level.
41
+ *
42
+ * @param int $level
43
+ * @param string $message
44
+ * @param array $context
45
+ *
46
+ * @return null
47
+ */
48
+ public function log($level, $message, array $context = [])
49
+ {
50
+ if (!isset($this->logMap[$level])) {
51
+ throw new \InvalidArgumentExcepton('Level is not supported. See "iPsr\Log\LogLevel"');
52
+ }
53
+
54
+ $zendLogLevel = $this->logMap[$level];
55
+
56
+ //Proxy log
57
+ $this->logger->log($message, $zendLogLevel);
58
+ }
59
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Notifier.php ADDED
@@ -0,0 +1,481 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class NthMobile_EasyWebShopSMS_Model_Notifier
5
+ */
6
+ class NthMobile_EasyWebShopSMS_Model_Notifier extends Mage_Core_Model_Abstract
7
+ {
8
+ /**
9
+ * @var array
10
+ */
11
+ protected $_recipients = array();
12
+
13
+ /**
14
+ * @var array
15
+ */
16
+ protected $_saleRecipients = array();
17
+
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_today = "";
22
+
23
+ /**
24
+ * @var array
25
+ */
26
+ protected $_customerGroups = array();
27
+
28
+ /**
29
+ * @var
30
+ */
31
+ protected $_currentStoreId;
32
+
33
+ /**
34
+ * @var
35
+ */
36
+ protected $_originalStoreId;
37
+
38
+ /**
39
+ * @throws Zend_Date_Exception
40
+ */
41
+ protected function _setToday()
42
+ {
43
+ // Date handling
44
+ $store = Mage_Core_Model_App::ADMIN_STORE_ID;
45
+ $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
46
+ date_default_timezone_set($timezone);
47
+
48
+ // Current date
49
+ $currentdate = date("Ymd");
50
+
51
+ $day = (int)substr($currentdate,-2);
52
+ $month = (int)substr($currentdate,4,2);
53
+ $year = (int)substr($currentdate,0,4);
54
+
55
+ $date = array(
56
+ 'year' => $year,
57
+ 'month' => $month,
58
+ 'day' => $day,
59
+ 'hour' => 23,
60
+ 'minute' => 59,
61
+ 'second' => 59
62
+ );
63
+
64
+ $today = new Zend_Date($date);
65
+ $today->setTimeZone("UTC");
66
+
67
+ date_default_timezone_set($timezone);
68
+
69
+ $this->_today = $today->toString("Y-MM-dd HH:mm:ss");
70
+ }
71
+
72
+ /**
73
+ * @return string
74
+ */
75
+ protected function _getToday()
76
+ {
77
+ return $this->_today;
78
+ }
79
+
80
+ /**
81
+ * @return array
82
+ */
83
+ protected function _getRecipients()
84
+ {
85
+ return $this->_recipients;
86
+ }
87
+
88
+ /**
89
+ * @return array
90
+ */
91
+ protected function _getSaleRecipients()
92
+ {
93
+ return $this->_saleRecipients;
94
+ }
95
+
96
+ /**
97
+ * @return NthMobile_EasyWebShopSMS_Model_Config
98
+ */
99
+ public function getConfig()
100
+ {
101
+ return Mage::getModel('easywebshopsms/config');
102
+ }
103
+
104
+ /**
105
+ * @return NthMobile_EasyWebShopSMS_Helper_Data
106
+ */
107
+ public function getHelper()
108
+ {
109
+ return Mage::helper('easywebshopsms');
110
+ }
111
+
112
+ /**
113
+ * @param $args
114
+ */
115
+ public function generateRecipients($args)
116
+ {
117
+ // Customer group check
118
+ if (array_key_exists('customer_group',$args['row'])
119
+ && !in_array($args['row']['customer_group'],$this->_customerGroups)) {
120
+ return;
121
+ }
122
+
123
+ // Test if the customer is already in the array
124
+ if (!array_key_exists($args['row']['customer_mobile_number'], $this->_recipients)) {
125
+
126
+ // Create an array of variables to assign to template
127
+ $smsDetails = array();
128
+
129
+ // Array that contains the data which will be used inside the template
130
+ $smsDetails['fullname'] = $args['row']['customer_firstname'].' '.$args['row']['customer_lastname'];
131
+ $smsDetails['firstname'] = $args['row']['customer_firstname'];
132
+ $smsDetails['customer_id'] = $args['row']['customer_id'];
133
+ $smsDetails['productname'][] = $args['row']['product_name'];
134
+ $smsDetails['cartprice'][] = Mage::helper('core')->currency(floatval(number_format(floatval($args['row']['product_price']),2)), true, false);
135
+ $smsDetails['cartprice_sum'] = floatval(number_format(floatval($args['row']['product_price']),2));
136
+ // Assign the values to the array of recipients
137
+ $this->_recipients[$args['row']['customer_mobile_number']]['cartId'] = $args['row']['cart_id'];
138
+
139
+ $smsDetails['link'] = $this->_generateUrl($this->_currentStoreId);
140
+ } else {
141
+
142
+ $smsDetails = $this->_recipients[$args['row']['customer_mobile_number']]['smsDetails'];
143
+
144
+ $smsDetails['productname'][] = $args['row']['product_name'];
145
+ $smsDetails['cartprice'][] = Mage::helper('core')->currency(floatval(number_format(floatval($args['row']['product_price']),2)), true, false);
146
+ $smsDetails['cartprice_sum'] += floatval(number_format(floatval($args['row']['product_price']),2));
147
+ }
148
+
149
+ //$smsDetails['cartprice_sum'] = Mage::helper('core')->currency($smsDetails['cartprice_sum'], true, false);
150
+
151
+ // Assign the array of template variables
152
+ $this->_recipients[$args['row']['customer_mobile_number']]['smsDetails'] = $smsDetails;
153
+ $this->_recipients[$args['row']['customer_mobile_number']]['store_id'] = $this->_currentStoreId;
154
+
155
+ }
156
+
157
+ /**
158
+ * @param $args
159
+ */
160
+ public function generateSaleRecipients($args)
161
+ {
162
+
163
+ // Customer group check
164
+ if (array_key_exists('customer_group',$args['row'])
165
+ && !in_array($args['row']['customer_group'],$this->_customerGroups)) {
166
+
167
+ return;
168
+ }
169
+
170
+ // Double check if the special from date is set
171
+ if (!array_key_exists('product_special_from_date',$args['row'])
172
+ || !$args['row']['product_special_from_date']) {
173
+
174
+ // If not we use today for the comparison
175
+ $fromDate = $this->_getToday();
176
+ } else {
177
+ $fromDate = $args['row']['product_special_from_date'];
178
+ }
179
+
180
+ // Do the same for the special to date
181
+ if (!array_key_exists('product_special_to_date',$args['row'])
182
+ || !$args['row']['product_special_to_date']) {
183
+
184
+ $toDate = $this->_getToday();
185
+ } else {
186
+ $toDate = $args['row']['product_special_to_date'];
187
+ }
188
+
189
+ // We need to ensure that the price in cart is higher than the new special price
190
+ // As well as the date comparison in case the sale is over or hasn't started
191
+ if (true || $args['row']['product_price_in_cart'] > 0.00
192
+ && $args['row']['product_special_price'] > 0.00
193
+ && ($args['row']['product_price_in_cart'] > $args['row']['product_special_price'])
194
+ && ($fromDate <= $this->_getToday())
195
+ && ($toDate >= $this->_getToday())) {
196
+
197
+ // Test if the customer is already in the array
198
+ if (!array_key_exists($args['row']['customer_mobile_number'], $this->_saleRecipients)) {
199
+
200
+ // Create an array of variables to assign to template
201
+ $smsDetails = array();
202
+
203
+ // Array that contains the data which will be used inside the template
204
+ $smsDetails['fullname'] = $args['row']['customer_firstname'].' '.$args['row']['customer_lastname'];
205
+ $smsDetails['firstname'] = $args['row']['customer_firstname'];
206
+ $smsDetails['customer_id'] = $args['row']['customer_id'];
207
+ $smsDetails['productname'][] = $args['row']['product_name'];
208
+ $smsDetails['cartprice'][] = Mage::helper('core')->currency(floatval(number_format(floatval($args['row']['product_price_in_cart']),2)), true, false);
209
+ $smsDetails['specialprice'][] = Mage::helper('core')->currency(floatval(number_format(floatval($args['row']['product_special_price']),2)), true, false);
210
+
211
+ // Assign the values to the array of recipients
212
+ $this->_saleRecipients[$args['row']['customer_mobile_number']]['cartId'] = $args['row']['cart_id'];
213
+
214
+ $smsDetails['link'] = $this->_generateUrl($this->_currentStoreId);
215
+
216
+ $smsDetails['cartprice_sum'] = floatval(number_format(floatval($args['row']['product_price_in_cart']),2));
217
+ $smsDetails['specialprice_sum'] = floatval(number_format(floatval($args['row']['product_special_price']),2));
218
+
219
+ // If one product before
220
+ $smsDetails['discount'] = number_format(floatval($args['row']['product_price_in_cart']),2) - number_format(floatval($args['row']['product_special_price']),2);
221
+ } else {
222
+ // We create some extra variables if there is several products in the cart
223
+ $smsDetails = $this->_saleRecipients[$args['row']['customer_mobile_number']]['smsDetails'];
224
+ // Discount amount
225
+ // We add the discount on the second product
226
+ $moreDiscount = number_format(floatval($args['row']['product_price_in_cart']),2) - number_format(floatval($args['row']['product_special_price']),2);
227
+ $smsDetails['discount'] += $moreDiscount;
228
+
229
+ $smsDetails['productname'][] = $args['row']['product_name'];
230
+ $smsDetails['cartprice'][] = Mage::helper('core')->currency(floatval(number_format(floatval($args['row']['product_price_in_cart']),2)), true, false);
231
+ $smsDetails['specialprice'][] = Mage::helper('core')->currency(floatval(number_format(floatval($args['row']['product_special_price']),2)), true, false);
232
+
233
+ $smsDetails['cartprice_sum'] += floatval(number_format(floatval($args['row']['product_price_in_cart']),2));
234
+ $smsDetails['specialprice_sum'] += floatval(number_format(floatval($args['row']['product_special_price']),2));
235
+
236
+ }
237
+
238
+ // Assign the array of template variables
239
+ $this->_saleRecipients[$args['row']['customer_mobile_number']]['smsDetails'] = $smsDetails;
240
+ $this->_saleRecipients[$args['row']['customer_mobile_number']]['store_id'] = $this->_currentStoreId;
241
+
242
+ }
243
+ }
244
+
245
+
246
+ /**
247
+ */
248
+ protected function _sendSaleSMSs()
249
+ {
250
+ $eventConfig = "abandoned_sale_cart_event";
251
+ if(!$this->getConfig()->isEventActive($eventConfig)){
252
+ Mage::getSingleton('adminhtml/session')->addWarning(
253
+ Mage::helper('easywebshopsms')->__(
254
+ 'Enable event: "%s" under settings.', Mage::helper('easywebshopsms')->__("Send Abandoned Sale cart SMS")
255
+ )
256
+ );
257
+ return false;
258
+ }
259
+
260
+
261
+ foreach ($this->_getSaleRecipients() as $mobile => $recipient) {
262
+
263
+ // Store Id
264
+ Mage::app()->setCurrentStore($recipient['store_id']);
265
+
266
+ $recipient['smsDetails']['mobile_number'] = $mobile;
267
+
268
+ $recipient['smsDetails']['discount'] = Mage::helper('core')->currency($recipient['smsDetails']['discount'], true, false);
269
+
270
+ $recipient['smsDetails']['cartprice_sum'] = Mage::helper('core')->currency($recipient['smsDetails']['cartprice_sum'], true, false);
271
+ $recipient['smsDetails']['specialprice_sum'] = Mage::helper('core')->currency($recipient['smsDetails']['specialprice_sum'], true, false);
272
+
273
+
274
+ $quote = Mage::getModel('sales/quote')->load($recipient['cartId']);
275
+
276
+ $helper = $this->getHelper();
277
+ $eventData = $helper->getOrderData($quote);
278
+ $eventData['smsDetails'] = $recipient['smsDetails'];
279
+ $eventData['customer_id'] = $eventData['smsDetails']['customer_id'];
280
+ $text = $this->getConfig()->getEventMessageTemplate($eventConfig);
281
+
282
+ if($helper->registerEvent($helper->prepareEventData("AbandonedSaleCartEvent", $eventData), $text)){
283
+ // We change the notification attribute
284
+ if(!$this->getConfig()->getDryRun()) {
285
+ $quote->setEasywebshopsmsAbandonedSaleNotified(1);
286
+
287
+ $quote->getResource()->saveAttribute($quote,array('easywebshopsms_abandoned_sale_notified'));
288
+ }
289
+ }
290
+
291
+ }
292
+ }
293
+
294
+
295
+ protected function _sendSMSs()
296
+ {
297
+
298
+ $eventConfig = "abandoned_cart_event";
299
+
300
+ if(!$this->getConfig()->isEventActive($eventConfig)){
301
+ Mage::getSingleton('adminhtml/session')->addWarning(
302
+ Mage::helper('easywebshopsms')->__(
303
+ 'Enable event: "%s" under settings.', Mage::helper('easywebshopsms')->__("Send Abandoned cart SMS")
304
+ )
305
+ );
306
+ return false;
307
+ }
308
+
309
+ // Send the emails via a loop
310
+ foreach ($this->_getRecipients() as $mobile => $recipient) {
311
+
312
+ // Store Id
313
+ Mage::app()->setCurrentStore($recipient['store_id']);
314
+
315
+ $recipient['smsDetails']['mobile_number'] = $mobile;
316
+
317
+ $recipient['smsDetails']['discount'] = Mage::helper('core')->currency($recipient['smsDetails']['discount'], true, false);
318
+ $recipient['smsDetails']['cartprice_sum'] = Mage::helper('core')->currency($recipient['smsDetails']['cartprice_sum'], true, false);
319
+
320
+ $quote = Mage::getModel('sales/quote')->load($recipient['cartId']);
321
+
322
+ $helper = $this->getHelper();
323
+ $eventData = $helper->getOrderData($quote);
324
+ $eventData['smsDetails'] = $recipient['smsDetails'];
325
+ $eventData['customer_id'] = $eventData['smsDetails']['customer_id'];
326
+ $text = $this->getConfig()->getEventMessageTemplate($eventConfig);
327
+
328
+ if($helper->registerEvent($helper->prepareEventData("AbandonedCartEvent", $eventData), $text)){
329
+ // We change the notification attribute
330
+ if(!$this->getConfig()->getDryRun()) {
331
+ $quote->setEasywebshopsmsAbandonedSaleNotified(1);
332
+
333
+ $quote->getResource()->saveAttribute($quote, array('easywebshopsms_abandoned_notified'));
334
+ }
335
+ }
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Send notification sms to customer with abandoned cart containing sale products
341
+ */
342
+ public function sendAbandonedCartsSaleSMS($mobiles = array())
343
+ {
344
+
345
+ // Set customer groups
346
+ $this->_customerGroups = $this->_customerGroups ? $this->_customerGroups : $this->getConfig()->getCustomerGroupsLimitation();
347
+ // Original store id
348
+ $this->_originalStoreId = Mage::app()->getStore()->getId();
349
+ try
350
+ {
351
+ if ($this->getConfig()->isApiEnabled()) {
352
+ $this->_setToday();
353
+
354
+ // Loop through the stores
355
+ foreach (Mage::app()->getWebsites() as $website) {
356
+ // Get the website id
357
+ $websiteId = $website->getWebsiteId();
358
+ foreach ($website->getGroups() as $group) {
359
+ $stores = $group->getStores();
360
+ foreach ($stores as $store) {
361
+
362
+ // Get the store id
363
+ $storeId = $store->getStoreId();
364
+ $this->_currentStoreId = $storeId;
365
+
366
+ // Init the store to be able to load the quote and the collections properly
367
+ Mage::app()->init($storeId,'store');
368
+
369
+ // Get the collection
370
+ $collection = Mage::getModel('NthMobile_EasyWebShopSMS_Model_Abandonedcart_Collection')->getSalesCollection($storeId, $websiteId, $mobiles);
371
+
372
+ $collection->load();
373
+
374
+ // Skip the rest of the code if the collection is empty
375
+ if ($collection->getSize() == 0) {
376
+ continue;
377
+ }
378
+
379
+ // Call iterator walk method with collection query string and callback method as parameters
380
+ // Has to be used to handle massive collection instead of foreach
381
+ Mage::getSingleton('core/resource_iterator')->walk($collection->getSelect(), array(array($this, 'generateSaleRecipients')));
382
+ }
383
+ }
384
+ }
385
+ $this->_sendSaleSMSs();
386
+ }
387
+ Mage::app()->setCurrentStore($this->_originalStoreId);
388
+
389
+ return count($this->_getSaleRecipients());
390
+ }
391
+ catch (Exception $e)
392
+ {
393
+ Mage::app()->setCurrentStore($this->_originalStoreId);
394
+ Mage::helper('abandonedcarts')->log(sprintf("%s->Error: %s", __METHOD__, $e->getMessage()));
395
+ return 0;
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Send notification email to customer with abandoned carts after the number of days specified in the config
401
+ */
402
+ public function sendAbandonedCartsSMS($mobiles = array())
403
+ {
404
+
405
+ // Set customer groups
406
+ $this->_customerGroups = $this->_customerGroups ? $this->_customerGroups : $this->getConfig()->getCustomerGroupsLimitation();
407
+ // Original store id
408
+ $this->_originalStoreId = Mage::app()->getStore()->getId();
409
+ try
410
+ {
411
+
412
+ if ($this->getConfig()->isApiEnabled()) {
413
+
414
+ // Date handling
415
+ $store = Mage_Core_Model_App::ADMIN_STORE_ID;
416
+ $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
417
+ date_default_timezone_set($timezone);
418
+
419
+ $delay = $this->getConfig()->getNotifDelay();
420
+
421
+ // Loop through the stores
422
+ foreach (Mage::app()->getWebsites() as $website) {
423
+ // Get the website id
424
+ $websiteId = $website->getWebsiteId();
425
+ foreach ($website->getGroups() as $group) {
426
+ $stores = $group->getStores();
427
+ foreach ($stores as $store) {
428
+
429
+ // Get the store id
430
+ $storeId = $store->getStoreId();
431
+ $this->_currentStoreId = $storeId;
432
+ // Init the store to be able to load the quote and the collections properly
433
+ Mage::app()->init($storeId, 'store');
434
+
435
+ // Get the collection
436
+ $collection = Mage::getModel('NthMobile_EasyWebShopSMS_Model_Abandonedcart_Collection')->getCollection($delay, $storeId, $websiteId, $mobiles);
437
+
438
+ $collection->load();
439
+
440
+ // Skip the rest of the code if the collection is empty
441
+ if ($collection->getSize() == 0) {
442
+ continue;
443
+ }
444
+
445
+ // Call iterator walk method with collection query string and callback method as parameters
446
+ // Has to be used to handle massive collection instead of foreach
447
+ Mage::getSingleton('core/resource_iterator')->walk($collection->getSelect(), array(array($this, 'generateRecipients')));
448
+ }
449
+ }
450
+ }
451
+ // Send the sms-es
452
+ $this->_sendSMSs();
453
+ }
454
+ Mage::app()->setCurrentStore($this->_originalStoreId);
455
+
456
+ return count($this->_getRecipients());
457
+ }
458
+ catch (Exception $e)
459
+ {
460
+ Mage::app()->setCurrentStore($this->_originalStoreId);
461
+ Mage::helper('easywebshopsms')->log(sprintf("%s->Error: %s", __METHOD__, $e->getMessage()));
462
+ return 0;
463
+ }
464
+ }
465
+
466
+ /**
467
+ * @return mixed|string
468
+ */
469
+ protected function _generateUrl( $storeId = 0)
470
+ {
471
+ return Mage::getUrl('easywebshopsms',
472
+ array(
473
+ '_store' => $storeId,
474
+ '_nosid' => true,
475
+ '_secure' => true
476
+ )
477
+ );
478
+
479
+ }
480
+
481
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Observer.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NthMobile_EasyWebShopSMS_Model_Observer
4
+ {
5
+
6
+ public static $lastExecutionTime; //to avoid multiple SMS if status was changed more than one time per 2 second
7
+
8
+ private $skipMultipleSendSmsPeriod = 5; //to avoid multiple SMS if status was changed more than one time per 5 second
9
+
10
+ public function _construct()
11
+ {
12
+ if (!self::$lastExecutionTime)
13
+ self::$lastExecutionTime = time();
14
+ }
15
+
16
+ /**
17
+ * @return NthMobile_EasyWebShopSMS_Model_Config
18
+ */
19
+ public function getConfig()
20
+ {
21
+ return Mage::getModel('easywebshopsms/config');
22
+ }
23
+
24
+ /**
25
+ * @return NthMobile_EasyWebShopSMS_Helper_Data
26
+ */
27
+ public function getHelper()
28
+ {
29
+ return Mage::helper('easywebshopsms');
30
+ }
31
+
32
+ public function hookToSalesOrderPlaceAfter(Varien_Event_Observer $observer)
33
+ {
34
+ if (time()-self::$lastExecutionTime<=$this->skipMultipleSendSmsPeriod)
35
+ return;
36
+
37
+ $eventConfig = "event_place_order";
38
+ $event = $observer->getEvent()->getOrder();
39
+
40
+ if($this->getConfig()->isEventActive($eventConfig))
41
+ {
42
+ $helper = $this->getHelper();
43
+ $eventData = $helper->getOrderData($event);
44
+ $text = $this->getConfig()->getEventMessageTemplate($eventConfig);
45
+
46
+ $helper->registerEvent($helper->prepareEventData("SalesOrderPlaceAfter", $eventData), $text);
47
+
48
+ self::$lastExecutionTime = time();
49
+ }
50
+ }
51
+
52
+ public function hookToSalesOrderShipmentPlaceAfter(Varien_Event_Observer $observer)
53
+ {
54
+ if (time()-self::$lastExecutionTime<=$this->skipMultipleSendSmsPeriod)
55
+ return;
56
+
57
+ $eventConfig = "event_place_order_shipment";
58
+ $shipment = $observer->getEvent()->getShipment();
59
+ $event = $shipment->getOrder();
60
+
61
+ if($this->getConfig()->isEventActive($eventConfig))
62
+ {
63
+ $helper = $this->getHelper();
64
+ $eventData = $helper->getOrderData($event);
65
+ $eventData['shipment']['total_qty'] = intval($shipment->getData('total_qty'));
66
+ $text = $this->getConfig()->getEventMessageTemplate($eventConfig);
67
+
68
+ $helper->registerEvent($helper->prepareEventData("SalesOrderShipmentPlaceAfter", $eventData), $text);
69
+
70
+ self::$lastExecutionTime = time();
71
+ }
72
+ }
73
+
74
+ public function orderStatusHistorySave($observer)
75
+ {
76
+
77
+ $config = $this->getConfig();
78
+ if (!$config->isApiEnabled()) return; //do nothing if api is disabled
79
+
80
+ $history = $observer->getEvent()->getStatusHistory();
81
+
82
+ //only for new status
83
+ if ($history->getId()) {
84
+
85
+ $order = $history->getOrder();
86
+ $newStatus = $order->getData('status');
87
+ $origStatus = $order->getOrigData('status');
88
+
89
+ if (time()-self::$lastExecutionTime<=$this->skipMultipleSendSmsPeriod)
90
+ return;
91
+
92
+ //if status has changed run action
93
+ if ($newStatus!=$origStatus) {
94
+ $eventConfig = "event_order_status_".$newStatus;
95
+ $text = $config->getEventMessageTemplate($eventConfig); //get template for new status (if active and exists)
96
+
97
+ $helper = $this->getHelper();
98
+ $eventData = $helper->getOrderData($order);
99
+
100
+ $helper->registerEvent($helper->prepareEventData("OrderStatusChange $origStatus > $newStatus", $eventData), $text);
101
+
102
+ self::$lastExecutionTime = time();
103
+
104
+ }
105
+ }
106
+ }
107
+
108
+
109
+ public function hookToCustomerLogin(Varien_Event_Observer $observer)
110
+ {
111
+ $eventConfig = "event_customer_login";
112
+
113
+ $event = $observer->getEvent();
114
+ if($this->getConfig()->isEventActive($eventConfig))
115
+ {
116
+ $text = $this->getConfig()->getEventMessageTemplate($eventConfig);
117
+ $helper = $this->getHelper();
118
+ $helper->registerEvent($helper->prepareEventData("CustomerLogin",$event->getData()),$text);
119
+ }
120
+ }
121
+
122
+ public function hookToCustomerLogout(Varien_Event_Observer $observer)
123
+ {
124
+ $eventConfig = "event_customer_logout";
125
+ $event = $observer->getEvent();
126
+ if($this->getConfig()->isEventActive($eventConfig))
127
+ {
128
+ $text = $this->getConfig()->getEventMessageTemplate($eventConfig);
129
+ $helper = $this->getHelper();
130
+ $helper->registerEvent($helper->prepareEventData("CustomerLogout",$event->getData()),$text);
131
+ }
132
+ }
133
+
134
+ public function hookToCustomerRegisterSuccess(Varien_Event_Observer $observer)
135
+ {
136
+ $eventConfig = "event_customer_register";
137
+
138
+ $event = $observer->getEvent()->getData();
139
+
140
+ if($this->getConfig()->isEventActive($eventConfig))
141
+ {
142
+ $text = $this->getConfig()->getEventMessageTemplate($eventConfig);
143
+ $helper = $this->getHelper();
144
+
145
+ $helper->registerEvent($helper->prepareEventData("CustomerRegisterSuccess", $event),$text);
146
+ }
147
+ }
148
+
149
+
150
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Resource/Easywebshopsms.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 30.5.2016.
6
+ * Time: 14:39
7
+ */
8
+ class NthMobile_EasyWebShopSMS_Model_Resource_Easywebshopsms extends Mage_Core_Model_Resource_Db_Abstract
9
+ {
10
+ protected function _construct()
11
+ {
12
+ $this->_init('easywebshopsms/easywebshopsms','id');
13
+ }
14
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Resource/Easywebshopsms/Collection.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 30.5.2016.
6
+ * Time: 14:41
7
+ */
8
+ class NthMobile_EasyWebShopSMS_Model_Resource_Easywebshopsms_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
9
+ {
10
+ public function _construct()
11
+ {
12
+ $this->_init('easywebshopsms/easywebshopsms');
13
+ }
14
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Resource/Setup.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class NthMobile_EasyWebShopSMS_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup{
4
+
5
+ }
app/code/community/NthMobile/EasyWebShopSMS/Model/Resources/Setup.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class NthMobile_EasyWebShopSMS_Model_Resources_Setup extends Mage_Eav_Model_Entity_Setup{
4
+
5
+ }
app/code/community/NthMobile/EasyWebShopSMS/controllers/Adminhtml/EasywebshopsmsabandonedcartsController.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 31.5.2016.
6
+ * Time: 9:48
7
+ */
8
+ class NthMobile_EasyWebShopSMS_Adminhtml_EasywebshopsmsabandonedcartsController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+
11
+ /**
12
+ * @return NthMobile_EasyWebShopSMS_Model_Config
13
+ */
14
+ public function getConfig()
15
+ {
16
+ return Mage::getModel('easywebshopsms/config');
17
+ }
18
+
19
+
20
+ public function indexAction()
21
+ {
22
+ $this->_title($this->__('Easywebshopsms'))->_title($this->__('Abandoned carts'));
23
+ $this->loadLayout();
24
+ $this->_setActiveMenu('easywebshopsms/easywebshopsms');
25
+ $this->renderLayout();
26
+ }
27
+
28
+ public function gridAction()
29
+ {
30
+ $this->loadLayout();
31
+ $this->getResponse()->setBody(
32
+ $this->getLayout()->createBlock('easywebshopsms/adminhtml_easywebshopsmsabandonedcarts_grid')->toHtml()
33
+ );
34
+ }
35
+
36
+ public function notifyAllAction()
37
+ {
38
+ try {
39
+ $count = Mage::getModel('easywebshopsms/notifier')->sendAbandonedCartsSMS();
40
+ Mage::getSingleton('adminhtml/session')->addSuccess(
41
+ Mage::helper('easywebshopsms')->__(
42
+ '%sTotal of %d customer(s) were successfully notified', ($this->getConfig()->getDryRun() ? "<b>!DRY RUN!</b> " : ""), $count
43
+ )
44
+ );
45
+ } catch (Exception $e) {
46
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
47
+ }
48
+ $this->_redirect('*/*/index');
49
+ }
50
+
51
+
52
+ public function notifyAction()
53
+ {
54
+ $customer_mobiles = $this->getRequest()->getParam($this->getRequest()->getParam('massaction_prepare_key', 'easywebshopsmsabandonedcarts'));
55
+ if (!is_array($customer_mobiles)) {
56
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('easywebshopsms')->__('Please select customers(s)'));
57
+ } else {
58
+
59
+ try {
60
+ $count = Mage::getModel('easywebshopsms/notifier')->sendAbandonedCartsSMS($customer_mobiles);
61
+ Mage::getSingleton('adminhtml/session')->addSuccess(
62
+ Mage::helper('easywebshopsms')->__(
63
+ '%sTotal of %d customer(s) were successfully notified', ($this->getConfig()->getDryRun() ? "<b>!DRY RUN!</b> " : ""), $count
64
+ )
65
+ );
66
+ } catch (Exception $e) {
67
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
68
+ }
69
+ }
70
+ $this->_redirect('*/*/index');
71
+ }
72
+ }
app/code/community/NthMobile/EasyWebShopSMS/controllers/Adminhtml/EasywebshopsmslogsController.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 31.5.2016.
6
+ * Time: 9:48
7
+ */
8
+ class NthMobile_EasyWebShopSMS_Adminhtml_EasywebshopsmslogsController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ public function indexAction()
11
+ {
12
+ $this->_title($this->__('Easywebshopsms'))->_title($this->__('Message Log'));
13
+ $this->loadLayout();
14
+ $this->_setActiveMenu('easywebshopsms/easywebshopsms');
15
+ $this->renderLayout();
16
+ }
17
+
18
+ public function gridAction()
19
+ {
20
+ $this->loadLayout();
21
+ $this->getResponse()->setBody(
22
+ $this->getLayout()->createBlock('easywebshopsms/adminhtml_easywebshopsmslogs_grid')->toHtml()
23
+ );
24
+ }
25
+
26
+ public function resetLogFileAction() {
27
+ $logFile = Mage::helper('easywebshopsms')->getLogFile();
28
+ $ret = "";
29
+ if(file_exists($logFile)) {
30
+ file_put_contents($logFile, "");
31
+ $ret = nl2br(file_put_contents($logFile));
32
+ }
33
+ Mage::app()->getResponse()->setBody($ret);
34
+ }
35
+ }
app/code/community/NthMobile/EasyWebShopSMS/controllers/Adminhtml/EasywebshopsmssaleabandonedcartsController.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 31.5.2016.
6
+ * Time: 9:48
7
+ */
8
+ class NthMobile_EasyWebShopSMS_Adminhtml_EasywebshopsmssaleabandonedcartsController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ /**
11
+ * @return NthMobile_EasyWebShopSMS_Model_Config
12
+ */
13
+ public function getConfig()
14
+ {
15
+ return Mage::getModel('easywebshopsms/config');
16
+ }
17
+
18
+
19
+ public function indexAction()
20
+ {
21
+ $this->_title($this->__('Easywebshopsms'))->_title($this->__('Sale Abandoned carts'));
22
+
23
+ $this->loadLayout();
24
+ $this->_setActiveMenu('easywebshopsms/easywebshopsms');
25
+ $this->renderLayout();
26
+ }
27
+
28
+ public function gridAction()
29
+ {
30
+ $this->loadLayout();
31
+ $this->getResponse()->setBody(
32
+ $this->getLayout()->createBlock('easywebshopsms/adminhtml_easywebshopsmssaleabandonedcarts_grid')->toHtml()
33
+ );
34
+ }
35
+
36
+
37
+ public function notifyAllAction()
38
+ {
39
+ try {
40
+ $count = Mage::getModel('easywebshopsms/notifier')->sendAbandonedCartsSaleSMS();
41
+ Mage::getSingleton('adminhtml/session')->addSuccess(
42
+ Mage::helper('easywebshopsms')->__(
43
+ '%sTotal of %d customer(s) were successfully notified', ($this->getConfig()->getDryRun() ? "<b>!DRY RUN!</b> " : ""), $count
44
+ )
45
+ );
46
+ } catch (Exception $e) {
47
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
48
+ }
49
+ $this->_redirect('*/*/index');
50
+ }
51
+
52
+
53
+ public function notifyAction()
54
+ {
55
+ $customer_mobiles = $this->getRequest()->getParam($this->getRequest()->getParam('massaction_prepare_key', 'easywebshopsmsabandonedcarts'));
56
+ if (!is_array($customer_mobiles)) {
57
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('easywebshopsms')->__('Please select customers(s)'));
58
+ } else {
59
+
60
+ try {
61
+ $count = Mage::getModel('easywebshopsms/notifier')->sendAbandonedCartsSaleSMS($customer_mobiles);
62
+ Mage::getSingleton('adminhtml/session')->addSuccess(
63
+ Mage::helper('easywebshopsms')->__(
64
+ '%sTotal of %d customer(s) were successfully notified', ($this->getConfig()->getDryRun() ? "<b>!DRY RUN!</b> " : ""), $count
65
+ )
66
+ );
67
+ } catch (Exception $e) {
68
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
69
+ }
70
+ }
71
+ $this->_redirect('*/*/index');
72
+ }
73
+ }
app/code/community/NthMobile/EasyWebShopSMS/controllers/ApiController.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Nikola Bakos <nikola.bakos@nth.ch>
5
+ *
6
+ * Paths follow the following pattern:
7
+ * /:module/:controller/:action
8
+ *
9
+ * :module is what matches package/module/config.xml
10
+ * config.frontend.routers.{module}.args.frontName value,
11
+ * and in this case 'easywebshopsms'
12
+ *
13
+ * :controller defaults to index
14
+ * :action defaults to index
15
+ *
16
+ */
17
+ class NthMobile_EasyWebShopSMS_ApiController extends Mage_Core_Controller_Front_Action
18
+ {
19
+
20
+ /**
21
+ * paths: /easywebshopsms/
22
+ * /easywebshopsms/api/handleBulkSmsNotification
23
+ * /easywebshopsms/api/relatedProducts
24
+ *
25
+ * @return void
26
+ */
27
+ public function relatedProductsAction()
28
+ {
29
+ $productId = Mage::app()->getRequest()->getParam('productId');
30
+ $relatedProducts = [];
31
+
32
+ if ($productId != null) {
33
+ $product = Mage::getModel('catalog/product')->load($productId);
34
+ $relatedProductsId = $product->getRelatedProductIds();
35
+ foreach ($relatedProductsId as $relatedProductId) {
36
+ $relatedProducts[] = Mage::getModel('catalog/product')->load($relatedProductId)->getData();
37
+ }
38
+ }
39
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($relatedProducts));
40
+ $this->getResponse()->setHeader('Content-type', 'application/json');
41
+ }
42
+
43
+ public function handleBulkSmsNotificationAction()
44
+ {
45
+ // TODO - finish notification handling
46
+ $handle = new \Samurai\BulkSms\Handle\NotificationHandle();
47
+
48
+ if ($handle->isValid()) {
49
+
50
+ $resource = $handle->resource();
51
+ $status = $resource->getStatus();
52
+ $inputData = [];
53
+ $smsId = $resource->getSmsId();
54
+
55
+ if ($status->isDelivered()) {
56
+
57
+ $inputData['sms_sent'] = 1;
58
+ }
59
+
60
+ $statusCode = $status->getCode();
61
+ $statusMessage = $status->getMessage();
62
+
63
+ $inputData['sms_status_code'] = $statusCode;
64
+ $inputData['sms_status_message'] = $statusMessage;
65
+
66
+ // TODO Update model()->where('sms_id' => $smsId)->save($inputData);
67
+ $id = $smsId;
68
+ $data = array('sms_status_message'=>$statusMessage,'sms_sent'=>$inputData['sms_sent']);
69
+ $model = Mage::getModel('easywebshopsms/easywebshopsms')->load($id)->addData($data);
70
+
71
+ $model->setId($id)->save();
72
+ // Update
73
+ } else {
74
+ // Invalid handle request
75
+ }
76
+ }
77
+
78
+ }
app/code/community/NthMobile/EasyWebShopSMS/controllers/TestController.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Nikola Bakos <nikola.bakos@nth.ch>
5
+ *
6
+ * Paths follow the following pattern:
7
+ * /:module/:controller/:action
8
+ *
9
+ * :module is what matches package/module/config.xml
10
+ * config.frontend.routers.{module}.args.frontName value,
11
+ * and in this case 'easywebshopsms'
12
+ *
13
+ * :controller defaults to index
14
+ * :action defaults to index
15
+ *
16
+ */
17
+ class NthMobile_EasyWebShopSMS_TestController extends Mage_Core_Controller_Front_Action
18
+ {
19
+
20
+ /**
21
+ * paths: /easywebshopsms/
22
+ * /easywebshopsms/test
23
+ * /easywebshopsms/test/log
24
+ *
25
+ * @return void
26
+ */
27
+ public function logAction()
28
+ {
29
+ Mage::log(" - - - - - - - - - - - - - - - - - - - - - - - - - " , Zend_Log::DEBUG, 'test.log');
30
+ Mage::log("log Action: " . file_get_contents('php://input') , Zend_Log::DEBUG, 'test.log');
31
+
32
+ $this->getResponse()->setBody("{\"result\":\"OK\"}");
33
+ $this->getResponse()->setHeader('Content-type', 'application/json');
34
+ }
35
+
36
+
37
+ }
app/code/community/NthMobile/EasyWebShopSMS/etc/config.xml ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <NthMobile_EasyWebShopSMS>
5
+ <version>1.0.1</version>
6
+ </NthMobile_EasyWebShopSMS>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <easywebshopsms>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>NthMobile_EasyWebShopSMS</module>
14
+ <!-- this is the url that will trigger the controller to be called -->
15
+ <!-- /easywebshopsms/:controller/:action -->
16
+ <frontName>easywebshopsms</frontName>
17
+ </args>
18
+ </easywebshopsms>
19
+ </routers>
20
+ <layout>
21
+ <updates>
22
+ <NthMobile_EasyWebShopSMS module="NthMobile_EasyWebShopSMS">
23
+ <file>nthmobile_easywebshopsms.xml</file>
24
+ </NthMobile_EasyWebShopSMS>
25
+ </updates>
26
+ </layout>
27
+ </frontend>
28
+ <global>
29
+ <models>
30
+ <easywebshopsms>
31
+ <class>NthMobile_EasyWebShopSMS_Model</class>
32
+ <resourceModel>easywebshopsms_resource</resourceModel>
33
+ </easywebshopsms>
34
+ <easywebshopsms_resource>
35
+ <class>NthMobile_EasyWebShopSMS_Model_Resource</class>
36
+ <entities>
37
+ <easywebshopsms>
38
+ <table>easywebshopsms</table>
39
+ </easywebshopsms>
40
+ </entities>
41
+ </easywebshopsms_resource>
42
+ </models>
43
+ <blocks>
44
+ <easywebshopsms>
45
+ <class>NthMobile_EasyWebShopSMS_Block</class>
46
+ </easywebshopsms>
47
+ </blocks>
48
+ <helpers>
49
+ <easywebshopsms>
50
+ <class>NthMobile_EasyWebShopSMS_Helper</class>
51
+ </easywebshopsms>
52
+ </helpers>
53
+ <events>
54
+ <sales_order_status_history_save_before>
55
+ <observers>
56
+ <easywebshopsms>
57
+ <class>easywebshopsms/observer</class>
58
+ <method>orderStatusHistorySave</method>
59
+ </easywebshopsms>
60
+ </observers>
61
+ </sales_order_status_history_save_before>
62
+ <sales_order_place_after>
63
+ <observers>
64
+ <easywebshopsms>
65
+ <class>easywebshopsms/observer</class>
66
+ <method>hookToSalesOrderPlaceAfter</method>
67
+ <type>singleton</type>
68
+ </easywebshopsms>
69
+ </observers>
70
+ </sales_order_place_after>
71
+ <sales_order_shipment_save_after>
72
+ <observers>
73
+ <easywebshopsms>
74
+ <class>easywebshopsms/observer</class>
75
+ <method>hookToSalesOrderShipmentPlaceAfter</method>
76
+ <type>singleton</type>
77
+ </easywebshopsms>
78
+ </observers>
79
+ </sales_order_shipment_save_after>
80
+ <customer_register_success>
81
+ <observers>
82
+ <easywebshopsms>
83
+ <class>easywebshopsms/observer</class>
84
+ <method>hookToCustomerRegisterSuccess</method>
85
+ <type>singleton</type>
86
+ </easywebshopsms>
87
+ </observers>
88
+ </customer_register_success>
89
+ <customer_login>
90
+ <observers>
91
+ <easywebshopsms>
92
+ <class>easywebshopsms/observer</class>
93
+ <method>hookToCustomerLogin</method>
94
+ <type>singleton</type>
95
+ </easywebshopsms>
96
+ </observers>
97
+ </customer_login>
98
+ <customer_logout>
99
+ <observers>
100
+ <easywebshopsms>
101
+ <class>easywebshopsms/observer</class>
102
+ <method>hookToCustomerLogout</method>
103
+ <type>singleton</type>
104
+ </easywebshopsms>
105
+ </observers>
106
+ </customer_logout>
107
+ </events>
108
+ <resources>
109
+ <NthMobile_EasyWebShopSMS_setup>
110
+ <setup>
111
+ <module>NthMobile_EasyWebShopSMS</module>
112
+ <class>Mage_Customer_Model_Entity_Setup</class>
113
+ </setup>
114
+ <connection>
115
+ <use>core_setup</use>
116
+ </connection>
117
+ </NthMobile_EasyWebShopSMS_setup>
118
+ <NthMobile_EasyWebShopSMS_write>
119
+ <connection>
120
+ <use>core_write</use>
121
+ </connection>
122
+ </NthMobile_EasyWebShopSMS_write>
123
+ <NthMobile_EasyWebShopSMS_read>
124
+ <connection>
125
+ <use>core_read</use>
126
+ </connection>
127
+ </NthMobile_EasyWebShopSMS_read>
128
+ </resources>
129
+ </global>
130
+ <admin>
131
+ <routers>
132
+ <easywebshopsms>
133
+ <use>admin</use>
134
+ <args>
135
+ <module>NthMobile_EasyWebShopSMS</module>
136
+ <frontName>easywebshopsms</frontName>
137
+ </args>
138
+ </easywebshopsms>
139
+ </routers>
140
+ </admin>
141
+ <adminhtml>
142
+ <menu>
143
+ <easywebshopsms translate="title" module="easywebshopsms">
144
+ <title>EasyWebShop SMS</title>
145
+ <sort_order>71</sort_order>
146
+ <children>
147
+ <logs translate="title" module="easywebshopsms">
148
+ <title>Message Log</title>
149
+ <sort_order>10</sort_order>
150
+ <action>easywebshopsms/adminhtml_easywebshopsmslogs</action>
151
+ </logs>
152
+ <abandonedcarts translate="title" module="easywebshopsms">
153
+ <title>Abandoned carts</title>
154
+ <sort_order>20</sort_order>
155
+ <action>easywebshopsms/adminhtml_easywebshopsmsabandonedcarts</action>
156
+ </abandonedcarts>
157
+ <saleabandonedcarts translate="title" module="easywebshopsms">
158
+ <title>Sale Abandoned carts</title>
159
+ <sort_order>25</sort_order>
160
+ <action>easywebshopsms/adminhtml_easywebshopsmssaleabandonedcarts</action>
161
+ </saleabandonedcarts>
162
+ <settings translate="title" module="easywebshopsms">
163
+ <title>Settings</title>
164
+ <sort_order>99</sort_order>
165
+ <action>adminhtml/system_config/edit/section/easywebshopsms</action>
166
+ </settings>
167
+ </children>
168
+ </easywebshopsms>
169
+ </menu>
170
+ <layout>
171
+ <updates>
172
+ <easywebshopsms>
173
+ <file>nthmobile_easywebshopsms.xml</file>
174
+ </easywebshopsms>
175
+ </updates>
176
+ </layout>
177
+ <acl>
178
+ <resources>
179
+ <admin>
180
+ <children>
181
+ <system>
182
+ <children>
183
+ <config>
184
+ <children>
185
+ <easywebshopsms translate="title" module="easywebshopsms">
186
+ <title>Easywebshopsms Configuration</title>
187
+ </easywebshopsms>
188
+ </children>
189
+ </config>
190
+ </children>
191
+ </system>
192
+ </children>
193
+ </admin>
194
+ </resources>
195
+ </acl>
196
+ </adminhtml>
197
+ </config>
app/code/community/NthMobile/EasyWebShopSMS/etc/system.xml ADDED
@@ -0,0 +1,509 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <tabs>
4
+ <nthmobile translate="label">
5
+ <label>NTH Mobile</label>
6
+ <sort_order>1</sort_order>
7
+ </nthmobile>
8
+ </tabs>
9
+
10
+ <sections>
11
+ <easywebshopsms translate="label" module="easywebshopsms">
12
+ <label>EasyWebShop SMS</label>
13
+ <tab>nthmobile</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>100</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <details module="easywebshopsms">
21
+ <frontend_model>easywebshopsms/adminhtml_system_config_section_details</frontend_model>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>0</show_in_website>
24
+ <show_in_store>0</show_in_store>
25
+ <sort_order>0</sort_order>
26
+ </details>
27
+
28
+ <api_connection translate="label">
29
+ <label>EasyWebShop SMS Connection</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ <fields>
36
+ <active translate="label">
37
+ <label>Activate</label>
38
+ <frontend_type>select</frontend_type>
39
+ <source_model>adminhtml/system_config_source_yesno</source_model>
40
+ <sort_order>1</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ <comment>Is module active for sending SMS messages</comment>
45
+ </active>
46
+ <api_user translate="label">
47
+ <label>Username</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>11</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ <comment>Enter EasyWebShop SMS Api username</comment>
54
+ </api_user>
55
+ <api_pass translate="label">
56
+ <label>Password</label>
57
+ <frontend_type>text</frontend_type>
58
+ <sort_order>12</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ <comment>Enter EasyWebShop SMS Api password</comment>
63
+ </api_pass>
64
+ <api_uri translate="label">
65
+ <label>Host</label>
66
+ <frontend_type>text</frontend_type>
67
+ <sort_order>13</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ <comment>Enter EasyWebShop SMS Api Host</comment>
72
+ </api_uri>
73
+ <api_port translate="label">
74
+ <label>Port</label>
75
+ <frontend_type>text</frontend_type>
76
+ <sort_order>14</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ <comment>Enter EasyWebShop SMS Api port</comment>
81
+ </api_port>
82
+ <storename translate="label">
83
+ <label>Store name</label>
84
+ <frontend_type>text</frontend_type>
85
+ <sort_order>90</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>1</show_in_store>
89
+ <comment>Enter Store name for custom messages eg. store.nth.ch</comment>
90
+ </storename>
91
+ <sms_origin>
92
+ <label>SMS Origin</label>
93
+ <frontend_type>text</frontend_type>
94
+ <sort_order>91</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <comment>Enter SMS "From" number</comment>
99
+ </sms_origin>
100
+ <debug_mode translate="label">
101
+ <label>Debug Mode</label>
102
+ <comment>Toggle debug mode. Useful for logging API calls and other important information</comment>
103
+ <frontend_type>select</frontend_type>
104
+ <sort_order>92</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>0</show_in_website>
107
+ <show_in_store>0</show_in_store>
108
+ <source_model>adminhtml/system_config_source_yesno</source_model>
109
+ </debug_mode>
110
+ <dry_run translate="label">
111
+ <label>Dry run</label>
112
+ <comment>Toggle dry run mode. Everything is processed except actual sending SMS message.</comment>
113
+ <frontend_type>select</frontend_type>
114
+ <sort_order>92</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>0</show_in_website>
117
+ <show_in_store>0</show_in_store>
118
+ <source_model>adminhtml/system_config_source_yesno</source_model>
119
+ </dry_run>
120
+ </fields>
121
+ </api_connection>
122
+ <message_configuration translate="label">
123
+ <label>Message configuration</label>
124
+ <frontend_type>text</frontend_type>
125
+ <sort_order>2</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ <comment><![CDATA[
130
+ <div style="padding:10px;background-color:#fff;border:1px solid #CCC;margin-bottom:7px;">
131
+ In each template you can use dynamic data. You can add <br />
132
+ - {customer.firstname} - customer first name <br />
133
+ - {customer.lastname} - customer last name <br />
134
+ - {data.order.status} - status of an order <br />
135
+ - {data.order.number} - order number<br />
136
+ - {data.tracking.number} - tracking number (if exists)<br />
137
+ - {data.storename} - the name of the store<br />
138
+ Example: Your order #{data.order.number} waits for a fee. Regards {storename}<br />
139
+ SMS Content: Your order #100000012 waits for a fee. Regards store.nth.com<br />
140
+ <br />
141
+ <br />
142
+ Additional placeholders for <b>Abandoned carts</b><br/>
143
+ - {data.smsDetails.productname} - products in cart name <br />
144
+ - {data.smsDetails.cartprice_sum} - sum cart price <br />
145
+ - {data.smsDetails.specialprice_sum} - special cart price (for: abandoned sale) <br />
146
+ - {data.smsDetails.discount} - sum discount of product in cart (for: abandoned sale) <br />
147
+
148
+ </div>
149
+ <div id="easywebshopsmsCounterContainer">
150
+ Message length: <span id="easywebshopsmsCounter">0</span> chars.<br />
151
+ <span id="easywebshopsmsTooLongAlert"> Warning: The template can be to long for 1 SMS.</span>
152
+ </div><br />
153
+ ]]></comment>
154
+ <fields>
155
+
156
+ <heading_place_order_event translate="label">
157
+ <label>Order Events</label>
158
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
159
+ <sort_order>5</sort_order>
160
+ <show_in_default>1</show_in_default>
161
+ <show_in_website>1</show_in_website>
162
+ <show_in_store>0</show_in_store>
163
+ </heading_place_order_event>
164
+ <event_place_order translate="label">
165
+ <label>Send SMS on Place Order Event</label>
166
+ <frontend_type>select</frontend_type>
167
+ <source_model>adminhtml/system_config_source_yesno</source_model>
168
+ <sort_order>6</sort_order>
169
+ <show_in_default>1</show_in_default>
170
+ <show_in_website>1</show_in_website>
171
+ <show_in_store>1</show_in_store>
172
+ <comment>Send SMS to customer when order is placed</comment>
173
+ </event_place_order>
174
+ <event_place_order_text_message>
175
+ <label>Message Text</label>
176
+ <frontend_type>textarea</frontend_type>
177
+ <sort_order>7</sort_order>
178
+ <show_in_default>1</show_in_default>
179
+ <show_in_website>1</show_in_website>
180
+ <show_in_store>1</show_in_store>
181
+ <depends><event_place_order>1</event_place_order></depends>
182
+ </event_place_order_text_message>
183
+
184
+ <event_order_status_pending translate="label">
185
+ <label>Send SMS after status changed to "Pending Payment"</label>
186
+ <frontend_type>select</frontend_type>
187
+ <source_model>adminhtml/system_config_source_yesno</source_model>
188
+ <sort_order>10</sort_order>
189
+ <show_in_default>1</show_in_default>
190
+ <show_in_website>1</show_in_website>
191
+ <show_in_store>1</show_in_store>
192
+ </event_order_status_pending>
193
+ <event_order_status_pending_text_message translate="label">
194
+ <label>Message text</label>
195
+ <frontend_type>textarea</frontend_type>
196
+ <sort_order>11</sort_order>
197
+ <show_in_default>1</show_in_default>
198
+ <show_in_website>1</show_in_website>
199
+ <show_in_store>1</show_in_store>
200
+ <depends><event_order_status_pending>1</event_order_status_pending></depends>
201
+ </event_order_status_pending_text_message>
202
+
203
+ <event_order_status_holded translate="label">
204
+ <label>Send SMS after status changed to "On Hold"</label>
205
+ <frontend_type>select</frontend_type>
206
+ <source_model>adminhtml/system_config_source_yesno</source_model>
207
+ <sort_order>15</sort_order>
208
+ <show_in_default>1</show_in_default>
209
+ <show_in_website>1</show_in_website>
210
+ <show_in_store>1</show_in_store>
211
+ </event_order_status_holded>
212
+ <event_order_status_holded_text_message translate="label">
213
+ <label>Message text</label>
214
+ <frontend_type>textarea</frontend_type>
215
+ <sort_order>16</sort_order>
216
+ <show_in_default>1</show_in_default>
217
+ <show_in_website>1</show_in_website>
218
+ <show_in_store>1</show_in_store>
219
+ <depends><event_order_status_holded>1</event_order_status_holded></depends>
220
+ </event_order_status_holded_text_message>
221
+
222
+ <event_order_status_processing translate="label">
223
+ <label>Send SMS after status changed to "Processing" eg. Invoice is created</label>
224
+ <frontend_type>select</frontend_type>
225
+ <source_model>adminhtml/system_config_source_yesno</source_model>
226
+ <sort_order>20</sort_order>
227
+ <show_in_default>1</show_in_default>
228
+ <show_in_website>1</show_in_website>
229
+ <show_in_store>1</show_in_store>
230
+ </event_order_status_processing>
231
+ <event_order_status_processing_text_message translate="label">
232
+ <label>Message text</label>
233
+ <frontend_type>textarea</frontend_type>
234
+ <sort_order>21</sort_order>
235
+ <show_in_default>1</show_in_default>
236
+ <show_in_website>1</show_in_website>
237
+ <show_in_store>1</show_in_store>
238
+ <depends><event_order_status_processing>1</event_order_status_processing></depends>
239
+ </event_order_status_processing_text_message>
240
+
241
+ <event_order_status_canceled translate="label">
242
+ <label>Send SMS after status changed to "Canceled"</label>
243
+ <frontend_type>select</frontend_type>
244
+ <source_model>adminhtml/system_config_source_yesno</source_model>
245
+ <sort_order>25</sort_order>
246
+ <show_in_default>1</show_in_default>
247
+ <show_in_website>1</show_in_website>
248
+ <show_in_store>1</show_in_store>
249
+ </event_order_status_canceled>
250
+ <event_order_status_canceled_text_message translate="label">
251
+ <label>Message text</label>
252
+ <frontend_type>textarea</frontend_type>
253
+ <sort_order>26</sort_order>
254
+ <show_in_default>1</show_in_default>
255
+ <show_in_website>1</show_in_website>
256
+ <show_in_store>1</show_in_store>
257
+ <depends><event_order_status_canceled>1</event_order_status_canceled></depends>
258
+ </event_order_status_canceled_text_message>
259
+
260
+ <event_order_status_complete translate="label">
261
+ <label>Send SMS after status changed to "Complete"</label>
262
+ <frontend_type>select</frontend_type>
263
+ <source_model>adminhtml/system_config_source_yesno</source_model>
264
+ <sort_order>30</sort_order>
265
+ <show_in_default>1</show_in_default>
266
+ <show_in_website>1</show_in_website>
267
+ <show_in_store>1</show_in_store>
268
+ </event_order_status_complete>
269
+ <event_order_status_complete_text_message translate="label">
270
+ <label>Message text</label>
271
+ <frontend_type>textarea</frontend_type>
272
+ <sort_order>31</sort_order>
273
+ <show_in_default>1</show_in_default>
274
+ <show_in_website>1</show_in_website>
275
+ <show_in_store>1</show_in_store>
276
+ <depends><event_order_status_complete>1</event_order_status_complete></depends>
277
+ </event_order_status_complete_text_message>
278
+
279
+ <event_order_status_closed translate="label">
280
+ <label>Send SMS after status changed to "Closed"</label>
281
+ <frontend_type>select</frontend_type>
282
+ <source_model>adminhtml/system_config_source_yesno</source_model>
283
+ <sort_order>35</sort_order>
284
+ <show_in_default>1</show_in_default>
285
+ <show_in_website>1</show_in_website>
286
+ <show_in_store>1</show_in_store>
287
+ </event_order_status_closed>
288
+ <event_order_status_closed_text_message translate="label">
289
+ <label>Message text</label>
290
+ <frontend_type>textarea</frontend_type>
291
+ <sort_order>36</sort_order>
292
+ <show_in_default>1</show_in_default>
293
+ <show_in_website>1</show_in_website>
294
+ <show_in_store>1</show_in_store>
295
+ <depends><event_order_status_closed>1</event_order_status_closed></depends>
296
+ </event_order_status_closed_text_message>
297
+
298
+ <heading_event_place_order_shipment translate="label">
299
+ <label>Shipment Events</label>
300
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
301
+ <sort_order>50</sort_order>
302
+ <show_in_default>1</show_in_default>
303
+ <show_in_website>1</show_in_website>
304
+ <show_in_store>0</show_in_store>
305
+ </heading_event_place_order_shipment>
306
+ <event_place_order_shipment>
307
+ <label>Send SMS on Shipment status</label>
308
+ <frontend_type>select</frontend_type>
309
+ <source_model>adminhtml/system_config_source_yesno</source_model>
310
+ <sort_order>51</sort_order>
311
+ <show_in_default>1</show_in_default>
312
+ <show_in_website>1</show_in_website>
313
+ <show_in_store>1</show_in_store>
314
+ <comment>extra placeholder: {data.shipment.total_qty}</comment>
315
+ </event_place_order_shipment>
316
+ <event_place_order_shipment_text_message>
317
+ <label>Message Text</label>
318
+ <frontend_type>textarea</frontend_type>
319
+ <sort_order>52</sort_order>
320
+ <show_in_default>1</show_in_default>
321
+ <show_in_website>1</show_in_website>
322
+ <show_in_store>1</show_in_store>
323
+ <depends><event_place_order_shipment>1</event_place_order_shipment></depends>
324
+ </event_place_order_shipment_text_message>
325
+
326
+
327
+ <heading_abandoned_cart translate="label">
328
+ <label>Abandoned carts</label>
329
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
330
+ <sort_order>70</sort_order>
331
+ <show_in_default>1</show_in_default>
332
+ <show_in_website>1</show_in_website>
333
+ <show_in_store>0</show_in_store>
334
+ </heading_abandoned_cart>
335
+ <abandoned_cart_event>
336
+ <label>Send Abandoned cart SMS</label>
337
+ <frontend_type>select</frontend_type>
338
+ <source_model>adminhtml/system_config_source_yesno</source_model>
339
+ <sort_order>71</sort_order>
340
+ <show_in_default>1</show_in_default>
341
+ <show_in_website>1</show_in_website>
342
+ <show_in_store>1</show_in_store>
343
+ </abandoned_cart_event>
344
+ <abandoned_cart_event_text_message>
345
+ <label>Message Text</label>
346
+ <frontend_type>textarea</frontend_type>
347
+ <sort_order>72</sort_order>
348
+ <show_in_default>1</show_in_default>
349
+ <show_in_website>1</show_in_website>
350
+ <show_in_store>1</show_in_store>
351
+ <depends><abandoned_cart_event>1</abandoned_cart_event></depends>
352
+ </abandoned_cart_event_text_message>
353
+ <abandoned_sale_cart_event>
354
+ <label>Send Abandoned Sale cart SMS</label>
355
+ <frontend_type>select</frontend_type>
356
+ <source_model>adminhtml/system_config_source_yesno</source_model>
357
+ <sort_order>73</sort_order>
358
+ <show_in_default>1</show_in_default>
359
+ <show_in_website>1</show_in_website>
360
+ <show_in_store>1</show_in_store>
361
+ </abandoned_sale_cart_event>
362
+ <abandoned_sale_cart_event_text_message>
363
+ <label>Message Text</label>
364
+ <frontend_type>textarea</frontend_type>
365
+ <sort_order>74</sort_order>
366
+ <show_in_default>1</show_in_default>
367
+ <show_in_website>1</show_in_website>
368
+ <show_in_store>1</show_in_store>
369
+ <depends><abandoned_sale_cart_event>1</abandoned_sale_cart_event></depends>
370
+ </abandoned_sale_cart_event_text_message>
371
+
372
+
373
+ <heading_customer_login_event translate="label">
374
+ <label>Customer Events</label>
375
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
376
+ <sort_order>90</sort_order>
377
+ <show_in_default>1</show_in_default>
378
+ <show_in_website>1</show_in_website>
379
+ <show_in_store>0</show_in_store>
380
+ </heading_customer_login_event>
381
+ <event_customer_login>
382
+ <label>Send SMS on Customer Login</label>
383
+ <frontend_type>select</frontend_type>
384
+ <source_model>adminhtml/system_config_source_yesno</source_model>
385
+ <sort_order>91</sort_order>
386
+ <show_in_default>1</show_in_default>
387
+ <show_in_website>1</show_in_website>
388
+ <show_in_store>1</show_in_store>
389
+ <comment>Send SMS to customer when customer logins into shop</comment>
390
+ </event_customer_login>
391
+ <event_customer_login_text_message>
392
+ <label>Message Text</label>
393
+ <frontend_type>textarea</frontend_type>
394
+ <sort_order>92</sort_order>
395
+ <show_in_default>1</show_in_default>
396
+ <show_in_website>1</show_in_website>
397
+ <show_in_store>1</show_in_store>
398
+ <depends><event_customer_login>1</event_customer_login></depends>
399
+ </event_customer_login_text_message>
400
+ <event_customer_logout>
401
+ <label>Send SMS on Customer Logout</label>
402
+ <frontend_type>select</frontend_type>
403
+ <source_model>adminhtml/system_config_source_yesno</source_model>
404
+ <sort_order>93</sort_order>
405
+ <show_in_default>1</show_in_default>
406
+ <show_in_website>1</show_in_website>
407
+ <show_in_store>1</show_in_store>
408
+ <comment>Send SMS to customer when customer logouts from shop</comment>
409
+ </event_customer_logout>
410
+ <event_customer_logout_text_message>
411
+ <label>Message Text</label>
412
+ <frontend_type>textarea</frontend_type>
413
+ <sort_order>94</sort_order>
414
+ <show_in_default>1</show_in_default>
415
+ <show_in_website>1</show_in_website>
416
+ <show_in_store>1</show_in_store>
417
+ <depends><event_customer_logout>1</event_customer_logout></depends>
418
+ </event_customer_logout_text_message>
419
+ <event_customer_register>
420
+ <label>Send SMS on Customer Register Success</label>
421
+ <frontend_type>select</frontend_type>
422
+ <source_model>adminhtml/system_config_source_yesno</source_model>
423
+ <sort_order>95</sort_order>
424
+ <show_in_default>1</show_in_default>
425
+ <show_in_website>1</show_in_website>
426
+ <show_in_store>1</show_in_store>
427
+ <comment>Send SMS to customer when customer registers</comment>
428
+ </event_customer_register>
429
+ <event_customer_register_text_message>
430
+ <label>Message Text</label>
431
+ <frontend_type>textarea</frontend_type>
432
+ <sort_order>96</sort_order>
433
+ <show_in_default>1</show_in_default>
434
+ <show_in_website>1</show_in_website>
435
+ <show_in_store>1</show_in_store>
436
+ <depends><event_customer_register>1</event_customer_register></depends>
437
+ </event_customer_register_text_message>
438
+ </fields>
439
+ </message_configuration>
440
+ <abandoned_notifications translate="label">
441
+ <label>Abandoned notifications</label>
442
+ <frontend_type>text</frontend_type>
443
+ <sort_order>2</sort_order>
444
+ <show_in_default>1</show_in_default>
445
+ <show_in_website>1</show_in_website>
446
+ <show_in_store>1</show_in_store>
447
+ <fields>
448
+ <heading_abandoned_catrs_heading translate="label">
449
+ <label>Abandoned cart from users</label>
450
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
451
+ <sort_order>5</sort_order>
452
+ <show_in_default>1</show_in_default>
453
+ <show_in_website>1</show_in_website>
454
+ <show_in_store>0</show_in_store>
455
+ </heading_abandoned_catrs_heading>
456
+ <notify_delay translate="label comment">
457
+ <label>Delay / Send Abandoned Cart SMS After</label>
458
+ <frontend_type>text</frontend_type>
459
+ <validate>validate-not-negative-number</validate>
460
+ <sort_order>10</sort_order>
461
+ <show_in_default>1</show_in_default>
462
+ <show_in_website>1</show_in_website>
463
+ <show_in_store>1</show_in_store>
464
+ <comment>(days). NB: this only affects unaltered abandoned carts.</comment>
465
+ </notify_delay>
466
+ <customer_groups translate="label">
467
+ <label>Customer Groups Restriction</label>
468
+ <frontend_type>multiselect</frontend_type>
469
+ <source_model>adminhtml/system_config_source_customer_group_multiselect</source_model>
470
+ <sort_order>50</sort_order>
471
+ <show_in_default>1</show_in_default>
472
+ <show_in_website>1</show_in_website>
473
+ <show_in_store>1</show_in_store>
474
+ </customer_groups>
475
+
476
+ </fields>
477
+ </abandoned_notifications>
478
+
479
+ <sms_log translate="label">
480
+ <label>EasyWebShop SMS LOG</label>
481
+ <frontend_type>text</frontend_type>
482
+ <sort_order>100</sort_order>
483
+ <show_in_default>1</show_in_default>
484
+ <show_in_website>1</show_in_website>
485
+ <show_in_store>1</show_in_store>
486
+ <fields>
487
+ <log_reset>
488
+ <frontend_type>button</frontend_type>
489
+ <frontend_model>easywebshopsms/adminhtml_system_config_log_reset</frontend_model>
490
+ <sort_order>1</sort_order>
491
+ <show_in_default>1</show_in_default>
492
+ <show_in_website>1</show_in_website>
493
+ <show_in_store>1</show_in_store>
494
+ </log_reset>
495
+ <log_info translate="label">
496
+ <label><![CDATA[EasyWebShop SMS LOG]]></label>
497
+ <sort_order>10</sort_order>
498
+ <frontend_model>easywebshopsms/adminhtml_system_config_log_log</frontend_model>
499
+ <frontend_type>label</frontend_type>
500
+ <show_in_default>1</show_in_default>
501
+ <show_in_website>1</show_in_website>
502
+ <show_in_store>1</show_in_store>
503
+ </log_info>
504
+ </fields>
505
+ </sms_log>
506
+ </groups>
507
+ </easywebshopsms>
508
+ </sections>
509
+ </config>
app/code/community/NthMobile/EasyWebShopSMS/sql/NthMobile_EasyWebShopSMS_setup/install-1.0.0.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 23.5.2016.
6
+ * Time: 11:31
7
+ */
8
+ $installer = $this;
9
+
10
+ $installer->startSetup();
11
+
12
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
13
+
14
+ $entityTypeId = $setup->getEntityTypeId('customer');
15
+ $attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
16
+ $attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
17
+
18
+ $installer->addAttribute("customer", "mobile_number", array(
19
+ "type" => "varchar",
20
+ "backend" => "",
21
+ "label" => "Mobile Number",
22
+ "input" => "text",
23
+ "source" => "",
24
+ "visible" => true,
25
+ "required" => false,
26
+ "default" => "",
27
+ "frontend" => "",
28
+ "unique" => false,
29
+ "note" => "Mobile Number"
30
+
31
+ ));
32
+
33
+ $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "mobile_number");
34
+
35
+
36
+ $setup->addAttributeToGroup(
37
+ $entityTypeId,
38
+ $attributeSetId,
39
+ $attributeGroupId,
40
+ 'mobile_number',
41
+ '999' //sort_order
42
+ );
43
+
44
+ $used_in_forms=array();
45
+
46
+ $used_in_forms[]="adminhtml_customer";
47
+ $used_in_forms[]="checkout_register";
48
+ $used_in_forms[]="customer_account_create";
49
+ $used_in_forms[]="customer_account_edit";
50
+ $used_in_forms[]="adminhtml_checkout";
51
+ $attribute->setData("used_in_forms", $used_in_forms)
52
+ ->setData("is_used_for_customer_segment", true)
53
+ ->setData("is_system", 0)
54
+ ->setData("is_user_defined", 1)
55
+ ->setData("is_visible", 1)
56
+ ->setData("sort_order", 100)
57
+ ;
58
+ $attribute->save();
59
+
60
+
61
+
62
+
63
+ $table = $installer->getConnection()
64
+ ->newTable($installer->getTable('easywebshopsms'))
65
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
66
+ 'identity' => true,
67
+ 'unsigned' => true,
68
+ 'nullable' => false,
69
+ 'primary' => true,
70
+ ), 'Id')
71
+ ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
72
+ 'nullable' => true,
73
+ ), 'Customer Id')
74
+ ->addColumn('event_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
75
+ 'nullable' => true,
76
+ ), 'Event Name')
77
+ ->addColumn('log_time', Varien_Db_Ddl_Table::TYPE_DATETIME, 255, array(
78
+ 'nullable' => false,
79
+ ), 'Log Time')
80
+ ->addColumn('sms_origin', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
81
+ 'nullable' => true,
82
+ ), 'SMS Origin')
83
+ ->addColumn('mobile_number', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
84
+ 'nullable' => true,
85
+ ), 'Mobile Number')
86
+ ->addColumn('message_text', Varien_Db_Ddl_Table::TYPE_VARCHAR, 500, array(
87
+ 'nullable' => true,
88
+ ), 'Message Text')
89
+ ->addColumn('sms_status_code', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
90
+ 'nullable' => true,
91
+ ), 'Sms Status Code')
92
+ ->addColumn('sms_status_message', Varien_Db_Ddl_Table::TYPE_VARCHAR, 200, array(
93
+ 'nullable' => true,
94
+ ), 'Sms Status Message')
95
+ ->addColumn('sms_sent', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
96
+ 'nullable' => true,
97
+ ), 'Sms Sent');
98
+ $installer->getConnection()->createTable($table);
99
+
100
+
101
+ $installer->endSetup();
app/code/community/NthMobile/EasyWebShopSMS/sql/NthMobile_EasyWebShopSMS_setup/upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ // Add a notification column to the sales_flat_quote table
7
+ $installer
8
+ ->getConnection()
9
+ ->addColumn(
10
+ $this->getTable('sales/quote'), 'easywebshopsms_abandoned_sale_notified', 'int(10) not null default 0'
11
+ );
12
+ $installer
13
+ ->getConnection()
14
+ ->addColumn(
15
+ $this->getTable('sales/quote'), 'easywebshopsms_abandoned_notified', 'int(10) not null default 0'
16
+ );
17
+
18
+ $installer->endSetup();
app/code/community/NthMobile/EasyWebShopSMS/sql/easywebshopsms_customer/install-1.0.0.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: pc
5
+ * Date: 23.5.2016.
6
+ * Time: 11:31
7
+ */
8
+ $installer = $this;
9
+ $installer->startSetup();
10
+ /*
11
+ * To change this license header, choose License Headers in Project Properties.
12
+ * To change this template file, choose Tools | Templates
13
+ * and open the template in the editor.
14
+ */
15
+ //attr1
16
+ $installer->addAttribute('customer','mobile_number', array(
17
+ 'type' => 'varchar',
18
+ 'label' => 'Mobile Number',
19
+ 'input' => 'text',
20
+ 'position' => 120,
21
+ 'required' => false,
22
+ 'is_system' => 0,
23
+ ));
24
+
25
+ $attribute1 = Mage::getSingleton('eav/config')->getAttribute('customer', 'mobile_number');
26
+
27
+ //
28
+ $attribute1->setData('used_in_forms', array(
29
+ 'adminhtml_customer',
30
+ 'checkout_register',
31
+ 'customer_account_create',
32
+ 'customer_account_edit',
33
+ ));
34
+
35
+ //
36
+ $attribute1->setData('is_user_defined', 0);
37
+
38
+ //
39
+ $attribute1->save();
40
+
41
+ Mage::log(__FILE__ . 'Update installed.');
42
+ $installer->endSetup();
app/design/adminhtml/base/default/layout/nthmobile_easywebshopsms.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.1" >
3
+
4
+ <easywebshopsms_adminhtml_easywebshopsmslogs_index>
5
+ <reference name="content">
6
+ <block type="easywebshopsms/adminhtml_easywebshopsmslogs" name="easywebshopsms_logs" />
7
+ </reference>
8
+ </easywebshopsms_adminhtml_easywebshopsmslogs_index>
9
+
10
+ <easywebshopsms_adminhtml_easywebshopsmsabandonedcarts_index>
11
+ <reference name="content">
12
+ <block type="easywebshopsms/adminhtml_easywebshopsmsabandonedcarts" name="easywebshopsms_abandonedcarts" />
13
+ </reference>
14
+ </easywebshopsms_adminhtml_easywebshopsmsabandonedcarts_index>
15
+ <easywebshopsms_adminhtml_easywebshopsmssaleabandonedcarts_index>
16
+ <reference name="content">
17
+ <block type="easywebshopsms/adminhtml_easywebshopsmssaleabandonedcarts" name="easywebshopsms_saleabandonedcarts" />
18
+ </reference>
19
+ </easywebshopsms_adminhtml_easywebshopsmssaleabandonedcarts_index>
20
+ </layout>
app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/abandonedcarts/list.phtml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0">
3
+ <tr>
4
+ <td style="<?php echo $this->getHeaderWidth() ?>"><?php echo $this->getHeaderHtml() ?></td>
5
+ <td class="form-buttons"><?php echo $this->getButtonsHtml() ?></td>
6
+ </tr>
7
+ </table>
8
+ </div>
9
+ <?php echo $this->getStoreSwitcherHtml() ?>
10
+ <div>
11
+ <?php echo $this->getGridHtml() ?>
12
+ </div>
app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/system/config/log/log.phtml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var NthMobile_EasyWebShopSMS_Block_Adminhtml_System_Config_Log_Log $this */
4
+ ?>
5
+ <style>
6
+ #row_easywebshopsms_sms_log_log_info {
7
+ margin-bottom: 10px;
8
+ }
9
+ #row_easywebshopsms_sms_log_log_info ul {
10
+ display: block;
11
+ width: 97%;
12
+ }
13
+
14
+ #row_easywebshopsms_sms_log_log_info ul li{
15
+ border: 1px solid rgba(0,0,0,0.1);
16
+ margin-bottom: 1px;
17
+ }
18
+ #row_easywebshopsms_sms_log_log_info ul li:hover{
19
+ background: rgba(155,155,155,0.1);
20
+ }
21
+ #row_easywebshopsms_sms_log_log_info ul li .details {
22
+ float: left;
23
+ width: 30%;
24
+ padding: 10px;
25
+ box-sizing: border-box;
26
+ }
27
+ #row_easywebshopsms_sms_log_log_info ul li .details-message {
28
+ float: left;
29
+ width: 70%;
30
+ padding: 10px;
31
+ box-sizing: border-box;
32
+ }
33
+
34
+ </style>
35
+ <div id="row_easywebshopsms_sms_log_log_info" style="max-height: 400px; overflow: auto; padding-bottom: 20px;">
36
+ <?php
37
+
38
+ $logFile = $this->getLogFile();
39
+ if (file_exists($logFile)) {
40
+ $lines = explode("__EOL__", file_get_contents($logFile));
41
+ $formatedText = "";
42
+ echo "<ul>";
43
+ $lines = array_reverse($lines, true);
44
+ foreach($lines as $line) {
45
+ if(empty($line) or strlen($line) < 10) continue;
46
+ $formatedText = "";
47
+ $ctx = explode("__CTX__",$line);
48
+ if(isset($ctx[1])) {
49
+ $data = json_decode($ctx[1], true);
50
+
51
+ if($data != null and isset($data['event_name'])) {
52
+ $formatedText .= "<div class='details'>";
53
+ $formatedText .= "<p><b>From:</b> ". @$data['sms_origin']."<br/><b>To:</b> ". @$data['mobile_number']."<br/><b>Time:</b> ". ((isset($data['time'])) ? date('Y-m-d H:i:s',$data['time']) : "") ."<br/><b>Event:</b> ". @$data['event_name']."<br/></p>";
54
+ $formatedText .= "</div>";
55
+ $formatedText .= "<div class='details-message'>";
56
+ $formatedText .= nl2br(trim(@$data['message_text'], "\n \r"));
57
+ $formatedText .= "</div>";
58
+ }
59
+ }
60
+ if(empty($formatedText)) {
61
+ $formatedText = nl2br(trim($line, "\n \r"));
62
+ }
63
+ echo "<li>".$formatedText. "</li>";
64
+ }
65
+ echo "</ul>";
66
+ } else {
67
+ echo "LOG file $logFile does not exist!";
68
+ }
69
+ ?>
70
+ </div>
71
+
app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/system/config/log/reset.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var NthMobile_EasyWebShopSMS_Block_Adminhtml_System_Config_Log_Reset $this */
4
+ ?>
5
+ <script type="text/javascript">
6
+ //<![CDATA[
7
+ function resetLogFile() {
8
+ new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
9
+ method: 'get',
10
+ onSuccess: function(transport){
11
+ document.getElementById("row_easywebshopsms_sms_log_log_info").innerHTML = transport.responseText;
12
+ }
13
+ });
14
+ }
15
+ //]]>
16
+ </script>
17
+
18
+ <?php echo $this->getButtonHtml() ?>
19
+
app/design/adminhtml/base/default/template/nthmobile/easywebshopsms/system/config/section/details.phtml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var NthMobile_EasyWebShopSMS_Block_Adminhtml_System_Config_Section_Details $this */
4
+
5
+ $helper = Mage::helper('easywebshopsms');
6
+ ?>
7
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('js/nthmobile/easywebshopsms/smscounter.js'); ?>" ></script>
8
+ <div class="easywebshopsms_container" style="display: block">
9
+ <table>
10
+ <tr>
11
+ <td>
12
+ <img width="350px" src="<?php echo $this->getSkinUrl('images/nthmobile/easywebshopsms/logo.jpg'); ?>" alt="NTH Mobile - EasyWebShop SMS" />
13
+ </td>
14
+ <td style="padding-left: 25px;">
15
+ <p>Use EasyWebShop SMS to send different SMS alerts from your web shop to your customers. If you have to send event-dependent notifications or create SMS marketing campaigns, EasyWebShop SMS is the right solution for you.</p>
16
+ <p>EasyWebShop SMS is a plugin based on SMS API technology.</p>
17
+ <br/>
18
+
19
+ <h4>Benefits</h4>
20
+ <p><b>Wish A Warm Welcome.</b> Send your customers a confirmatory SMS after they have successfully registered with your web shop.</p>
21
+ <p><b>Say Thank You.</b> Thank customers for choosing your product by sending a thank-you SMS after the first purchase.</p>
22
+ <p><b>Schedule your campaigns for later.</b> Send your SMS campaigns or alerts immediately, or optimize it by scheduling delivery later.</p>
23
+ <p><b>Engage Customers.</b> Send SMS reminders of unfinished purchases and take them to checkout to complete their purchase.</p>
24
+ <p><b>Personalize offers.</b> Inform customers of attractive discounts and special offers or notify them when their wish list item goes on sale.</p>
25
+ <p><b>Offer Incentives.</b> Stimulate customers who need extra incentive to purchase your goods/service by sending SMS notifications with special offers.</p>
26
+ <p><b>Demonstrate Reliability.</b> Reassure your customers by sending order-confirmation SMS following a purchase.</p>
27
+ <br/>
28
+ <p>What is the price and how do I get started?</p>
29
+ <p><?php echo
30
+ $helper->__(
31
+ "Click %shere%s to find out both!",
32
+ '<a target="_blank" href="' . $this->getSupportLink() . '">',
33
+ '</a>'
34
+ );
35
+ ?></p>
36
+
37
+
38
+ </td>
39
+ </tr>
40
+
41
+ </table>
42
+
43
+ </div>
app/design/frontend/base/default/layout/nthmobile_easywebshopsms.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ /**
5
+ * Global Layout Overrides to add custom structure blocks to layout template files
6
+ *
7
+ * @category
8
+ * @package
9
+ * @copyright
10
+ * @license
11
+ */
12
+ -->
13
+ <layout>
14
+
15
+ <default>
16
+ <block type="core/text_list" name="easywebshopsms.customer.fields" />
17
+
18
+ </default>
19
+ <customer_account_create>
20
+ <reference name="easywebshopsms.customer.fields">
21
+ <block type="customer/form_register" name="easywebshopsms_form_register" template="nthmobile/easywebshopsms/form/register.phtml"/>
22
+ </reference>
23
+ </customer_account_create>
24
+
25
+ <customer_account_edit>
26
+ <reference name="easywebshopsms.customer.fields">
27
+ <!-- <remove name="customer_edit" /> -->
28
+ <block type="customer/form_edit" name="easywebshopsms_form_edit" template="nthmobile/easywebshopsms/form/edit.phtml"/>
29
+ </reference>
30
+ </customer_account_edit>
31
+
32
+ <checkout_onepage_review>
33
+ <reference name="checkout.onepage.review.info.items.after">
34
+ <block type="checkout/onepage_review" name="easywebshopsms.checkout.onepage.review.info" template="nthmobile/easywebshopsms/onepage/info/mobile_number.phtml" />
35
+ </reference>
36
+ </checkout_onepage_review>
37
+
38
+
39
+
40
+ </layout>
app/design/frontend/base/default/template/nthmobile/easywebshopsms/form/edit.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+
2
+ <li>
3
+ <label for="mobile_number" class="required"><em>*</em><?php echo $this->__('Mobile Number') ?></label>
4
+ <div class="input-box">
5
+ <input type="mobile_number" autocapitalize="off" autocorrect="off" spellcheck="false" name="mobile_number" id="mobile_number" value="<?php echo $this->escapeHtml($this->getCustomer()->getMobileNumber()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Mobile Number')) ?>" class="input-text required-entry" />
6
+ </div>
7
+ </li>
8
+
app/design/frontend/base/default/template/nthmobile/easywebshopsms/form/register.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+
2
+ <li>
3
+ <label for="mobile_number"><?php echo $this->__('Mobile Number') ?></label>
4
+ <div class="input-box">
5
+ <input type="text" name="mobile_number" id="mobile_number" value="<?php echo $this->escapeHtml($this->getFormData()->getMobileNumber()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Mobile Number')) ?>" class="input-text" />
6
+ </div>
7
+ </li>
app/design/frontend/base/default/template/nthmobile/easywebshopsms/onepage/info/mobile_number.phtml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isCustomerLoggedIn()) :
2
+ echo "<br/>";
3
+ if ($this->getCustomer()->getMobileNumber() == ''){ ?>
4
+ <label for="mobile_number"><em>*</em> <?php echo $this->__('Want receive SMS notifications?'); ?></label>
5
+ <a href="<?php echo $this->getUrl('customer/account/edit'); ?>"><?php echo $this->__('Enter mobile number here.'); ?></a>
6
+ <?php } else if ($this->getCustomer()->getMobileNumber() != '') { ?>
7
+ <label for="mobile_number"><em>*</em> <?php echo $this->__('SMS notifications will be sent to: %s', $this->getCustomer()->getMobileNumber()); ?></label>
8
+ <a href="<?php echo $this->getUrl('customer/account/edit'); ?>"><?php echo $this->__('Change'); ?></a>
9
+ <?php } ?>
10
+
11
+ <?php endif; ?>
app/etc/modules/NthMobile_EasyWebShopSMS.xml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+
4
+ /**
5
+ * Magento
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * @category NthMobile
18
+ * @package NthMobile_EasyWebShopSMS
19
+ * @copyright Copyright (c) 2016 NTH mobile GmbH (http://www.nth-mobile.com/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+ -->
23
+
24
+ <config>
25
+ <modules>
26
+ <NthMobile_EasyWebShopSMS>
27
+ <active>true</active>
28
+ <codePool>community</codePool>
29
+ <version>1.0.1</version>
30
+ </NthMobile_EasyWebShopSMS>
31
+ </modules>
32
+ </config>
package.xml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>NthMobile_EasyWebShopSMS</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Use EasyWebShop SMS to send different SMS alerts from your web shop to your customers. If you have to send event-dependent notifications or create SMS marketing campaigns, EasyWebShop SMS is the right solution for you.&#xD;
10
+ &#xD;
11
+ EasyWebShop SMS is a plugin based on SMS API technology.</summary>
12
+ <description>Use EasyWebShop SMS to send different SMS alerts from your web shop to your customers. If you have to send event-dependent notifications or create SMS marketing campaigns, EasyWebShop SMS is the right solution for you.&#xD;
13
+ &#xD;
14
+ EasyWebShop SMS is a plugin based on SMS API technology.&#xD;
15
+ &#xD;
16
+ &#xD;
17
+ Benefits&#xD;
18
+ &#xD;
19
+ Wish A Warm Welcome. Send your customers a confirmatory SMS after they have successfully registered with your web shop.&#xD;
20
+ &#xD;
21
+ Say Thank You. Thank customers for choosing your product by sending a thank-you SMS after the first purchase.&#xD;
22
+ &#xD;
23
+ Schedule your campaigns for later. Send your SMS campaigns or alerts immediately, or optimize it by scheduling delivery later.&#xD;
24
+ &#xD;
25
+ Engage Customers. Send SMS reminders of unfinished purchases and take them to checkout to complete their purchase.&#xD;
26
+ &#xD;
27
+ Personalize offers. Inform customers of attractive discounts and special offers or notify them when their wish list item goes on sale.&#xD;
28
+ &#xD;
29
+ Offer Incentives. Stimulate customers who need extra incentive to purchase your goods/service by sending SMS notifications with special offers.&#xD;
30
+ &#xD;
31
+ Demonstrate Reliability. Reassure your customers by sending order-confirmation SMS following a purchase.</description>
32
+ <notes>First release</notes>
33
+ <authors><author><name>NTH</name><user>NTH_mobile</user><email>goran.kelekovic@nth.ch</email></author></authors>
34
+ <date>2016-11-09</date>
35
+ <time>09:20:39</time>
36
+ <contents><target name="magecommunity"><dir name="NthMobile"><dir name="EasyWebShopSMS"><dir name="Block"><dir name="Adminhtml"><file name="Easywebshopsmsabandonedcarts.php" hash="93afd65912b9050102b07903dbd81bf6"/><file name="Easywebshopsmslogs.php" hash="fe135abf217da7594d37c24ed5f6174e"/><file name="Easywebshopsmssaleabandonedcarts.php" hash="1d0139381065ffce6672a4062c4dbb76"/><dir name="Easywebshopsmsabandonedcarts"><file name="Grid.php" hash="3030fb87758bf749a0723f998d0e8e8d"/></dir><dir name="Easywebshopsmslogs"><file name="Grid.php" hash="1bf6bb6def9597a32e6064fe8ba739ce"/></dir><dir name="Easywebshopsmssaleabandonedcarts"><file name="Grid.php" hash="4f70df0868fc4f41f90d92d9419aa37b"/></dir><dir name="System"><dir name="Config"><dir name="Log"><file name="Log.php" hash="a6f9d978d6cefa89f41f6a12bb6bb6cd"/><file name="Reset.php" hash="be5bfc23fb06f6c660131fbb29de44ac"/></dir><dir name="Section"><file name="Details.php" hash="c8d286f3a36fafc4c51407309159d19e"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="ApiController.php" hash="bbb6942283e5adf12960b01468d2dd22"/><file name="TestController.php" hash="529dbe7a2564c89a214e2d0ca2e7164f"/><dir name="Adminhtml"><file name="EasywebshopsmsabandonedcartsController.php" hash="482e13ed2982930ff9acfb8df1bfb8dc"/><file name="EasywebshopsmslogsController.php" hash="3dcbf2facafd750c3bce9c0fb7a4a58b"/><file name="EasywebshopsmssaleabandonedcartsController.php" hash="7585967c6ab393cf380875ea08deabff"/></dir></dir><dir name="etc"><file name="config.xml" hash="4ca9a6ca5ce9341e364d92380e8a25a8"/><file name="system.xml" hash="766eb9156b0c3e0d4a2a67436fdc73d0"/></dir><dir name="Helper"><file name="Data.php" hash="1651c680029f3c6f7835190a7b555030"/></dir><dir name="Model"><file name="Bulkclient.php" hash="1d85f637a51f28c15616dfdcda16c365"/><file name="Config.php" hash="dbae3de50b2791649ccedcec8b3a1679"/><file name="Easywebshopsms.php" hash="5bd694fc8e157258c74e36033fb68f69"/><file name="Notifier.php" hash="8ba3733c60e4dd97b658cdf314d533ea"/><file name="Observer.php" hash="c9f7275760790f4db51c3043531f2b5a"/><dir name="Abandonedcart"><file name="Collection.php" hash="fe36d3064c1f6181c568187603291d92"/></dir><dir name="Logger"><file name="Factory.php" hash="6c4a88e693eb477d503c25965f47ff1c"/><file name="Logger.php" hash="ee1e0f2f0e2e3d823e2a90a8f2998919"/></dir><dir name="Resource"><file name="Easywebshopsms.php" hash="2238b1766a327d615401051cb0ea1e63"/><file name="Setup.php" hash="ace669f97ae7e870f0f1ecba672a6f87"/><dir name="Easywebshopsms"><file name="Collection.php" hash="00d2ead3b11fbdf96564ef93d25c5443"/></dir></dir><dir name="Resources"><file name="Setup.php" hash="f48ef8fe62d2c4e27b1a176a3cf091d4"/></dir></dir><dir name="sql"><dir name="easywebshopsms_customer"><file name="install-1.0.0.php" hash="87eec8a5b82a16a1be68616a13b2485f"/></dir><dir name="NthMobile_EasyWebShopSMS_setup"><file name="install-1.0.0.php" hash="de974cdde4ffd3e294c6adf3d00c7f75"/><file name="upgrade-1.0.0-1.0.1.php" hash="0a22178fa01cfbfeaf5ee8810998a86a"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="layout"><file name="nthmobile_easywebshopsms.xml" hash="fcfeeedeb773571ed732604793c9c329"/></dir><dir name="template"><dir name="nthmobile"><dir name="easywebshopsms"><dir name="abandonedcarts"><file name="list.phtml" hash="3fa7a086416234088d00fe5469fbec78"/></dir><dir name="system"><dir name="config"><dir name="log"><file name="log.phtml" hash="6ff536fa709de013740e7a0edeb48aa8"/><file name="reset.phtml" hash="ea703b9b01d881fb8cd61aabee989382"/></dir><dir name="section"><file name="details.phtml" hash="12b5f94424cb16729ccae4ffc05e389e"/></dir></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="nthmobile_easywebshopsms.xml" hash="069c5f21bead66fa83e0c1c50ed3fd63"/></dir><dir name="template"><dir name="nthmobile"><dir name="easywebshopsms"><dir name="form"><file name="edit.phtml" hash="f6836dfaf76128eef25a97cf072cc050"/><file name="register.phtml" hash="68b537cc3b3645753c2cf1c803f6b44c"/></dir><dir name="onepage"><dir name="info"><file name="mobile_number.phtml" hash="363f3982d0a5acba1092a335becdfdd1"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NthMobile_EasyWebShopSMS.xml" hash="385d41dde78f41839fa4fa4741a26418"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="images"><dir name="nthmobile"><dir name="easywebshopsms"><file name="logo.jpg" hash="1bca4624f77292f5ffea14002c14d36a"/></dir></dir></dir><dir name="js"><dir name="nthmobile"><dir name="easywebshopsms"><file name="smscounter.js" hash="ca32dbf291f172d1798baddbd1f67156"/></dir></dir></dir></dir></dir></dir></target></contents>
37
+ <compatible/>
38
+ <dependencies><required><php><min>5.4.1</min><max>6.0.0</max></php></required></dependencies>
39
+ </package>
skin/adminhtml/base/default/images/nthmobile/easywebshopsms/logo.jpg ADDED
Binary file
skin/adminhtml/base/default/js/nthmobile/easywebshopsms/smscounter.js ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var myEasywebshopsmsCounter = Class.create({
2
+ initialize: function(eventToObserve) // Is called when the page has finished loading by the Event.observe code below
3
+ {
4
+
5
+ var easywebshopsmsCounter = document.getElementById('easywebshopsmsCounter');
6
+ var easywebshopsmsCounterContainer = document.getElementById('easywebshopsmsCounterContainer');
7
+ var maxchars = 160;
8
+ var activeTextArea = false;
9
+ var textAreaId = false;
10
+
11
+ $('easywebshopsms_message_configuration').observe(eventToObserve, function(event) {
12
+ var textlength = 0;
13
+ activeTextArea = event.findElement('textarea');
14
+
15
+ if (activeTextArea) {
16
+
17
+ if (textAreaId !== activeTextArea.id) {
18
+ easywebshopsmsCounterContainer.remove(); //remove old easywebshopsmsCounterContainer
19
+ activeTextArea.insert({//reinitialize conterContainer in new position
20
+ after: easywebshopsmsCounterContainer
21
+ });
22
+ easywebshopsmsCounterContainer.show(); //snow easywebshopsmsCounter div at starts
23
+ }
24
+ textlength = activeTextArea.value.length;
25
+
26
+ easywebshopsmsCounter.update(textlength);
27
+
28
+ if (textlength <= (maxchars - 50)) {
29
+ $('easywebshopsmsCounter').setStyle({
30
+ fontSize: '150%',
31
+ fontWeight: 'normal',
32
+ color: '#0F910F'
33
+ });
34
+ $('easywebshopsmsTooLongAlert').hide();
35
+ }
36
+ else if (textlength <= (maxchars - 20)) {
37
+ $('easywebshopsmsCounter').setStyle({
38
+ fontWeight: 'bold',
39
+ color: '#FF8400'
40
+ });
41
+ $('easywebshopsmsTooLongAlert').hide();
42
+ } else {
43
+ $('easywebshopsmsCounter').setStyle({
44
+ fontWeight: ' bold',
45
+ color: '#B80000'
46
+ });
47
+ $('easywebshopsmsTooLongAlert').show();
48
+ }
49
+ }
50
+ });
51
+ }
52
+ });
53
+ // Global variable for the instance of the class
54
+ // Creating an instance of the class if the page has finished loading
55
+ Event.observe(window, 'load', function() {
56
+ document.getElementById('easywebshopsmsCounterContainer').hide(); //hide easywebshopsmsCounter div at start
57
+ new myEasywebshopsmsCounter('click');
58
+ new myEasywebshopsmsCounter('keyup');
59
+ });