simitracking_0117 - Version 4.0.0

Version Notes

4.0 Stable Version

Download this release

Release Info

Developer Hải Tạ Hoàng
Extension simitracking_0117
Version 4.0.0
Comparing to
See all releases


Version 4.0.0

Files changed (61) hide show
  1. app/code/local/Simi/Simitracking/Block/Adminhtml/Device.php +15 -0
  2. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit.php +42 -0
  3. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/.DS_Store +0 -0
  4. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Form.php +24 -0
  5. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Renderer/Datetime.php +28 -0
  6. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Renderer/Selectname.php +31 -0
  7. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tab/.DS_Store +0 -0
  8. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tab/Form.php +68 -0
  9. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tabs.php +27 -0
  10. app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Grid.php +119 -0
  11. app/code/local/Simi/Simitracking/Block/Adminhtml/Role.php +15 -0
  12. app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit.php +43 -0
  13. app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Form.php +20 -0
  14. app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Tab/Form.php +69 -0
  15. app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Tabs.php +22 -0
  16. app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Grid.php +61 -0
  17. app/code/local/Simi/Simitracking/Block/Adminhtml/User.php +15 -0
  18. app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit.php +35 -0
  19. app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Form.php +20 -0
  20. app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Tab/Form.php +106 -0
  21. app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Tabs.php +22 -0
  22. app/code/local/Simi/Simitracking/Block/Adminhtml/User/Grid.php +61 -0
  23. app/code/local/Simi/Simitracking/Helper/Data.php +142 -0
  24. app/code/local/Simi/Simitracking/Helper/Siminotification.php +199 -0
  25. app/code/local/Simi/Simitracking/Model/Api/Abandonedcarts.php +86 -0
  26. app/code/local/Simi/Simitracking/Model/Api/Addresses.php +54 -0
  27. app/code/local/Simi/Simitracking/Model/Api/Bestsellers.php +75 -0
  28. app/code/local/Simi/Simitracking/Model/Api/Customers.php +84 -0
  29. app/code/local/Simi/Simitracking/Model/Api/Orders.php +243 -0
  30. app/code/local/Simi/Simitracking/Model/Api/Permissions.php +30 -0
  31. app/code/local/Simi/Simitracking/Model/Api/Products.php +200 -0
  32. app/code/local/Simi/Simitracking/Model/Api/Sales.php +158 -0
  33. app/code/local/Simi/Simitracking/Model/Api/Salesforecasts.php +117 -0
  34. app/code/local/Simi/Simitracking/Model/Api/Staffs.php +100 -0
  35. app/code/local/Simi/Simitracking/Model/Api/Stores.php +21 -0
  36. app/code/local/Simi/Simitracking/Model/Customer.php +104 -0
  37. app/code/local/Simi/Simitracking/Model/Device.php +91 -0
  38. app/code/local/Simi/Simitracking/Model/Mysql4/Device.php +9 -0
  39. app/code/local/Simi/Simitracking/Model/Mysql4/Device/Collection.php +10 -0
  40. app/code/local/Simi/Simitracking/Model/Mysql4/Permission.php +9 -0
  41. app/code/local/Simi/Simitracking/Model/Mysql4/Permission/Collection.php +10 -0
  42. app/code/local/Simi/Simitracking/Model/Mysql4/Role.php +9 -0
  43. app/code/local/Simi/Simitracking/Model/Mysql4/Role/Collection.php +10 -0
  44. app/code/local/Simi/Simitracking/Model/Mysql4/User.php +9 -0
  45. app/code/local/Simi/Simitracking/Model/Mysql4/User/Collection.php +10 -0
  46. app/code/local/Simi/Simitracking/Model/Observer.php +75 -0
  47. app/code/local/Simi/Simitracking/Model/Permission.php +13 -0
  48. app/code/local/Simi/Simitracking/Model/Role.php +13 -0
  49. app/code/local/Simi/Simitracking/Model/Server.php +21 -0
  50. app/code/local/Simi/Simitracking/Model/User.php +13 -0
  51. app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/DeviceController.php +97 -0
  52. app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/RoleController.php +144 -0
  53. app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/UserController.php +178 -0
  54. app/code/local/Simi/Simitracking/controllers/IndexController.php +60 -0
  55. app/code/local/Simi/Simitracking/controllers/RestController.php +55 -0
  56. app/code/local/Simi/Simitracking/etc/adminhtml.xml +84 -0
  57. app/code/local/Simi/Simitracking/etc/config.xml +149 -0
  58. app/code/local/Simi/Simitracking/etc/system.xml +73 -0
  59. app/code/local/Simi/Simitracking/sql/simitracking_setup/mysql4-install-0.1.0.php +71 -0
  60. app/code/local/Simi/Simitracking/sql/simitracking_setup/mysql4-upgrade-0.1.1-0.1.2.php +9 -0
  61. package.xml +18 -0
app/code/local/Simi/Simitracking/Block/Adminhtml/Device.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+
5
+ */
6
+ class Simi_Simitracking_Block_Adminhtml_Device extends Mage_Adminhtml_Block_Widget_Grid_Container
7
+ {
8
+ public function __construct(){
9
+ $this->_controller = 'adminhtml_device';
10
+ $this->_blockGroup = 'simitracking';
11
+ $this->_headerText = Mage::helper('simiconnector')->__('Tracking Device Manager');
12
+ parent::__construct();
13
+ $this->removeButton('add');
14
+ }
15
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+
5
+ */
6
+ class Simi_Simitracking_Block_Adminhtml_Device_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
7
+
8
+ public function __construct() {
9
+ parent::__construct();
10
+
11
+ $this->_objectId = 'id';
12
+ $this->_blockGroup = 'simitracking';
13
+ $this->_controller = 'adminhtml_device';
14
+
15
+ $this->removeButton('reset');
16
+ $this->removeButton('save');
17
+ $this->_formScripts[] = "
18
+ function toggleEditor() {
19
+ if (tinyMCE.getInstanceById('device_content') == null)
20
+ tinyMCE.execCommand('mceAddControl', false, 'device_content');
21
+ else
22
+ tinyMCE.execCommand('mceRemoveControl', false, 'device_content');
23
+ }
24
+
25
+ function saveAndContinueEdit(){
26
+ editForm.submit($('edit_form').action+'back/edit/');
27
+ }
28
+ ";
29
+ }
30
+
31
+ /**
32
+ * get text to show in header when edit an device
33
+ *
34
+ * @return string
35
+ */
36
+ public function getHeaderText() {
37
+ if (Mage::registry('device_data') && Mage::registry('device_data')->getId())
38
+ return Mage::helper('simitracking')->__("View Device '%s'", $this->htmlEscape(Mage::registry('device_data')->getId()));
39
+ return Mage::helper('simitracking')->__('Add Device');
40
+ }
41
+
42
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/.DS_Store ADDED
Binary file
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Form.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+
6
+ */
7
+ class Simi_Simitracking_Block_Adminhtml_Device_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
8
+
9
+ protected function _prepareForm() {
10
+ $form = new Varien_Data_Form(array(
11
+ 'id' => 'edit_form',
12
+ 'action' => $this->getUrl('*/*/save', array(
13
+ 'id' => $this->getRequest()->getParam('id'),
14
+ )),
15
+ 'method' => 'post',
16
+ 'enctype' => 'multipart/form-data'
17
+ ));
18
+
19
+ $form->setUseContainer(true);
20
+ $this->setForm($form);
21
+ return parent::_prepareForm();
22
+ }
23
+
24
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Renderer/Datetime.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_Device_Edit_Renderer_Datetime extends Varien_Data_Form_Element_Abstract {
4
+
5
+ /**
6
+ * Retrieve Element HTML
7
+ *
8
+ * @return string
9
+ */
10
+ public function getElementHtml()
11
+ {
12
+ $values = explode(',', $this->getEscapedValue());
13
+ $html = $this->getBold() ? '<strong>' : '';
14
+ foreach($values as $id => $value){
15
+ $dateFormatIso = Mage::app()->getLocale()
16
+ ->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
17
+ $time = Mage::app()->getLocale()->date($value, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($dateFormatIso);
18
+ $html .= $time . '<br/>';
19
+ }
20
+
21
+ $html.= $this->getBold() ? '</strong>' : '';
22
+ $html.= $this->getAfterElementHtml();
23
+ return $html;
24
+ }
25
+
26
+ }
27
+
28
+
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Renderer/Selectname.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_Device_Edit_Renderer_Selectname extends Varien_Data_Form_Element_Abstract {
4
+
5
+ /**
6
+ * Retrieve Element HTML
7
+ *
8
+ * @return string
9
+ */
10
+ public function getElementHtml()
11
+ {
12
+
13
+ $html = $this->getBold() ? '<strong>' : '';
14
+ $values = explode(',', $this->getEscapedValue());
15
+ foreach($values as $id => $value){
16
+ $countryId = $value;
17
+ $country = Mage::getResourceModel('directory/country_collection')
18
+ ->loadByStore()
19
+ ->addFieldToFilter('country_id',$countryId)
20
+ ->getFirstItem();
21
+ $html .= $country->getName().'<br/>';
22
+ }
23
+
24
+ $html .= $this->getBold() ? '</strong>' : '';
25
+ $html .= $this->getAfterElementHtml();
26
+ return $html;
27
+ }
28
+
29
+ }
30
+
31
+
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tab/.DS_Store ADDED
Binary file
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tab/Form.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+
5
+ */
6
+ class Simi_Simitracking_Block_Adminhtml_Device_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
7
+
8
+ protected function _prepareForm() {
9
+ $form = new Varien_Data_Form();
10
+ $this->setForm($form);
11
+
12
+
13
+ if (Mage::getSingleton('adminhtml/session')->getDeviceData()) {
14
+ $data = Mage::getSingleton('adminhtml/session')->getDeviceData();
15
+ Mage::getSingleton('adminhtml/session')->setDeviceData(null);
16
+ } elseif (Mage::registry('device_data'))
17
+ $data = Mage::registry('device_data')->getData();
18
+
19
+ $fieldset = $form->addFieldset('device_form', array('legend' => Mage::helper('simitracking')->__('Device information')));
20
+ $fieldset->addType('datetime', 'Simi_Simitracking_Block_Adminhtml_Device_Edit_Renderer_Datetime');
21
+ $fieldset->addType('selectname', 'Simi_Simitracking_Block_Adminhtml_Device_Edit_Renderer_Selectname');
22
+
23
+ $stores = Mage::getModel('core/store')->getCollection();
24
+
25
+ $list_store = array();
26
+ foreach ($stores as $store) {
27
+ $list_store[] = array(
28
+ 'value' => $store->getId(),
29
+ 'label' => $store->getName(),
30
+ );
31
+ }
32
+ $fieldset->addField('storeview_id', 'select', array(
33
+ 'label' => Mage::helper('simitracking')->__('Store View'),
34
+ 'name' => 'storeview_id',
35
+ 'values' => $list_store,
36
+ 'disabled' => true,
37
+ 'onchange' => 'clearDevices()'
38
+ ));
39
+
40
+ $fieldset->addField('plaform_id', 'select', array(
41
+ 'label' => Mage::helper('simitracking')->__('Device Type'),
42
+ 'name' => 'plaform_id',
43
+ 'values' => array(
44
+ array('value' => 1, 'label' => Mage::helper('simitracking')->__('iPhone')),
45
+ array('value' => 2, 'label' => Mage::helper('simitracking')->__('iPad')),
46
+ array('value' => 3, 'label' => Mage::helper('simitracking')->__('Android')),
47
+ ),
48
+ 'disabled' => true,
49
+ ));
50
+
51
+ $fieldset->addField('device_token', 'label', array(
52
+ 'label' => Mage::helper('simitracking')->__('Device Token'),
53
+ ));
54
+
55
+ $fieldset->addField('device_user_agent', 'label', array(
56
+ 'label' => Mage::helper('simitracking')->__('Device User Agent'),
57
+ ));
58
+
59
+ $fieldset->addField('created_time', 'datetime', array(
60
+ 'label' => Mage::helper('simitracking')->__('Updated Date'),
61
+ 'bold' => true,
62
+ 'name' => 'created_date',
63
+ ));
64
+ $form->setValues($data);
65
+ return parent::_prepareForm();
66
+ }
67
+
68
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tabs.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+
6
+ */
7
+ class Simi_Simitracking_Block_Adminhtml_Device_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
8
+
9
+ public function __construct() {
10
+ parent::__construct();
11
+ $this->setId('simitracking_tabs');
12
+ $this->setDestElementId('edit_form');
13
+ $this->setTitle(Mage::helper('simitracking')->__('Device Information'));
14
+ }
15
+
16
+ /**
17
+ */
18
+ protected function _beforeToHtml() {
19
+ $this->addTab('form_section', array(
20
+ 'label' => Mage::helper('simitracking')->__('Device Information'),
21
+ 'title' => Mage::helper('simitracking')->__('Device Information'),
22
+ 'content' => $this->getLayout()->createBlock('simitracking/adminhtml_device_edit_tab_form')->toHtml(),
23
+ ));
24
+ return parent::_beforeToHtml();
25
+ }
26
+
27
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Grid.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+
5
+ */
6
+ class Simi_Simitracking_Block_Adminhtml_Device_Grid extends Mage_Adminhtml_Block_Widget_Grid {
7
+
8
+ public function __construct() {
9
+ parent::__construct();
10
+ $this->setId('deviceGrid');
11
+ $this->setDefaultSort('entity_id');
12
+ $this->setDefaultDir('DESC');
13
+ $this->setSaveParametersInSession(true);
14
+ }
15
+
16
+ /**
17
+ * prepare collection for block to display
18
+ *
19
+ */
20
+ protected function _prepareCollection() {
21
+ $collection = Mage::getModel('simitracking/device')->getCollection()->addFieldToFilter('is_key_token','0');
22
+ $this->setCollection($collection);
23
+ return parent::_prepareCollection();
24
+ }
25
+
26
+ /**
27
+ * prepare columns for this grid
28
+ *
29
+ */
30
+ protected function _prepareColumns() {
31
+ $this->addColumn('entity_id', array(
32
+ 'header' => Mage::helper('simitracking')->__('ID'),
33
+ 'align' => 'right',
34
+ 'width' => '50px',
35
+ 'index' => 'entity_id',
36
+ ));
37
+
38
+ $this->addColumn('user_email', array(
39
+ 'header' => Mage::helper('simitracking')->__('Customer Email'),
40
+ 'width' => '150px',
41
+ 'index' => 'user_email'
42
+ ));
43
+
44
+ $this->addColumn('plaform_id', array(
45
+ 'header' => Mage::helper('simitracking')->__('Device Type'),
46
+ 'align' => 'left',
47
+ 'width' => '100px',
48
+ 'index' => 'plaform_id',
49
+ 'type' => 'options',
50
+ 'options' => array(
51
+ 3 => Mage::helper('simitracking')->__('Android'),
52
+ 1 => Mage::helper('simitracking')->__('iPhone'),
53
+ 2 => Mage::helper('simitracking')->__('iPad'),
54
+ ),
55
+ ));
56
+
57
+ $this->addColumn('device_user_agent', array(
58
+ 'header' => Mage::helper('simitracking')->__('Device User Agent'),
59
+ 'width' => '150px',
60
+ 'index' => 'device_user_agent'
61
+ ));
62
+
63
+ $this->addColumn('created_time', array(
64
+ 'header' => Mage::helper('simitracking')->__('Created Date'),
65
+ 'width' => '150px',
66
+ 'align' => 'right',
67
+ 'index' => 'created_time',
68
+ 'type' => 'datetime'
69
+ ));
70
+
71
+
72
+
73
+ $this->addColumn('action', array(
74
+ 'header' => Mage::helper('simitracking')->__('Action'),
75
+ 'width' => '80px',
76
+ 'type' => 'action',
77
+ 'getter' => 'getId',
78
+ 'actions' => array(
79
+ array(
80
+ 'caption' => Mage::helper('simitracking')->__('View'),
81
+ 'url' => array('base' => '*/*/edit'),
82
+ 'field' => 'id'
83
+ )),
84
+ 'filter' => false,
85
+ 'sortable' => false,
86
+ 'index' => 'stores',
87
+ 'is_system' => true,
88
+ ));
89
+ return parent::_prepareColumns();
90
+ }
91
+
92
+ /**
93
+ * prepare mass action for this grid
94
+ *
95
+ * @return Magestore_Madapter_Block_Adminhtml_Madapter_Grid
96
+ */
97
+ protected function _prepareMassaction() {
98
+ $this->setMassactionIdField('simitracking');
99
+ $this->getMassactionBlock()->setFormFieldName('simitracking');
100
+
101
+ $this->getMassactionBlock()->addItem('delete', array(
102
+ 'label' => Mage::helper('simitracking')->__('Delete'),
103
+ 'url' => $this->getUrl('*/*/massDelete'),
104
+ 'confirm' => Mage::helper('simitracking')->__('Are you sure?')
105
+ ));
106
+
107
+ return $this;
108
+ }
109
+
110
+ /**
111
+ * get url for each row in grid
112
+ *
113
+ * @return string
114
+ */
115
+ public function getRowUrl($row) {
116
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
117
+ }
118
+
119
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Role.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+
4
+ */
5
+ class Simi_Simitracking_Block_Adminhtml_Role extends Mage_Adminhtml_Block_Widget_Grid_Container {
6
+
7
+ public function __construct() {
8
+ $this->_controller = 'adminhtml_role';
9
+ $this->_blockGroup = 'simitracking';
10
+ $this->_headerText = Mage::helper('simitracking')->__('Role');
11
+ $this->_addButtonLabel = Mage::helper('simitracking')->__('Add Role');
12
+ parent::__construct();
13
+ }
14
+
15
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Simi_Simitracking_Block_Adminhtml_Role_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
5
+
6
+ public function __construct() {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'simitracking';
11
+ $this->_controller = 'adminhtml_role';
12
+ $this->_updateButton('delete', 'label', Mage::helper('simitracking')->__('Delete'));
13
+ $this->_addButton('saveandcontinue', array(
14
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
15
+ 'onclick' => 'saveAndContinueEdit()',
16
+ 'class' => 'save',
17
+ ), -100);
18
+ $this->_formScripts[] = "
19
+ function toggleEditor() {
20
+ if (tinyMCE.getInstanceById('notice_content') == null)
21
+ tinyMCE.execCommand('mceAddControl', false, 'notice_content');
22
+ else
23
+ tinyMCE.execCommand('mceRemoveControl', false, 'notice_content');
24
+ }
25
+
26
+ function saveAndContinueEdit(){
27
+ editForm.submit($('edit_form').action+'back/edit/');
28
+ }
29
+ ";
30
+ }
31
+
32
+ /**
33
+ * get text to show in header when edit an item
34
+ *
35
+ * @return string
36
+ */
37
+ public function getHeaderText() {
38
+ if (Mage::registry('role_data') && Mage::registry('role_data')->getId())
39
+ return Mage::helper('simitracking')->__("Edit Role '%s'", $this->htmlEscape(Mage::registry('role_data')->getRoleTitle()));
40
+ return Mage::helper('simitracking')->__('Add Role');
41
+ }
42
+
43
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Form.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_Role_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
4
+
5
+ protected function _prepareForm() {
6
+ $form = new Varien_Data_Form(array(
7
+ 'id' => 'edit_form',
8
+ 'action' => $this->getUrl('*/*/save', array(
9
+ 'id' => $this->getRequest()->getParam('id'),
10
+ )),
11
+ 'method' => 'post',
12
+ 'enctype' => 'multipart/form-data'
13
+ ));
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+
20
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Tab/Form.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_Role_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
4
+
5
+ protected function _prepareForm() {
6
+ $form = new Varien_Data_Form();
7
+ $this->setForm($form);
8
+
9
+ if (Mage::getSingleton('adminhtml/session')->getConnectorData()) {
10
+ $data = Mage::getSingleton('adminhtml/session')->getConnectorData();
11
+ Mage::getSingleton('adminhtml/session')->setConnectorData(null);
12
+ } elseif (Mage::registry('role_data'))
13
+ $data = Mage::registry('role_data')->getData();
14
+
15
+
16
+ $fieldset = $form->addFieldset('simitracking_form', array('legend' => Mage::helper('simitracking')->__('Role information')));
17
+
18
+ $fieldset->addField('role_title', 'text', array(
19
+ 'label' => Mage::helper('simitracking')->__('Title'),
20
+ 'class' => 'required-entry',
21
+ 'required' => true,
22
+ 'name' => 'role_title',
23
+ ));
24
+
25
+ $fieldset->addField('is_owner_role', 'select', array(
26
+ 'label' => Mage::helper('simitracking')->__('Tracking View'),
27
+ 'class' => 'required-entry',
28
+ 'required' => true,
29
+ 'name' => 'is_owner_role',
30
+ 'values' => array(
31
+ array('value' => 0, 'label' => Mage::helper('simitracking')->__('Sales Staff')),
32
+ array('value' => 1, 'label' => Mage::helper('simitracking')->__('Store Owner')),
33
+ )
34
+ ));
35
+
36
+ foreach (Mage::getModel('simitracking/permission')->getCollection()->addFieldToFilter('role_id', $data['entity_id']) as $permissionModel) {
37
+ $data['simi_permission_id_' . $permissionModel->getPermissionId()] = '1';
38
+ }
39
+ foreach (Mage::helper('simitracking')->getPermissionSections() as $sectionIndex => $section) {
40
+ $fieldset = $form->addFieldset('section_' . $sectionIndex, array('legend' => $section));
41
+ foreach (Mage::helper('simitracking')->getPermissions() as $permissionId => $permission) {
42
+ $generatedId = 'simi_permission_id_' . $permissionId;
43
+ if ($data[$generatedId] != '1')
44
+ $data[$generatedId] = '0';
45
+ if ($permission['section'] == $sectionIndex)
46
+ $fieldset->addField($generatedId, 'select', array(
47
+ 'label' => $permission['title'],
48
+ 'required' => false,
49
+ 'name' => $generatedId,
50
+ 'onchange' => 'this.className= \'permission_allowed_\' + this.options[this.selectedIndex].value',
51
+ 'class' => 'permission_allowed_' . $data[$generatedId],
52
+ 'values' => array(
53
+ array(
54
+ 'value' => '0',
55
+ 'label' => Mage::helper('simitracking')->__('Not Allowed')
56
+ ),
57
+ array(
58
+ 'value' => '1',
59
+ 'label' => Mage::helper('simitracking')->__('Allowed')
60
+ ))
61
+ ));
62
+ }
63
+ }
64
+
65
+ $form->setValues($data);
66
+ return parent::_prepareForm();
67
+ }
68
+
69
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Tabs.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_Role_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
4
+
5
+ public function __construct() {
6
+ parent::__construct();
7
+ $this->setId('notice_tabs');
8
+ $this->setDestElementId('edit_form');
9
+ $this->setTitle(Mage::helper('simitracking')->__('Role Information'));
10
+ }
11
+
12
+
13
+ protected function _beforeToHtml() {
14
+ $this->addTab('form_section', array(
15
+ 'label' => Mage::helper('simitracking')->__('Role Information'),
16
+ 'title' => Mage::helper('simitracking')->__('Role Information'),
17
+ 'content' => $this->getLayout()->createBlock('simitracking/adminhtml_role_edit_tab_form')->toHtml(),
18
+ ));
19
+ return parent::_beforeToHtml();
20
+ }
21
+
22
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Grid.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+
5
+ */
6
+ class Simi_Simitracking_Block_Adminhtml_Role_Grid extends Mage_Adminhtml_Block_Widget_Grid {
7
+
8
+ public function __construct() {
9
+ parent::__construct();
10
+ $this->setId('noticeGrid');
11
+ $this->setDefaultSort('entity_id');
12
+ $this->setDefaultDir('ASC');
13
+ $this->setSaveParametersInSession(true);
14
+ }
15
+
16
+ protected function _prepareCollection() {
17
+ $webId = 0;
18
+ $collection = Mage::getModel('simitracking/role')->getCollection();
19
+ if ($this->getRequest()->getParam('website')) {
20
+ $webId = $this->getRequest()->getParam('website');
21
+ $collection->addFieldToFilter('website_id', array('eq' => $webId));
22
+ }
23
+ $this->setCollection($collection);
24
+ return parent::_prepareCollection();
25
+ }
26
+
27
+ protected function _prepareColumns() {
28
+ $this->addColumn('entity_id', array(
29
+ 'header' => Mage::helper('simitracking')->__('ID'),
30
+ 'align' => 'right',
31
+ 'width' => '50px',
32
+ 'index' => 'entity_id',
33
+ ));
34
+
35
+ $this->addColumn('role_title', array(
36
+ 'header' => Mage::helper('simitracking')->__('Role Title'),
37
+ 'align' => 'left',
38
+ 'index' => 'role_title',
39
+ ));
40
+
41
+ return parent::_prepareColumns();
42
+ }
43
+
44
+ protected function _prepareMassaction() {
45
+ $this->setMassactionIdField('entity_id');
46
+ $this->getMassactionBlock()->setFormFieldName('simitracking');
47
+
48
+ $this->getMassactionBlock()->addItem('delete', array(
49
+ 'label' => Mage::helper('simitracking')->__('Delete'),
50
+ 'url' => $this->getUrl('*/*/massDelete'),
51
+ 'confirm' => Mage::helper('simitracking')->__('Are you sure?')
52
+ ));
53
+
54
+ return $this;
55
+ }
56
+
57
+ public function getRowUrl($row) {
58
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
59
+ }
60
+
61
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/User.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+
4
+ */
5
+ class Simi_Simitracking_Block_Adminhtml_User extends Mage_Adminhtml_Block_Widget_Grid_Container {
6
+
7
+ public function __construct() {
8
+ $this->_controller = 'adminhtml_user';
9
+ $this->_blockGroup = 'simitracking';
10
+ $this->_headerText = Mage::helper('simitracking')->__('User');
11
+ $this->_addButtonLabel = Mage::helper('simitracking')->__('Add User');
12
+ parent::__construct();
13
+ }
14
+
15
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_User_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
4
+
5
+ public function __construct() {
6
+ parent::__construct();
7
+
8
+ $this->_objectId = 'id';
9
+ $this->_blockGroup = 'simitracking';
10
+ $this->_controller = 'adminhtml_user';
11
+ $this->_updateButton('delete', 'label', Mage::helper('simitracking')->__('Delete'));
12
+ $this->_addButton('saveandcontinue', array(
13
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
14
+ 'onclick' => 'saveAndContinueEdit()',
15
+ 'class' => 'save',
16
+ ), -100);
17
+ $this->_formScripts[] = "
18
+ function saveAndContinueEdit(){
19
+ editForm.submit($('edit_form').action+'back/edit/');
20
+ }
21
+ ";
22
+ }
23
+
24
+ /**
25
+ * get text to show in header when edit an item
26
+ *
27
+ * @return string
28
+ */
29
+ public function getHeaderText() {
30
+ if (Mage::registry('user_data') && Mage::registry('user_data')->getId())
31
+ return Mage::helper('simitracking')->__("Edit User '%s'", $this->htmlEscape(Mage::registry('user_data')->getUserTitle()));
32
+ return Mage::helper('simitracking')->__('Add User');
33
+ }
34
+
35
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Form.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_User_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
4
+
5
+ protected function _prepareForm() {
6
+ $form = new Varien_Data_Form(array(
7
+ 'id' => 'edit_form',
8
+ 'action' => $this->getUrl('*/*/save', array(
9
+ 'id' => $this->getRequest()->getParam('id'),
10
+ )),
11
+ 'method' => 'post',
12
+ 'enctype' => 'multipart/form-data'
13
+ ));
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+
20
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Tab/Form.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_User_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
4
+
5
+ protected function _prepareForm() {
6
+ $form = new Varien_Data_Form();
7
+ $this->setForm($form);
8
+
9
+ if (Mage::getSingleton('adminhtml/session')->getConnectorData()) {
10
+ $data = Mage::getSingleton('adminhtml/session')->getConnectorData();
11
+ Mage::getSingleton('adminhtml/session')->setConnectorData(null);
12
+ } elseif (Mage::registry('user_data'))
13
+ $data = Mage::registry('user_data')->getData();
14
+
15
+ $fieldset = $form->addFieldset('simitracking_form', array('legend' => Mage::helper('simitracking')->__('User information')));
16
+
17
+ $fieldset->addField('status', 'select', array(
18
+ 'label' => Mage::helper('simitracking')->__('Enable'),
19
+ 'name' => 'status',
20
+ 'values' => array(
21
+ array('value' => 1, 'label' => Mage::helper('simitracking')->__('Yes')),
22
+ array('value' => 0, 'label' => Mage::helper('simitracking')->__('No')),
23
+ )
24
+ ));
25
+
26
+ $fieldset->addField('user_title', 'text', array(
27
+ 'label' => Mage::helper('simitracking')->__('Title'),
28
+ 'class' => 'required-entry',
29
+ 'required' => true,
30
+ 'name' => 'user_title',
31
+ ));
32
+
33
+ $roleArray = array();
34
+ foreach (Mage::getModel('simitracking/role')->getCollection() as $role) {
35
+ $roleArray[] = array(
36
+ 'value' => $role->getId(),
37
+ 'label' => $role->getRoleTitle()
38
+ );
39
+ }
40
+ if (count($roleArray) == 0)
41
+ $fieldset->addField('role_id', 'text', array(
42
+ 'label' => Mage::helper('simitracking')->__('Role'),
43
+ 'class' => 'required-entry',
44
+ 'required' => true,
45
+ 'disabled' => true,
46
+ 'name' => 'role_id',
47
+ ));
48
+ else
49
+ $fieldset->addField('role_id', 'select', array(
50
+ 'label' => Mage::helper('simitracking')->__('Role'),
51
+ 'class' => 'required-entry',
52
+ 'required' => true,
53
+ 'values' => $roleArray,
54
+ 'name' => 'role_id',
55
+ ));
56
+
57
+ $fieldset->addField('user_profile_image', 'image', array(
58
+ 'label' => Mage::helper('simitracking')->__('Profile Image'),
59
+ 'required' => false,
60
+ 'note' => Mage::helper('simitracking')->__('Square image. Eg. 200px x 200px'),
61
+ 'name' => 'user_profile_image_co',
62
+ ));
63
+
64
+ $fieldset->addField('user_email', 'text', array(
65
+ 'label' => Mage::helper('simitracking')->__('Customer Email'),
66
+ 'class' => 'required-entry validate-email',
67
+ 'required' => true,
68
+ 'note' => Mage::helper('simitracking')->__('Customer account with this Email has permissions as the Role assigned'),
69
+ 'name' => 'user_email',
70
+ ));
71
+ $existed_device = Mage::getModel('simitracking/device')->getCollection()
72
+ ->addFieldToFilter('is_key_token', 1)
73
+ ->addFieldToFilter('user_email', $data['user_email'])->getFirstItem();
74
+ if ($existed_device->getId()) {
75
+ //$url = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL);
76
+ $url = $this->builderQuery = Mage::getModel('core/store')->getCollection()->getFirstItem()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
77
+ $jsonString = '{"user_email":"' . $data['user_email'] . '","url":"' . $url . '","session_id":"' . $existed_device->getData('session_id') . '"}';
78
+ $encodedString = base64_encode($jsonString);
79
+ $loginQR = '<img src="http://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=' . $encodedString . '" />';
80
+ $fieldset->addField('qrcode', 'label', array(
81
+ 'label' => Mage::helper('simitracking')->__('Login QR Code'),
82
+ 'required' => false,
83
+ 'bold' => true,
84
+ 'name' => 'qrcode',
85
+ 'after_element_html' => $loginQR
86
+ ));
87
+ }
88
+
89
+
90
+ if (!isset($data['is_receive_notification']))
91
+ $data['is_receive_notification'] = 1;
92
+ $fieldset->addField('is_receive_notification', 'select', array(
93
+ 'label' => Mage::helper('simitracking')->__('Receive Notification'),
94
+ 'name' => 'is_receive_notification',
95
+ 'values' => array(
96
+ array('value' => 1, 'label' => Mage::helper('simitracking')->__('Yes')),
97
+ array('value' => 0, 'label' => Mage::helper('simitracking')->__('No')),
98
+ )
99
+ ));
100
+
101
+
102
+ $form->setValues($data);
103
+ return parent::_prepareForm();
104
+ }
105
+
106
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Tabs.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Block_Adminhtml_User_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
4
+
5
+ public function __construct() {
6
+ parent::__construct();
7
+ $this->setId('notice_tabs');
8
+ $this->setDestElementId('edit_form');
9
+ $this->setTitle(Mage::helper('simitracking')->__('User Information'));
10
+ }
11
+
12
+
13
+ protected function _beforeToHtml() {
14
+ $this->addTab('form_section', array(
15
+ 'label' => Mage::helper('simitracking')->__('User Information'),
16
+ 'title' => Mage::helper('simitracking')->__('User Information'),
17
+ 'content' => $this->getLayout()->createBlock('simitracking/adminhtml_user_edit_tab_form')->toHtml(),
18
+ ));
19
+ return parent::_beforeToHtml();
20
+ }
21
+
22
+ }
app/code/local/Simi/Simitracking/Block/Adminhtml/User/Grid.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+
5
+ */
6
+ class Simi_Simitracking_Block_Adminhtml_User_Grid extends Mage_Adminhtml_Block_Widget_Grid {
7
+
8
+ public function __construct() {
9
+ parent::__construct();
10
+ $this->setId('noticeGrid');
11
+ $this->setDefaultSort('entity_id');
12
+ $this->setDefaultDir('ASC');
13
+ $this->setSaveParametersInSession(true);
14
+ }
15
+
16
+ protected function _prepareCollection() {
17
+ $webId = 0;
18
+ $collection = Mage::getModel('simitracking/user')->getCollection();
19
+ if ($this->getRequest()->getParam('website')) {
20
+ $webId = $this->getRequest()->getParam('website');
21
+ $collection->addFieldToFilter('website_id', array('eq' => $webId));
22
+ }
23
+ $this->setCollection($collection);
24
+ return parent::_prepareCollection();
25
+ }
26
+
27
+ protected function _prepareColumns() {
28
+ $this->addColumn('entity_id', array(
29
+ 'header' => Mage::helper('simitracking')->__('ID'),
30
+ 'align' => 'right',
31
+ 'width' => '50px',
32
+ 'index' => 'entity_id',
33
+ ));
34
+
35
+ $this->addColumn('user_title', array(
36
+ 'header' => Mage::helper('simitracking')->__('User Title'),
37
+ 'align' => 'left',
38
+ 'index' => 'user_title',
39
+ ));
40
+
41
+ return parent::_prepareColumns();
42
+ }
43
+
44
+ protected function _prepareMassaction() {
45
+ $this->setMassactionIdField('entity_id');
46
+ $this->getMassactionBlock()->setFormFieldName('simitracking');
47
+
48
+ $this->getMassactionBlock()->addItem('delete', array(
49
+ 'label' => Mage::helper('simitracking')->__('Delete'),
50
+ 'url' => $this->getUrl('*/*/massDelete'),
51
+ 'confirm' => Mage::helper('simitracking')->__('Are you sure?')
52
+ ));
53
+
54
+ return $this;
55
+ }
56
+
57
+ public function getRowUrl($row) {
58
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
59
+ }
60
+
61
+ }
app/code/local/Simi/Simitracking/Helper/Data.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ const SALE_TRACKING = '1';
6
+ const TOTAL_DETAIL = '2';
7
+ const SALE_DETAIL = '3';
8
+ const PRODUCT_LIST = '4';
9
+ const PRODUCT_DETAIL = '5';
10
+ const PRODUCT_EDIT = '6';
11
+ const CUSTOMER_LIST = '7';
12
+ const CUSTOMER_DETAIL = '8';
13
+ const CUSTOMER_EDIT = '9';
14
+ const CUSTOMER_ADDRESS_LIST = '10';
15
+ const CUSTOMER_ADDRESS_EDIT = '11';
16
+ const CUSTOMER_ADDRESS_REMOVE = '12';
17
+ const ORDER_LIST = '13';
18
+ const ORDER_DETAIL = '14';
19
+ const INVOICE_ORDER = '15';
20
+ const SHIP_ORDER = '16';
21
+ const CANCEL_ORDER = '17';
22
+ const HOLD_ORDER = '18';
23
+ const UNHOLD_ORDER = '19';
24
+ const ABANDONED_CARTS_LIST = '20';
25
+ const ABANDONED_CARTS_DETAILS = '21';
26
+
27
+ public function getPermissionSections() {
28
+ return array(
29
+ "1" => $this->__("Store Statistics"),
30
+ "2" => $this->__("Catalog Management"),
31
+ "3" => $this->__("Customer Management"),
32
+ "4" => $this->__("Order Management"),
33
+ "5" => $this->__("Abandoned Carts"),
34
+ );
35
+ }
36
+
37
+ public function getPermissions() {
38
+ return array(
39
+ self::SALE_TRACKING => array(
40
+ "title" => $this->__("Sales Tracking"),
41
+ "section" => "1"),
42
+ self::TOTAL_DETAIL => array(
43
+ "title" => $this->__("Totals Details"),
44
+ "section" => "1"),
45
+ self::SALE_DETAIL => array(
46
+ "title" => $this->__("Lifetime Sales"),
47
+ "section" => "1"),
48
+ self::PRODUCT_LIST => array(
49
+ "title" => $this->__("Product List"),
50
+ "section" => "2"),
51
+ self::PRODUCT_DETAIL => array(
52
+ "title" => $this->__("Product Details"),
53
+ "section" => "2"),
54
+ self::PRODUCT_EDIT => array(
55
+ "title" => $this->__("Product Edit"),
56
+ "section" => "2"),
57
+ self::CUSTOMER_LIST => array(
58
+ "title" => $this->__("Customer List"),
59
+ "section" => "3"),
60
+ self::CUSTOMER_DETAIL => array(
61
+ "title" => $this->__("Customer Details"),
62
+ "section" => "3"),
63
+ self::CUSTOMER_EDIT => array(
64
+ "title" => $this->__("Customer Edit"),
65
+ "section" => "3"),
66
+ self::CUSTOMER_ADDRESS_LIST => array(
67
+ "title" => $this->__("Customer Address List"),
68
+ "section" => "3"),
69
+ /*
70
+ self::CUSTOMER_ADDRESS_EDIT => array(
71
+ "title" => $this->__("Customer Address Edit"),
72
+ "section" => "3"),
73
+ self::CUSTOMER_ADDRESS_REMOVE => array(
74
+ "title" => $this->__("Customer Address Remove"),
75
+ "section" => "3"),
76
+ */
77
+ self::ORDER_LIST => array(
78
+ "title" => $this->__("Order List"),
79
+ "section" => "4"),
80
+ self::ORDER_DETAIL => array(
81
+ "title" => $this->__("Order Detail"),
82
+ "section" => "4"),
83
+ self::INVOICE_ORDER => array(
84
+ "title" => $this->__("Invoice Order"),
85
+ "section" => "4"),
86
+ self::SHIP_ORDER => array(
87
+ "title" => $this->__("Ship Order"),
88
+ "section" => "4"),
89
+ self::CANCEL_ORDER => array(
90
+ "title" => $this->__("Cancel Order"),
91
+ "section" => "4"),
92
+ self::HOLD_ORDER => array(
93
+ "title" => $this->__("Hold Order"),
94
+ "section" => "4"),
95
+ self::UNHOLD_ORDER => array(
96
+ "title" => $this->__("Unhold Order"),
97
+ "section" => "4"),
98
+ self::ABANDONED_CARTS_LIST => array(
99
+ "title" => $this->__("Abandoned Carts List"),
100
+ "section" => "5"),
101
+ self::ABANDONED_CARTS_DETAILS => array(
102
+ "title" => $this->__("Abandoned Carts Details"),
103
+ "section" => "5"),
104
+ );
105
+ }
106
+
107
+ /*
108
+ * $permissionId follow the list at const list
109
+ */
110
+
111
+ public function isAllowed($permissionId) {
112
+ if (!Mage::getSingleton('customer/session')->isLoggedIn())
113
+ throw new Exception(Mage::helper('simitracking')->__('Please Login'), 4);
114
+ $user = Mage::getModel('simitracking/user')->getCollection()
115
+ ->addFieldToFilter('user_email', Mage::getSingleton('customer/session')->getCustomer()->getEmail())->getFirstItem();
116
+ $permissionList = Mage::getModel('simitracking/permission')->getCollection()
117
+ ->addFieldToFilter('role_id', $user->getRoleId())
118
+ ->addFieldToFilter('permission_id', $permissionId);
119
+ if (!$permissionList->count())
120
+ throw new Exception($this->__('Permission Denied'), 4);
121
+ }
122
+
123
+ /*
124
+ * Continue session
125
+ */
126
+
127
+ public function continueSessionWithSessionId($sessionId) {
128
+ $existed_device = Mage::getModel('simitracking/device')->getCollection()->addFieldToFilter('session_id', $sessionId)->getFirstItem();
129
+ if ($existed_device->getId()) {
130
+ /*
131
+ if (time() > $existed_device->getData('session_deadline')) {
132
+ throw new Exception(Mage::helper('simitracking')->__('Your session has expired. Please log in again'), 4);
133
+ }
134
+ */
135
+ $customer = Mage::helper('simiconnector/customer')->getCustomerByEmail($existed_device->getData('user_email'));
136
+ if ($customer->getId()) {
137
+ Mage::helper('simiconnector/customer')->loginByCustomer($customer);
138
+ return true;
139
+ }
140
+ }
141
+ }
142
+ }
app/code/local/Simi/Simitracking/Helper/Siminotification.php ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Helper_Siminotification extends Mage_Core_Helper_Abstract {
4
+
5
+ public function sendNoticeNewOrder($orderId) {
6
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
7
+ $data = array();
8
+ $data['order_id'] = $orderId;
9
+ $data['notice_title'] = $this->__('New Order Created: #').$orderModel->getData('increment_id').$this->__(', GrandTotal: ').$orderModel->getData('base_currency_code').$orderModel->getData('base_grand_total');
10
+ $data['notice_content'] = $this->__('New Order Created: #').$orderModel->getData('increment_id').$this->__(', GrandTotal: ').$orderModel->getData('base_currency_code').$orderModel->getData('base_grand_total');
11
+ $trans = $this->send($data);
12
+ return $trans;
13
+ }
14
+
15
+ public function sendNoticeProcessingOrder($orderId) {
16
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
17
+ $data = array();
18
+ $data['order_id'] = $orderId;
19
+ $data['notice_title'] = $this->__('Order Processing: #').$orderModel->getData('increment_id').$this->__(', GrandTotal: ').$orderModel->getData('base_currency_code').$orderModel->getData('base_grand_total');
20
+ $data['notice_content'] = $this->__('Order Processing: #').$orderModel->getData('increment_id').$this->__(', GrandTotal: ').$orderModel->getData('base_currency_code').$orderModel->getData('base_grand_total');
21
+ $trans = $this->send($data);
22
+ return $trans;
23
+ }
24
+
25
+ public function sendNoticeCompletedOrder($orderId) {
26
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
27
+ $data = array();
28
+ $data['order_id'] = $orderId;
29
+ $data['notice_title'] = $this->__('Order Completed: #').$orderModel->getData('increment_id').$this->__(', GrandTotal: ').$orderModel->getData('base_currency_code').$orderModel->getData('base_grand_total');
30
+ $data['notice_content'] = $this->__('Order Completed: #').$orderModel->getData('increment_id').$this->__(', GrandTotal: ').$orderModel->getData('base_currency_code').$orderModel->getData('base_grand_total');
31
+ $trans = $this->send($data);
32
+ return $trans;
33
+ }
34
+
35
+ public function send($data) {
36
+ $customerModelCollection = Mage::getModel('simitracking/user')->getCollection()->addFieldToFilter('is_receive_notification',1);
37
+ $emailArray = array();
38
+ foreach ($customerModelCollection as $customerModel) {
39
+ $emailArray[] = $customerModel->getData('user_email');
40
+ }
41
+ $collectionDevice = Mage::getModel('simitracking/device')->getCollection()->addFieldToFilter('is_key_token', array('neq' => 1))->addFieldToFilter('user_email', array('in' => $emailArray));
42
+ $collectionDevice2 = Mage::getModel('simitracking/device')->getCollection()->addFieldToFilter('is_key_token', array('neq' => 1))->addFieldToFilter('user_email', array('in' => $emailArray));
43
+ $collectionDevice->addFieldToFilter('plaform_id', array('neq' => 3));
44
+ $collectionDevice2->addFieldToFilter('plaform_id', array('eq' => 3));
45
+ $resultIOS = $this->sendIOS($collectionDevice, $data);
46
+ $resultAndroid = $this->sendAndroid($collectionDevice2, $data);
47
+ if ($resultIOS || $resultAndroid)
48
+ return true;
49
+ else
50
+ return false;
51
+ }
52
+
53
+ public function sendIOS($collectionDevice, $data) {
54
+ $ch = $this->getDirPEMfile();
55
+ $dir = $this->getDirPEMPassfile();
56
+ $body['aps'] = array(
57
+ 'alert' => $data['notice_title'],
58
+ 'sound' => 'default',
59
+ 'badge' => 0,
60
+ 'title' => $data['notice_title'],
61
+ 'message' => $data['notice_content'],
62
+ 'order_id' => $data['order_id']
63
+ );
64
+ $payload = json_encode($body);
65
+ $totalDevice = 0;
66
+
67
+ $i = 0;
68
+ $tokenArray = array();
69
+ $sentsuccess = true;
70
+ foreach ($collectionDevice as $item) {
71
+ if ($i == 1) {
72
+ $result = $this->repeatSendiOS($tokenArray, $payload, $ch, $dir);
73
+ if (!$result)
74
+ $sentsuccess = false;
75
+ $i = 0;
76
+ $tokenArray = array();
77
+ }
78
+ $pos = strpos($item->getDeviceToken(), 'nontoken');
79
+ if ((strlen($item->getDeviceToken()) < 70) && ($pos === false))
80
+ $tokenArray[] = $item->getDeviceToken();
81
+ $i++;
82
+ $totalDevice++;
83
+ }
84
+ if ($i <= 1)
85
+ $result = $this->repeatSendiOS($tokenArray, $payload, $ch, $dir);
86
+ if (!$result)
87
+ $sentsuccess = false;
88
+
89
+ return true;
90
+ }
91
+
92
+ public function repeatSendiOS($tokenArray, $payload, $ch, $dir) {
93
+ $ctx = stream_context_create();
94
+ stream_context_set_option($ctx, 'ssl', 'local_cert', $ch);
95
+ $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
96
+ if (!$fp) {
97
+ return;
98
+ }
99
+ foreach ($tokenArray as $deviceToken) {
100
+ $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
101
+ // Send it to the server
102
+ $result = fwrite($fp, $msg, strlen($msg));
103
+ if (!$result) {
104
+ return false;
105
+ }
106
+ }
107
+ fclose($fp);
108
+ return true;
109
+ }
110
+
111
+ public function repeatSendAnddroid($total, $collectionDevice, $message) {
112
+ while (true) {
113
+ $from_user = 0;
114
+ $check = $total - 999;
115
+ if ($check <= 0) {
116
+ //send to (total+from_user) user from_user
117
+ $is = $this->sendTurnAnroid($collectionDevice, $from_user, $from_user + $total, $message);
118
+ if ($is == false) {
119
+ return false;
120
+ }
121
+ return true;
122
+ } else {
123
+ //send to 100 user from_user
124
+ $is = $this->sendTurnAnroid($collectionDevice, $from_user, $from_user + 999, $message);
125
+ if ($is == false) {
126
+ return false;
127
+ }
128
+ $total = $check;
129
+ $from_user += 999;
130
+ }
131
+ }
132
+ }
133
+
134
+ public function sendTurnAnroid($collectionDevice, $from, $to, $message) {
135
+ $registrationIDs = array();
136
+ for ($i = $from; $i <= $to; $i++) {
137
+ $item = $collectionDevice[$i];
138
+ $pos = strpos($item['device_token'], 'nontoken');
139
+ if ($pos === false)
140
+ $registrationIDs[] = $item['device_token'];
141
+ }
142
+
143
+ $url = 'https://android.googleapis.com/gcm/send';
144
+ $fields = array(
145
+ 'registration_ids' => $registrationIDs,
146
+ 'data' => array("message" => $message),
147
+ );
148
+ $api_key = 'AIzaSyAy10doIjM2f6ghh-_-PHKURQslm-A3JCk';
149
+ $headers = array(
150
+ 'Authorization: key=' . $api_key,
151
+ 'Content-Type: application/json');
152
+
153
+ $result = '';
154
+ try {
155
+ $ch = curl_init();
156
+ curl_setopt($ch, CURLOPT_URL, $url);
157
+ curl_setopt($ch, CURLOPT_POST, true);
158
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
159
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
160
+ // Disabling SSL Certificate support temporarly
161
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
162
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
163
+ $result = curl_exec($ch);
164
+ curl_close($ch);
165
+ } catch (Exception $e) {
166
+
167
+ }
168
+
169
+ $re = json_decode($result);
170
+
171
+ if ($re == NULL || $re->success == 0) {
172
+ return false;
173
+ }
174
+ return true;
175
+ }
176
+
177
+ public function sendAndroid($collectionDevice, $data) {
178
+ $total = count($collectionDevice);
179
+ $message = $data;
180
+
181
+ $this->repeatSendAnddroid($total, $collectionDevice->getData(), $message);
182
+ return true;
183
+ }
184
+
185
+ public function getDirPEMfile() {
186
+ return Mage::getBaseDir('media') . DS . 'simi' . DS . 'simitracking' . DS . 'pem' . DS . 'push.pem';
187
+ }
188
+
189
+ public function getDirPEMPassfile() {
190
+ return Mage::getBaseDir('media') . DS . 'simi' . DS . 'simitracking' . DS . 'pem' . DS . 'ios' . DS . 'pass_pem.config';
191
+ }
192
+
193
+ public function getConfig($nameConfig, $storeviewId = null) {
194
+ if (!$storeviewId)
195
+ $storeviewId = Mage::app()->getStore()->getId();
196
+ return Mage::getStoreConfig($nameConfig, $storeviewId);
197
+ }
198
+
199
+ }
app/code/local/Simi/Simitracking/Model/Api/Abandonedcarts.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Simi_Simitracking_Model_Api_Abandonedcarts extends Simi_Simiconnector_Model_Api_Customers {
4
+
5
+ public function setBuilderQuery() {
6
+ $data = $this->getData();
7
+ if ($data['resourceid']) {
8
+ Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::ABANDONED_CARTS_DETAILS);
9
+ $this->builderQuery = Mage::getModel('sales/quote')->load($data['resourceid']);
10
+ } else {
11
+ Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::ABANDONED_CARTS_LIST);
12
+ $this->builderQuery = Mage::getModel('sales/quote')->getCollection()->addFieldToFilter('grand_total', array('neq' => '0'));
13
+ }
14
+ }
15
+
16
+ /*
17
+ * Show Abandoned Cart Detail
18
+ */
19
+
20
+ public function show() {
21
+ $entity = $this->builderQuery;
22
+ $data = $this->getData();
23
+ $parameters = $data['params'];
24
+ $fields = array();
25
+ if (isset($parameters['fields']) && $parameters['fields']) {
26
+ $fields = explode(',', $parameters['fields']);
27
+ }
28
+ $info = $entity->toArray($fields);
29
+ //product array
30
+ $productCollection = $this->builderQuery->getItemsCollection();
31
+ $productInfoArray = array();
32
+ foreach ($productCollection as $entity) {
33
+ if ($entity->getData('parent_item_id') != NULL)
34
+ continue;
35
+
36
+ $options = array();
37
+ if (version_compare(Mage::getVersion(), '1.5.0.0', '>=') === true) {
38
+ $helper = Mage::helper('catalog/product_configuration');
39
+ if ($entity->getProductType() == "simple") {
40
+ $options = Mage::helper('simiconnector/checkout')->convertOptionsCart($helper->getCustomOptions($entity));
41
+ } elseif ($entity->getProductType() == "configurable") {
42
+ $options = Mage::helper('simiconnector/checkout')->convertOptionsCart($helper->getConfigurableOptions($entity));
43
+ } elseif ($entity->getProductType() == "bundle") {
44
+ $options = Mage::helper('simiconnector/checkout')->getOptions($entity);
45
+ }
46
+ } else {
47
+ if ($entity->getProductType() != "bundle") {
48
+ $options = Mage::helper('simiconnector/checkout')->getUsedProductOption($entity);
49
+ } else {
50
+ $options = Mage::helper('simiconnector/checkout')->getOptions($entity);
51
+ }
52
+ }
53
+
54
+ $pro_price = $entity->getCalculationPrice();
55
+ if (Mage::helper('tax')->displayCartPriceInclTax() || Mage::helper('tax')->displayCartBothPrices()) {
56
+ $pro_price = Mage::helper('checkout')->getSubtotalInclTax($entity);
57
+ }
58
+
59
+ $quoteitem = $entity->toArray($fields);
60
+ $quoteitem['option'] = $options;
61
+ $quoteitem['image'] = Mage::helper('simiconnector/products')->getImageProduct($entity->getProduct(), null, $parameters['image_width'], $parameters['image_height']);
62
+ $productInfoArray[] = $quoteitem;
63
+ }
64
+ $info['products'] = $productInfoArray;
65
+ return $this->getDetail($info);
66
+ }
67
+
68
+ protected function _whereFilter(&$query, $parameters)
69
+ {
70
+ if (isset($parameters[self::FILTER])) {
71
+ foreach ($parameters[self::FILTER] as $key => $value) {
72
+ if ($key == 'or') {
73
+ $filters = array();
74
+ foreach ($value as $k => $v) {
75
+ $filters[] = $this->_addCondition($k, $v, true);
76
+ }
77
+ if (count($filters)) $query->addFieldToFilter($filters);
78
+ } else {
79
+ $filter = $this->_addCondition($key, $value);
80
+ $query->addFieldToFilter($key, $filter);
81
+ }
82
+ }
83
+ }
84
+ }
85
+
86
+ }
app/code/local/Simi/Simitracking/Model/Api/Addresses.php ADDED
@@ -0,0 +1,54 @@