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
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device.php +15 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit.php +42 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/.DS_Store +0 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Form.php +24 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Renderer/Datetime.php +28 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Renderer/Selectname.php +31 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tab/.DS_Store +0 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tab/Form.php +68 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Edit/Tabs.php +27 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Device/Grid.php +119 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Role.php +15 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit.php +43 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Form.php +20 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Tab/Form.php +69 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Edit/Tabs.php +22 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/Role/Grid.php +61 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/User.php +15 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit.php +35 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Form.php +20 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Tab/Form.php +106 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/User/Edit/Tabs.php +22 -0
- app/code/local/Simi/Simitracking/Block/Adminhtml/User/Grid.php +61 -0
- app/code/local/Simi/Simitracking/Helper/Data.php +142 -0
- app/code/local/Simi/Simitracking/Helper/Siminotification.php +199 -0
- app/code/local/Simi/Simitracking/Model/Api/Abandonedcarts.php +86 -0
- app/code/local/Simi/Simitracking/Model/Api/Addresses.php +54 -0
- app/code/local/Simi/Simitracking/Model/Api/Bestsellers.php +75 -0
- app/code/local/Simi/Simitracking/Model/Api/Customers.php +84 -0
- app/code/local/Simi/Simitracking/Model/Api/Orders.php +243 -0
- app/code/local/Simi/Simitracking/Model/Api/Permissions.php +30 -0
- app/code/local/Simi/Simitracking/Model/Api/Products.php +200 -0
- app/code/local/Simi/Simitracking/Model/Api/Sales.php +158 -0
- app/code/local/Simi/Simitracking/Model/Api/Salesforecasts.php +117 -0
- app/code/local/Simi/Simitracking/Model/Api/Staffs.php +100 -0
- app/code/local/Simi/Simitracking/Model/Api/Stores.php +21 -0
- app/code/local/Simi/Simitracking/Model/Customer.php +104 -0
- app/code/local/Simi/Simitracking/Model/Device.php +91 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/Device.php +9 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/Device/Collection.php +10 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/Permission.php +9 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/Permission/Collection.php +10 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/Role.php +9 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/Role/Collection.php +10 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/User.php +9 -0
- app/code/local/Simi/Simitracking/Model/Mysql4/User/Collection.php +10 -0
- app/code/local/Simi/Simitracking/Model/Observer.php +75 -0
- app/code/local/Simi/Simitracking/Model/Permission.php +13 -0
- app/code/local/Simi/Simitracking/Model/Role.php +13 -0
- app/code/local/Simi/Simitracking/Model/Server.php +21 -0
- app/code/local/Simi/Simitracking/Model/User.php +13 -0
- app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/DeviceController.php +97 -0
- app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/RoleController.php +144 -0
- app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/UserController.php +178 -0
- app/code/local/Simi/Simitracking/controllers/IndexController.php +60 -0
- app/code/local/Simi/Simitracking/controllers/RestController.php +55 -0
- app/code/local/Simi/Simitracking/etc/adminhtml.xml +84 -0
- app/code/local/Simi/Simitracking/etc/config.xml +149 -0
- app/code/local/Simi/Simitracking/etc/system.xml +73 -0
- app/code/local/Simi/Simitracking/sql/simitracking_setup/mysql4-install-0.1.0.php +71 -0
- app/code/local/Simi/Simitracking/sql/simitracking_setup/mysql4-upgrade-0.1.1-0.1.2.php +9 -0
- 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 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
*/
|
6 |
+
class Simi_Simitracking_Model_Api_Addresses extends Simi_Simiconnector_Model_Api_Addresses {
|
7 |
+
|
8 |
+
public function setBuilderQuery() {
|
9 |
+
$data = $this->getData();
|
10 |
+
if ($data['resourceid']) {
|
11 |
+
|
12 |
+
} else {
|
13 |
+
if (!isset($data['params']) || (!isset($data['params']['customer_id']))) {
|
14 |
+
throw new Exception($this->_helper->__('Please send the Customer ID'), 4);
|
15 |
+
} else {
|
16 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::CUSTOMER_ADDRESS_LIST);
|
17 |
+
$customer = Mage::getModel('customer/customer')->load($data['params']['customer_id']);
|
18 |
+
$addressArray = array();
|
19 |
+
$billing = $customer->getPrimaryBillingAddress();
|
20 |
+
if ($billing) {
|
21 |
+
$addressArray[] = $billing->getId();
|
22 |
+
}
|
23 |
+
$shipping = $customer->getPrimaryShippingAddress();
|
24 |
+
if ($shipping) {
|
25 |
+
$addressArray[] = $shipping->getId();
|
26 |
+
}
|
27 |
+
foreach ($customer->getAddresses() as $index => $address) {
|
28 |
+
$addressArray[] = $index;
|
29 |
+
}
|
30 |
+
$this->builderQuery = Mage::getModel('customer/address')->getCollection()
|
31 |
+
->addFieldToFilter('entity_id', array('in' => $addressArray));
|
32 |
+
}
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
/*
|
39 |
+
* View Address List
|
40 |
+
*/
|
41 |
+
|
42 |
+
public function index() {
|
43 |
+
$result = parent::index();
|
44 |
+
$addresses = $result['addresses'];
|
45 |
+
foreach ($addresses as $index => $address) {
|
46 |
+
$addressModel = Mage::getModel('customer/address')->load($address['entity_id']);
|
47 |
+
$addresses[$index] = array_merge($address, Mage::helper('simiconnector/address')->getAddressDetail($addressModel, null));
|
48 |
+
}
|
49 |
+
$result['addresses'] = $addresses;
|
50 |
+
return $result;
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Bestsellers.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Api_Bestsellers extends Simi_Simiconnector_Model_Api_Addresses {
|
4 |
+
|
5 |
+
public function setBuilderQuery() {
|
6 |
+
$data = $this->getData();
|
7 |
+
$this->_helperProduct = Mage::helper('simiconnector/products');
|
8 |
+
$this->_helperProduct->setData($data);
|
9 |
+
|
10 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::PRODUCT_LIST);
|
11 |
+
$this->builderQuery = $collection = Mage::getResourceModel('reports/product_collection')
|
12 |
+
->addAttributeToSelect('*')
|
13 |
+
->addOrderedQty()->addMinimalPrice()
|
14 |
+
->addTaxPercents()
|
15 |
+
->addStoreFilter()
|
16 |
+
->setOrder('ordered_qty', 'desc');
|
17 |
+
if (isset($data['params']['store_id']) && $data['params']['store_id'] != '0' && $data['params']['store_id'] != '') {
|
18 |
+
$this->builderQuery->addStoreFilter($data['params']['store_id']);
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
public function index() {
|
23 |
+
$collection = $this->builderQuery;
|
24 |
+
$this->filter();
|
25 |
+
$data = $this->getData();
|
26 |
+
$parameters = $data['params'];
|
27 |
+
$page = 1;
|
28 |
+
if (isset($parameters[self::PAGE]) && $parameters[self::PAGE]) {
|
29 |
+
$page = $parameters[self::PAGE];
|
30 |
+
}
|
31 |
+
|
32 |
+
$limit = self::DEFAULT_LIMIT;
|
33 |
+
if (isset($parameters[self::LIMIT]) && $parameters[self::LIMIT]) {
|
34 |
+
$limit = $parameters[self::LIMIT];
|
35 |
+
}
|
36 |
+
|
37 |
+
$offset = $limit * ($page - 1);
|
38 |
+
if (isset($parameters[self::OFFSET]) && $parameters[self::OFFSET]) {
|
39 |
+
$offset = $parameters[self::OFFSET];
|
40 |
+
}
|
41 |
+
$collection->setPageSize($offset + $limit);
|
42 |
+
|
43 |
+
$all_ids = array();
|
44 |
+
$info = array();
|
45 |
+
$total = $collection->getSize();
|
46 |
+
|
47 |
+
if ($offset > $total)
|
48 |
+
throw new Exception($this->_helper->__('Invalid method.'), 4);
|
49 |
+
|
50 |
+
$fields = array();
|
51 |
+
if (isset($parameters['fields']) && $parameters['fields']) {
|
52 |
+
$fields = explode(',', $parameters['fields']);
|
53 |
+
}
|
54 |
+
|
55 |
+
$check_limit = 0;
|
56 |
+
$check_offset = 0;
|
57 |
+
|
58 |
+
foreach ($collection as $entity) {
|
59 |
+
if (++$check_offset <= $offset) {
|
60 |
+
continue;
|
61 |
+
}
|
62 |
+
if (++$check_limit > $limit)
|
63 |
+
break;
|
64 |
+
|
65 |
+
if (!$entity->getName()) {
|
66 |
+
$entity = Mage::getModel('catalog/product')->load($entity->getId());
|
67 |
+
}
|
68 |
+
$info_detail = $entity->toArray($fields);
|
69 |
+
$all_ids[] = $entity->getId();
|
70 |
+
$info[] = $info_detail;
|
71 |
+
}
|
72 |
+
return $this->getList($info, $all_ids, $total, $limit, $offset);
|
73 |
+
}
|
74 |
+
|
75 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Customers.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
*/
|
6 |
+
class Simi_Simitracking_Model_Api_Customers extends Simi_Simiconnector_Model_Api_Customers {
|
7 |
+
|
8 |
+
protected $_DEFAULT_ORDER = 'entity_id';
|
9 |
+
protected $_RETURN_MESSAGE;
|
10 |
+
|
11 |
+
public function setBuilderQuery() {
|
12 |
+
$data = $this->getData();
|
13 |
+
if ($data['resourceid']) {
|
14 |
+
$this->builderQuery = Mage::getModel('customer/customer')->load($data['resourceid']);
|
15 |
+
} else {
|
16 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::CUSTOMER_LIST);
|
17 |
+
$this->builderQuery = Mage::getModel('customer/customer')->getCollection();
|
18 |
+
$this->builderQuery->addAttributeToSelect(array('prefix', 'firstname', 'middlename', 'lastname', 'suffix'));
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
/*
|
23 |
+
* New Customer
|
24 |
+
*/
|
25 |
+
|
26 |
+
public function store() {
|
27 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::CUSTOMER_EDIT);
|
28 |
+
$data = $this->getData();
|
29 |
+
$customer = Mage::getModel('simitracking/customer')->newCustomer($data);
|
30 |
+
$this->builderQuery = $customer;
|
31 |
+
$this->_RETURN_MESSAGE = Mage::helper('customer')->__("Customer Created");
|
32 |
+
return $this->show();
|
33 |
+
}
|
34 |
+
|
35 |
+
/*
|
36 |
+
* Update Customer
|
37 |
+
*/
|
38 |
+
|
39 |
+
public function update() {
|
40 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::CUSTOMER_EDIT);
|
41 |
+
$data = $this->getData();
|
42 |
+
$customer = Mage::getModel('simitracking/customer')->updateCustomer($data, $this->builderQuery);
|
43 |
+
$this->builderQuery = $customer;
|
44 |
+
$this->_RETURN_MESSAGE = Mage::helper('customer')->__('The account information has been saved.');
|
45 |
+
return $this->show();
|
46 |
+
}
|
47 |
+
|
48 |
+
/*
|
49 |
+
* Show customer Detail
|
50 |
+
*/
|
51 |
+
|
52 |
+
public function show() {
|
53 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::CUSTOMER_DETAIL);
|
54 |
+
$entity = $this->builderQuery;
|
55 |
+
$data = $this->getData();
|
56 |
+
$parameters = $data['params'];
|
57 |
+
$fields = array();
|
58 |
+
if (isset($parameters['fields']) && $parameters['fields']) {
|
59 |
+
$fields = explode(',', $parameters['fields']);
|
60 |
+
}
|
61 |
+
$info = $entity->toArray($fields);
|
62 |
+
if (isset($info['default_billing']))
|
63 |
+
$info['billing_address_data'] = Mage::helper('simiconnector/address')->getAddressDetail(Mage::getModel('customer/address')->load($info['default_billing']));
|
64 |
+
if (isset($info['default_shipping']))
|
65 |
+
$info['shipping_address_data'] = Mage::helper('simiconnector/address')->getAddressDetail(Mage::getModel('customer/address')->load($info['default_shipping']));
|
66 |
+
if (isset($info['gender'])) {
|
67 |
+
$info['gender'] = $entity->getResource()->getAttribute('gender')->getSource()->getOptionText($entity->getGender());
|
68 |
+
}
|
69 |
+
if (isset($info['dob'])) {
|
70 |
+
$dobArray = explode(" ", $info['dob']);
|
71 |
+
$info['dob'] = $dobArray[0];
|
72 |
+
}
|
73 |
+
|
74 |
+
return $this->getDetail($info);
|
75 |
+
}
|
76 |
+
|
77 |
+
/*
|
78 |
+
* Prevent Auto Login
|
79 |
+
*/
|
80 |
+
protected function renewCustomerSesssion($data) {
|
81 |
+
return;
|
82 |
+
}
|
83 |
+
|
84 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Orders.php
ADDED
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Api_Orders extends Simi_Simiconnector_Model_Api_Orders {
|
4 |
+
|
5 |
+
public function setBuilderQuery() {
|
6 |
+
$data = $this->getData();
|
7 |
+
if ($data['resourceid']) {
|
8 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::ORDER_DETAIL);
|
9 |
+
$this->builderQuery = Mage::getModel('sales/order')->load($data['resourceid']);
|
10 |
+
if (!$this->builderQuery->getId()) {
|
11 |
+
$this->builderQuery = Mage::getModel('sales/order')->loadByIncrementId($data['resourceid']);
|
12 |
+
}
|
13 |
+
if (!$this->builderQuery->getId()) {
|
14 |
+
throw new Exception(Mage::helper('simiconnector')->__('Cannot find the Order'), 6);
|
15 |
+
}
|
16 |
+
} else {
|
17 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::ORDER_LIST);
|
18 |
+
$this->builderQuery = Mage::getModel('sales/order')->getCollection();
|
19 |
+
if (isset($data['params'])) {
|
20 |
+
if (isset($data['params']['from_date']) && isset($data['params']['to_date'])) {
|
21 |
+
$fromDate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $data['params']['from_date'])));
|
22 |
+
$toDate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $data['params']['to_date'])) + 86399);
|
23 |
+
|
24 |
+
/* Get the collection */
|
25 |
+
$this->builderQuery = $this->builderQuery
|
26 |
+
->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
|
27 |
+
}
|
28 |
+
if (isset($data['params']['customer_email']) && isset($data['params']['customer_email']['like'])) {
|
29 |
+
$query = $data['params']['customer_email']['like'];
|
30 |
+
$pos = strpos($query, '%');
|
31 |
+
if ($pos === false) {
|
32 |
+
$this->builderQuery->addFieldToFilter('customer_id', array('neq' => null));
|
33 |
+
}
|
34 |
+
}
|
35 |
+
}
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
public function update() {
|
40 |
+
$data = $this->getData();
|
41 |
+
$order = $this->builderQuery;
|
42 |
+
$param = $data['contents'];
|
43 |
+
$order_helper = Mage::helper('simiconnector/orders');
|
44 |
+
$result = null;
|
45 |
+
if ($param->status == 'cancel') {
|
46 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::CANCEL_ORDER);
|
47 |
+
$result = $order_helper->cancelOrder($order);
|
48 |
+
} elseif ($param->status == 'invoice') {
|
49 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::INVOICE_ORDER);
|
50 |
+
$result = $order_helper->invoiceOrder($order);
|
51 |
+
} elseif ($param->status == 'ship') {
|
52 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::SHIP_ORDER);
|
53 |
+
$result = $order_helper->shipOrder($order);
|
54 |
+
} elseif ($param->status == 'hold') {
|
55 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::HOLD_ORDER);
|
56 |
+
$result = $order_helper->holdOrder($order);
|
57 |
+
} elseif ($param->status == 'unhold') {
|
58 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::UNHOLD_ORDER);
|
59 |
+
$result = $order_helper->unHoldOrder($order);
|
60 |
+
} else {
|
61 |
+
$order->setState($param->status, true);
|
62 |
+
$order->save();
|
63 |
+
}
|
64 |
+
if (null != $result) {
|
65 |
+
$return_data = $this->show();
|
66 |
+
$return_data[$this->getSingularKey()]['message'] = $result['message'];
|
67 |
+
return $return_data;
|
68 |
+
}
|
69 |
+
return $this->show();
|
70 |
+
}
|
71 |
+
|
72 |
+
public function show() {
|
73 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::ORDER_DETAIL);
|
74 |
+
$order = Simi_Simiconnector_Model_Api_Abstract::show();
|
75 |
+
$order[$this->getSingularKey()]['payment_method'] = $this->builderQuery->getPayment()->getMethodInstance()->getCode();
|
76 |
+
$order[$this->getSingularKey()]['payment_description'] = $this->builderQuery->getPayment()->getMethodInstance()->getTitle();
|
77 |
+
$order[$this->getSingularKey()]['billing_address'] = Mage::helper('simiconnector/address')->getAddressDetail($this->builderQuery->getBillingAddress(), null);
|
78 |
+
$shippingAdress = Mage::helper('simiconnector/address')->getAddressDetail($this->builderQuery->getShippingAddress(), null);
|
79 |
+
if (count($shippingAdress) != 0) {
|
80 |
+
$order[$this->getSingularKey()]['shipping_address'] = $shippingAdress;
|
81 |
+
}
|
82 |
+
$order[$this->getSingularKey()]['order_items'] = $this->_getProductFromOrderHistoryDetail($this->builderQuery);
|
83 |
+
$order[$this->getSingularKey()]['total'] = Mage::helper('simiconnector/total')->showTotalOrder($this->builderQuery);
|
84 |
+
$order[$this->getSingularKey()]['action'] = $this->getOrderAction();
|
85 |
+
$order[$this->getSingularKey()]['base_currency_symbol'] = Mage::app()->getLocale()->currency($this->builderQuery->getData('base_currency_code'))->getSymbol();
|
86 |
+
$order[$this->getSingularKey()]['order_currency_symbol'] = Mage::app()->getLocale()->currency($this->builderQuery->getData('order_currency_code'))->getSymbol();
|
87 |
+
$order[$this->getSingularKey()]['global_currency_symbol'] = Mage::app()->getLocale()->currency($this->builderQuery->getData('global_currency_code'))->getSymbol();
|
88 |
+
$order[$this->getSingularKey()]['store_currency_symbol'] = Mage::app()->getLocale()->currency($this->builderQuery->getData('store_currency_code'))->getSymbol();
|
89 |
+
return $order;
|
90 |
+
}
|
91 |
+
|
92 |
+
public function index() {
|
93 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::ORDER_LIST);
|
94 |
+
$collection = $this->builderQuery;
|
95 |
+
$this->filter();
|
96 |
+
$data = $this->getData();
|
97 |
+
$parameters = $data['params'];
|
98 |
+
$page = 1;
|
99 |
+
if (isset($parameters[self::PAGE]) && $parameters[self::PAGE]) {
|
100 |
+
$page = $parameters[self::PAGE];
|
101 |
+
}
|
102 |
+
|
103 |
+
$limit = self::DEFAULT_LIMIT;
|
104 |
+
if (isset($parameters[self::LIMIT]) && $parameters[self::LIMIT]) {
|
105 |
+
$limit = $parameters[self::LIMIT];
|
106 |
+
}
|
107 |
+
|
108 |
+
$offset = $limit * ($page - 1);
|
109 |
+
if (isset($parameters[self::OFFSET]) && $parameters[self::OFFSET]) {
|
110 |
+
$offset = $parameters[self::OFFSET];
|
111 |
+
}
|
112 |
+
$collection->setPageSize($offset + $limit);
|
113 |
+
|
114 |
+
$all_ids = array();
|
115 |
+
$info = array();
|
116 |
+
$total = $collection->getSize();
|
117 |
+
|
118 |
+
if ($offset > $total)
|
119 |
+
throw new Exception($this->_helper->__('Invalid method.'), 4);
|
120 |
+
|
121 |
+
$fields = array();
|
122 |
+
if (isset($parameters['fields']) && $parameters['fields']) {
|
123 |
+
$fields = explode(',', $parameters['fields']);
|
124 |
+
}
|
125 |
+
|
126 |
+
$check_limit = 0;
|
127 |
+
$check_offset = 0;
|
128 |
+
|
129 |
+
foreach ($collection as $entity) {
|
130 |
+
if (++$check_offset <= $offset) {
|
131 |
+
continue;
|
132 |
+
}
|
133 |
+
if (++$check_limit > $limit)
|
134 |
+
break;
|
135 |
+
|
136 |
+
$data = $entity->toArray($fields);
|
137 |
+
$data['base_currency_symbol'] = Mage::app()->getLocale()->currency($entity->getData('base_currency_code'))->getSymbol();
|
138 |
+
$data['order_currency_symbol'] = Mage::app()->getLocale()->currency($entity->getData('order_currency_code'))->getSymbol();
|
139 |
+
$data['global_currency_symbol'] = Mage::app()->getLocale()->currency($entity->getData('global_currency_code'))->getSymbol();
|
140 |
+
$data['store_currency_symbol'] = Mage::app()->getLocale()->currency($entity->getData('store_currency_code'))->getSymbol();
|
141 |
+
$info[] = $data;
|
142 |
+
$all_ids[] = $entity->getId();
|
143 |
+
}
|
144 |
+
$orders = $this->getList($info, $all_ids, $total, $limit, $offset);
|
145 |
+
$orders['layers']['layer_filter'][] = array(
|
146 |
+
'attribute' => 'status',
|
147 |
+
'title' => 'Status',
|
148 |
+
'filter' => $this->get_orders_statuses(),
|
149 |
+
);
|
150 |
+
if (!Mage::app()->isSingleStoreMode()) {
|
151 |
+
$groups = $this->getGroups();
|
152 |
+
$orders['layers']['layer_filter'][] = array(
|
153 |
+
'attribute' => 'store',
|
154 |
+
'title' => 'Store',
|
155 |
+
'filter' => $groups['store'],
|
156 |
+
);
|
157 |
+
$orders['website'] = $groups['website'];
|
158 |
+
}
|
159 |
+
return $orders;
|
160 |
+
}
|
161 |
+
|
162 |
+
public function getOrderAction() {
|
163 |
+
$cur_order = $this->builderQuery;
|
164 |
+
$antions = array();
|
165 |
+
if ($cur_order->canCancel()) {
|
166 |
+
$actions[] = array(
|
167 |
+
'key' => 'cancel',
|
168 |
+
'value' => 'Cancel'
|
169 |
+
);
|
170 |
+
}
|
171 |
+
|
172 |
+
if ($cur_order->canHold()) {
|
173 |
+
$actions[] = array(
|
174 |
+
'key' => 'hold',
|
175 |
+
'value' => 'Hold'
|
176 |
+
);
|
177 |
+
}
|
178 |
+
|
179 |
+
if ($cur_order->canUnhold()) {
|
180 |
+
$actions[] = array(
|
181 |
+
'key' => 'unhold',
|
182 |
+
'value' => 'Unhold'
|
183 |
+
);
|
184 |
+
}
|
185 |
+
|
186 |
+
if ($cur_order->canShip()) {
|
187 |
+
$actions[] = array(
|
188 |
+
'key' => 'ship',
|
189 |
+
'value' => 'Ship'
|
190 |
+
);
|
191 |
+
}
|
192 |
+
|
193 |
+
if ($cur_order->canInvoice()) {
|
194 |
+
$actions[] = array(
|
195 |
+
'key' => 'invoice',
|
196 |
+
'value' => 'Invoice'
|
197 |
+
);
|
198 |
+
}
|
199 |
+
return $actions;
|
200 |
+
}
|
201 |
+
|
202 |
+
protected function get_orders_statuses() {
|
203 |
+
$statuses = Mage::getModel('sales/order_status')->getResourceCollection()->getData();
|
204 |
+
return $statuses;
|
205 |
+
}
|
206 |
+
|
207 |
+
protected function _getStoreModel() {
|
208 |
+
return Mage::getSingleton('adminhtml/system_store');
|
209 |
+
}
|
210 |
+
|
211 |
+
protected function getGroups() {
|
212 |
+
$return_data = array();
|
213 |
+
$stores = array();
|
214 |
+
$website_data = array();
|
215 |
+
$data = $this->_getStoreModel()->getStoresStructure(false);
|
216 |
+
foreach ($data as $website) {
|
217 |
+
$item1 = array(
|
218 |
+
'website_id' => $website['value'],
|
219 |
+
'website_label' => $website['label'],
|
220 |
+
);
|
221 |
+
foreach ($website['children'] as $group) {
|
222 |
+
$item2 = array(
|
223 |
+
'store_id' => $group['value'],
|
224 |
+
'store_label' => $group['label'],
|
225 |
+
);
|
226 |
+
foreach ($group['children'] as $storeview) {
|
227 |
+
$item3 = array(
|
228 |
+
'store_id' => $storeview['value'],
|
229 |
+
'store_label' => $storeview['label'],
|
230 |
+
);
|
231 |
+
$stores[] = $item3;
|
232 |
+
$item2['storeview'][] = $item3;
|
233 |
+
}
|
234 |
+
$item1['store'][] = $item2;
|
235 |
+
}
|
236 |
+
$website_data[] = $item1;
|
237 |
+
}
|
238 |
+
$return_data['website'] = $website_data;
|
239 |
+
$return_data['store'] = $stores;
|
240 |
+
return $return_data;
|
241 |
+
}
|
242 |
+
|
243 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Permissions.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Api_Permissions extends Simi_Simiconnector_Model_Api_Abstract {
|
4 |
+
|
5 |
+
public function setBuilderQuery() {
|
6 |
+
$data = $this->getData();
|
7 |
+
if ($data['resourceid']) {
|
8 |
+
|
9 |
+
} else {
|
10 |
+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
11 |
+
$user = Mage::getModel('simitracking/user')->getCollection()->addFieldToFilter('user_email', Mage::getSingleton('customer/session')->getCustomer()->getEmail())->getFirstItem();
|
12 |
+
$this->builderQuery = Mage::getModel('simitracking/permission')->getCollection()->addFieldToFilter('role_id', $user->getRoleId());
|
13 |
+
} else
|
14 |
+
throw new Exception(Mage::helper('simitracking')->__('Please Login'), 4);
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
public function index()
|
19 |
+
{
|
20 |
+
$result = parent::index();
|
21 |
+
$permissionList = Mage::helper('simitracking')->getPermissions();
|
22 |
+
|
23 |
+
foreach ($result['permissions'] as $index=>$permission) {
|
24 |
+
$permission['permission_title'] = $permissionList[$permission['permission_id']]['title'];
|
25 |
+
$result['permissions'][$index] = $permission;
|
26 |
+
}
|
27 |
+
return $result;
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Products.php
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Api_Products extends Simi_Simiconnector_Model_Api_Products {
|
4 |
+
|
5 |
+
protected $_stockitem;
|
6 |
+
|
7 |
+
|
8 |
+
public function setBuilderQuery() {
|
9 |
+
$data = $this->getData();
|
10 |
+
$this->_helperProduct = Mage::helper('simiconnector/products');
|
11 |
+
$this->_helperProduct->setData($data);
|
12 |
+
if ($data['resourceid']) {
|
13 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::PRODUCT_DETAIL);
|
14 |
+
$this->builderQuery = Mage::getModel('catalog/product')->load($data['resourceid']);
|
15 |
+
|
16 |
+
$dataToSave = $data['contents'];
|
17 |
+
$storeId = false;
|
18 |
+
if (isset($dataToSave->store_id)) {
|
19 |
+
$storeId = $dataToSave->store_id;
|
20 |
+
} else if (isset($data['params']) && isset($data['params']['store_id'])) {
|
21 |
+
$storeId = $data['params']['store_id'];
|
22 |
+
}
|
23 |
+
if ($storeId != false) {
|
24 |
+
$this->builderQuery->setStoreId($storeId);
|
25 |
+
Mage::app()->setCurrentStore($storeId);
|
26 |
+
} else
|
27 |
+
$this->builderQuery->setStoreId(0);
|
28 |
+
} else {
|
29 |
+
$this->builderQuery = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')
|
30 |
+
->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left');
|
31 |
+
if (isset($data['params']['store_id']) && $data['params']['store_id'] != '0' && $data['params']['store_id'] != '') {
|
32 |
+
$this->builderQuery->setStoreId($data['params']['store_id']);
|
33 |
+
}
|
34 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::PRODUCT_LIST);
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
/*
|
39 |
+
* Update Product
|
40 |
+
*/
|
41 |
+
|
42 |
+
public function update() {
|
43 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::PRODUCT_EDIT);
|
44 |
+
$data = $this->getData();
|
45 |
+
$dataToSave = $data['contents'];
|
46 |
+
$product = $this->builderQuery;
|
47 |
+
|
48 |
+
//product update
|
49 |
+
if ($dataToSave->name) {
|
50 |
+
$product->setData('name', $dataToSave->name);
|
51 |
+
}
|
52 |
+
if ($dataToSave->description) {
|
53 |
+
$product->setData('description', $dataToSave->description);
|
54 |
+
}
|
55 |
+
if ($dataToSave->short_description) {
|
56 |
+
$product->setData('short_description', $dataToSave->short_description);
|
57 |
+
}
|
58 |
+
$product->save();
|
59 |
+
//stock item
|
60 |
+
if (isset($dataToSave->is_in_stock) || isset($dataToSave->qty)) {
|
61 |
+
$this->_stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
|
62 |
+
if (isset($dataToSave->qty)) {
|
63 |
+
$this->_stockItem->setData('qty', $dataToSave->qty);
|
64 |
+
}
|
65 |
+
if (isset($dataToSave->is_in_stock)) {
|
66 |
+
$this->_stockItem->setData('is_in_stock', $dataToSave->is_in_stock);
|
67 |
+
}
|
68 |
+
$this->_stockItem->save();
|
69 |
+
}
|
70 |
+
|
71 |
+
$this->builderQuery = $product;
|
72 |
+
$this->_RETURN_MESSAGE = Mage::helper('customer')->__('The product has been updated.');
|
73 |
+
return $this->show();
|
74 |
+
}
|
75 |
+
|
76 |
+
/*
|
77 |
+
* Listing Products
|
78 |
+
*/
|
79 |
+
|
80 |
+
public function index() {
|
81 |
+
$collection = $this->builderQuery;
|
82 |
+
$this->filter();
|
83 |
+
$data = $this->getData();
|
84 |
+
$parameters = $data['params'];
|
85 |
+
$page = 1;
|
86 |
+
if (isset($parameters[self::PAGE]) && $parameters[self::PAGE]) {
|
87 |
+
$page = $parameters[self::PAGE];
|
88 |
+
}
|
89 |
+
|
90 |
+
$limit = self::DEFAULT_LIMIT;
|
91 |
+
if (isset($parameters[self::LIMIT]) && $parameters[self::LIMIT]) {
|
92 |
+
$limit = $parameters[self::LIMIT];
|
93 |
+
}
|
94 |
+
|
95 |
+
$offset = $limit * ($page - 1);
|
96 |
+
if (isset($parameters[self::OFFSET]) && $parameters[self::OFFSET]) {
|
97 |
+
$offset = $parameters[self::OFFSET];
|
98 |
+
}
|
99 |
+
$collection->setPageSize($offset + $limit);
|
100 |
+
|
101 |
+
$all_ids = array();
|
102 |
+
$info = array();
|
103 |
+
$total = $collection->getSize();
|
104 |
+
|
105 |
+
if ($offset > $total)
|
106 |
+
throw new Exception($this->_helper->__('Invalid method.'), 4);
|
107 |
+
|
108 |
+
$fields = array();
|
109 |
+
if (isset($parameters['fields']) && $parameters['fields']) {
|
110 |
+
$fields = explode(',', $parameters['fields']);
|
111 |
+
}
|
112 |
+
|
113 |
+
$check_limit = 0;
|
114 |
+
$check_offset = 0;
|
115 |
+
|
116 |
+
foreach ($collection as $entity) {
|
117 |
+
if (++$check_offset <= $offset) {
|
118 |
+
continue;
|
119 |
+
}
|
120 |
+
if (++$check_limit > $limit)
|
121 |
+
break;
|
122 |
+
$info_detail = $entity->toArray($fields);
|
123 |
+
$all_ids[] = $entity->getId();
|
124 |
+
$imagelink = Mage::helper('simiconnector/products')->getImageProduct($entity, null, $parameters['image_width'], $parameters['image_height']);
|
125 |
+
|
126 |
+
$info_detail['images'] = array(array(
|
127 |
+
'url' => $imagelink,
|
128 |
+
'position' => 1,
|
129 |
+
));
|
130 |
+
$info[] = $info_detail;
|
131 |
+
}
|
132 |
+
return $this->getList($info, $all_ids, $total, $limit, $offset);
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Show Detail
|
137 |
+
* override
|
138 |
+
*/
|
139 |
+
public function show() {
|
140 |
+
$entity = $this->builderQuery;
|
141 |
+
$data = $this->getData();
|
142 |
+
$parameters = $data['params'];
|
143 |
+
$fields = array();
|
144 |
+
if (isset($parameters['fields']) && $parameters['fields']) {
|
145 |
+
$fields = explode(',', $parameters['fields']);
|
146 |
+
}
|
147 |
+
$info = $entity->toArray($fields);
|
148 |
+
$product = Mage::getModel('catalog/product')->load($entity->getId());
|
149 |
+
$media_gallery = $product->getMediaGallery();
|
150 |
+
$images = array();
|
151 |
+
|
152 |
+
foreach ($media_gallery['images'] as $image) {
|
153 |
+
if ($image['disabled'] == 0) {
|
154 |
+
$imagelink = $this->_helperProduct->getImageProduct($entity, $image['file'], $parameters['image_width'], $parameters['image_height']);
|
155 |
+
$images[] = array(
|
156 |
+
'url' => $imagelink,
|
157 |
+
'position' => $image['position'],
|
158 |
+
);
|
159 |
+
}
|
160 |
+
}
|
161 |
+
if (count($images) == 0) {
|
162 |
+
$imagelink = $this->_helperProduct->getImageProduct($entity, null, $parameters['image_width'], $parameters['image_height']);
|
163 |
+
$images[] = array(
|
164 |
+
'url' => $imagelink,
|
165 |
+
'position' => 1,
|
166 |
+
);
|
167 |
+
}
|
168 |
+
if (!Mage::registry('product') && $entity->getId()) {
|
169 |
+
Mage::register('product', $entity);
|
170 |
+
}
|
171 |
+
|
172 |
+
$block_att = Mage::getBlockSingleton('catalog/product_view_attributes');
|
173 |
+
$_additional = $block_att->getAdditionalData();
|
174 |
+
|
175 |
+
$ratings = Mage::helper('simiconnector/review')->getRatingStar($entity->getId());
|
176 |
+
$total_rating = Mage::helper('simiconnector/review')->getTotalRate($ratings);
|
177 |
+
$avg = Mage::helper('simiconnector/review')->getAvgRate($ratings, $total_rating);
|
178 |
+
|
179 |
+
$info['additional'] = $_additional;
|
180 |
+
$info['images'] = $images;
|
181 |
+
$info['app_prices'] = Mage::helper('simiconnector/price')->formatPriceFromProduct($entity, true);
|
182 |
+
$info['app_tier_prices'] = Mage::helper('simiconnector/tierprice')->formatTierPrice($entity);
|
183 |
+
$info['app_reviews'] = array(
|
184 |
+
'rate' => $avg,
|
185 |
+
'number' => $ratings[5],
|
186 |
+
'5_star_number' => $ratings[4],
|
187 |
+
'4_star_number' => $ratings[3],
|
188 |
+
'3_star_number' => $ratings[2],
|
189 |
+
'2_star_number' => $ratings[1],
|
190 |
+
'1_star_number' => $ratings[0],
|
191 |
+
'form_add_reviews' => Mage::helper('simiconnector/review')->getReviewToAdd(),
|
192 |
+
);
|
193 |
+
if ($this->_stockItem) {
|
194 |
+
$info['stock_item'] = $this->_stockItem->getData();
|
195 |
+
}
|
196 |
+
$this->detail_info = $this->getDetail($info);
|
197 |
+
return $this->detail_info;
|
198 |
+
}
|
199 |
+
|
200 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Sales.php
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Api_Sales extends Simi_Simiconnector_Model_Api_Abstract {
|
4 |
+
|
5 |
+
public function setBuilderQuery() {
|
6 |
+
$data = $this->getData();
|
7 |
+
if ($data['resourceid']) {
|
8 |
+
if ($data['resourceid'] == 'total') {
|
9 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::TOTAL_DETAIL);
|
10 |
+
$this->builderQuery = $this->getTotalSale();
|
11 |
+
} else if ($data['resourceid'] == 'lifetime') {
|
12 |
+
$this->builderQuery = $this->getLifetimeSale();
|
13 |
+
} else if ($data['resourceid'] == 'refresh') {
|
14 |
+
$collectionsNames = array('sales/report_order',
|
15 |
+
'sales/report_invoiced',
|
16 |
+
'sales/report_refunded',
|
17 |
+
'sales/report_bestsellers',
|
18 |
+
'tax/report_tax',
|
19 |
+
'sales/report_shipping');
|
20 |
+
foreach ($collectionsNames as $collectionName) {
|
21 |
+
Mage::getResourceModel($collectionName)->aggregate();
|
22 |
+
}
|
23 |
+
$this->builderQuery = $this->getLifetimeSale();
|
24 |
+
}
|
25 |
+
} else {
|
26 |
+
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
public function getTotalSale() {
|
31 |
+
$dataModel = Mage::getResourceModel('reports/order_collection');
|
32 |
+
$dataModel->checkIsLive();
|
33 |
+
$this->_applyFilter($dataModel);
|
34 |
+
$dataModel->calculateTotals(true);
|
35 |
+
$dataModel->load();
|
36 |
+
return $dataModel->getFirstItem();
|
37 |
+
}
|
38 |
+
|
39 |
+
public function getLifetimeSale() {
|
40 |
+
$dataModel = Mage::getResourceModel('reports/order_collection')
|
41 |
+
->calculateSales(true);
|
42 |
+
$dataModel->load();
|
43 |
+
return $dataModel->getFirstItem();
|
44 |
+
}
|
45 |
+
|
46 |
+
protected function _applyFilter($dataModel) {
|
47 |
+
$data = $this->getData();
|
48 |
+
if (isset($data['params'])) {
|
49 |
+
if (isset($data['params']['from_date']) && isset($data['params']['to_date'])) {
|
50 |
+
$fromTimeStamp = $data['params']['from_date'].' 12:00:00';
|
51 |
+
$toTimeStamp = $data['params']['to_date'].' 00:00:00';
|
52 |
+
|
53 |
+
$dateStart = Mage::app()->getLocale()->date($fromTimeStamp, Varien_Date::DATETIME_INTERNAL_FORMAT);
|
54 |
+
$dateEnd = Mage::app()->getLocale()->date($toTimeStamp, Varien_Date::DATETIME_INTERNAL_FORMAT);
|
55 |
+
|
56 |
+
$dateStart->setHour(0);
|
57 |
+
$dateStart->setMinute(0);
|
58 |
+
$dateStart->setSecond(0);
|
59 |
+
|
60 |
+
$dateEnd->setHour(23);
|
61 |
+
$dateEnd->setMinute(59);
|
62 |
+
$dateEnd->setSecond(59);
|
63 |
+
|
64 |
+
$dateStart->setTimezone('Etc/UTC');
|
65 |
+
$dateEnd->setTimezone('Etc/UTC');
|
66 |
+
|
67 |
+
$fromDate = $dateStart->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
|
68 |
+
$toDate = $dateEnd->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
|
69 |
+
|
70 |
+
$dataModel->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
|
71 |
+
}
|
72 |
+
|
73 |
+
if (isset($data['params']['store_id']) && $data['params']['store_id'] != '0' && $data['params']['store_id'] != '') {
|
74 |
+
$dataModel->addFieldToFilter('store_id', $data['params']['store_id']);
|
75 |
+
} else if (isset($data['params']['website'])) {
|
76 |
+
$storeIds = Mage::app()->getWebsite($data['params']['website'])->getStoreIds();
|
77 |
+
$dataModel->addFieldToFilter('store_id', array('in' => $storeIds));
|
78 |
+
} else if (isset($data['params']['group'])) {
|
79 |
+
$storeIds = Mage::app()->getGroup($data['params']['group'])->getStoreIds();
|
80 |
+
$dataModel->addFieldToFilter('store_id', array('in' => $storeIds));
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
public function show() {
|
86 |
+
$data = $this->getData();
|
87 |
+
if ($data['resourceid']) {
|
88 |
+
if (($data['resourceid'] == 'total') || ($data['resourceid'] == 'lifetime')) {
|
89 |
+
return parent::show();
|
90 |
+
} else if (($data['resourceid'] == 'saleinfo') || ($data['resourceid'] == 'refresh')) {
|
91 |
+
Mage::helper('simitracking')->isAllowed(Simi_Simitracking_Helper_Data::SALE_TRACKING);
|
92 |
+
$this->builderQuery = Mage::getModel('reports/grouped_collection');
|
93 |
+
$this->builderQuery->setResourceCollection('sales/report_order_collection');
|
94 |
+
|
95 |
+
//month , day, year
|
96 |
+
$period = 'day';
|
97 |
+
if (isset($data['params']['period'])) {
|
98 |
+
$period = $data['params']['period'];
|
99 |
+
}
|
100 |
+
$stores = array();
|
101 |
+
if (isset($data['params']['store_id']) && $data['params']['store_id'] != '0' && $data['params']['store_id'] != '') {
|
102 |
+
$stores[] = $data['params']['store_id'];
|
103 |
+
}
|
104 |
+
$totalsCollection = Mage::getResourceModel('sales/report_order_collection')
|
105 |
+
->setPeriod($period);
|
106 |
+
if (isset($data['params']) && isset($data['params']['from_date']) && isset($data['params']['to_date'])) {
|
107 |
+
$timeDifference = time() - Mage::getModel('core/date')->timestamp(time());
|
108 |
+
$fromTimeStamp = Mage::getModel('core/date')->timestamp(strtotime(str_replace('-', '/', $data['params']['from_date'])) - $timeDifference);
|
109 |
+
$toTimeStamp = Mage::getModel('core/date')->timestamp(strtotime(str_replace('-', '/', $data['params']['to_date']) . " GMT") - $timeDifference + 86399);
|
110 |
+
$fromDate = date('Y-m-d H:i:s', $fromTimeStamp);
|
111 |
+
$toDate = date('Y-m-d H:i:s', $toTimeStamp);
|
112 |
+
$totalsCollection->setDateRange($fromDate, $toDate);
|
113 |
+
}
|
114 |
+
$totalsCollection->addStoreFilter($stores)
|
115 |
+
->setAggregatedColumns(
|
116 |
+
array('orders_count' => 'sum(orders_count)',
|
117 |
+
'total_qty_ordered' => 'sum(total_qty_ordered)',
|
118 |
+
'total_income_amount' => 'sum(total_income_amount)',
|
119 |
+
'total_invoiced_amount' => 'sum(total_invoiced_amount)',
|
120 |
+
//'total_refunded_amount' => 'sum(total_refunded_amount)',
|
121 |
+
//'total_tax_amount' => 'sum(total_tax_amount)',
|
122 |
+
//'total_shipping_amount' => 'sum(total_shipping_amount)',
|
123 |
+
//'total_discount_amount' => 'sum(total_discount_amount)',
|
124 |
+
//'total_canceled_amount' => 'sum(total_canceled_amount)',
|
125 |
+
'period' => 'period'));
|
126 |
+
|
127 |
+
$collection = Mage::getModel('reports/grouped_collection');
|
128 |
+
Mage::helper('reports')->prepareIntervalsCollection(
|
129 |
+
$collection, $fromDate, $toDate, $period
|
130 |
+
);
|
131 |
+
$collection->setColumnGroupBy('period');
|
132 |
+
$collection->setResourceCollection($totalsCollection);
|
133 |
+
|
134 |
+
$arrayReturn = array();
|
135 |
+
foreach ($collection->getItems() as $item) {
|
136 |
+
$dataArray = $item->toArray();
|
137 |
+
if ($period == 'day') {
|
138 |
+
$dayAndMonth = explode('-', substr($dataArray['period'], 5));
|
139 |
+
$dataArray['period'] = $dayAndMonth[1] . '/' . $dayAndMonth[0];
|
140 |
+
}
|
141 |
+
$arrayReturn[] = $dataArray;
|
142 |
+
}
|
143 |
+
$totalSale = $this->getTotalSale();
|
144 |
+
$lifetimeSale = $this->getLifetimeSale()->toArray();
|
145 |
+
|
146 |
+
if (isset($lifetimeSale['lifetime'])) {
|
147 |
+
$lifetimeSale['lifetime'] = (string)round($lifetimeSale['lifetime'], 2);
|
148 |
+
}
|
149 |
+
if (isset($lifetimeSale['average'])) {
|
150 |
+
$lifetimeSale['average'] = (string)round($lifetimeSale['average'], 2);
|
151 |
+
}
|
152 |
+
return array('sale' => array('total_chart' => $arrayReturn, 'total_sale' => $totalSale->toArray(), 'lifetime_sale' => $lifetimeSale));
|
153 |
+
//zend_debug::dump($totalsCollection->getItems());die;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Salesforecasts.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Api_Salesforecasts extends Simi_Simiconnector_Model_Api_Abstract {
|
4 |
+
|
5 |
+
public function setBuilderQuery() {
|
6 |
+
$data = $this->getData();
|
7 |
+
if ($data['resourceid']) {
|
8 |
+
|
9 |
+
} else {
|
10 |
+
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
public function show() {
|
15 |
+
$data = $this->getData();
|
16 |
+
if ($data['resourceid']) {
|
17 |
+
if ($data['resourceid'] == 'day') {
|
18 |
+
$grownValue = 0.2; //per year
|
19 |
+
$totalDays = 90;
|
20 |
+
if (isset($data['params']['number_of_days']) && $data['params']['number_of_days'] != '0' && $data['params']['number_of_days'] != '') {
|
21 |
+
$totalDays = $data['params']['number_of_days'];
|
22 |
+
}
|
23 |
+
// get latest 366 days sales report
|
24 |
+
$period = 'day';
|
25 |
+
$stores = array();
|
26 |
+
if (isset($data['params']['store_id']) && $data['params']['store_id'] != '0' && $data['params']['store_id'] != '') {
|
27 |
+
$stores[] = $data['params']['store_id'];
|
28 |
+
}
|
29 |
+
$totalsCollection = Mage::getResourceModel('sales/report_order_collection')
|
30 |
+
->setPeriod($period);
|
31 |
+
|
32 |
+
$fromTimeStamp = Mage::getModel('core/date')->timestamp(time() - 366 * 86400);
|
33 |
+
$toTimeStamp = Mage::getModel('core/date')->timestamp(time());
|
34 |
+
$fromDate = date('Y-m-d H:i:s', $fromTimeStamp);
|
35 |
+
$toDate = date('Y-m-d H:i:s', $toTimeStamp);
|
36 |
+
$totalsCollection->setDateRange($fromDate, $toDate);
|
37 |
+
|
38 |
+
$totalsCollection->addStoreFilter($stores)
|
39 |
+
->setAggregatedColumns(
|
40 |
+
array('orders_count' => 'sum(orders_count)',
|
41 |
+
'total_qty_ordered' => 'sum(total_qty_ordered)',
|
42 |
+
'total_income_amount' => 'sum(total_income_amount)',
|
43 |
+
'total_invoiced_amount' => 'sum(total_invoiced_amount)',
|
44 |
+
'period' => 'period'));
|
45 |
+
|
46 |
+
$collection = Mage::getModel('reports/grouped_collection');
|
47 |
+
Mage::helper('reports')->prepareIntervalsCollection(
|
48 |
+
$collection, $fromDate, $toDate, $period
|
49 |
+
);
|
50 |
+
|
51 |
+
$collection->setColumnGroupBy('period');
|
52 |
+
$collection->setResourceCollection($totalsCollection);
|
53 |
+
|
54 |
+
$resultArray = $collection->getItems();
|
55 |
+
$totalCollected = count($resultArray);
|
56 |
+
|
57 |
+
|
58 |
+
// create forecast
|
59 |
+
$forecastArray = array();
|
60 |
+
$dayToReport = time();
|
61 |
+
for ($i = 0; $i < $totalDays; $i++) {
|
62 |
+
$dayToReport += 86400;
|
63 |
+
$highestOrderCount = 0;
|
64 |
+
$highestSales = 0;
|
65 |
+
//last week
|
66 |
+
$weekItem = $resultArray[$totalCollected + $i%7 - 7]->toArray();
|
67 |
+
if (isset($weekItem['orders_count'])) {
|
68 |
+
$calculatedOrderCount = (int)($weekItem['orders_count']*pow(($grownValue + 1), ($i/365)));
|
69 |
+
if ($calculatedOrderCount > $highestOrderCount)
|
70 |
+
$highestOrderCount = $calculatedOrderCount;
|
71 |
+
}
|
72 |
+
if (isset($weekItem['total_invoiced_amount'])) {
|
73 |
+
$calculatedInvoiceAmout = $weekItem['total_invoiced_amount']*pow(($grownValue + 1), ($i/365));
|
74 |
+
if ($calculatedInvoiceAmout > $highestSales)
|
75 |
+
$highestSales = round($calculatedInvoiceAmout, 2);
|
76 |
+
}
|
77 |
+
|
78 |
+
//last 30 days
|
79 |
+
$monthItem = $resultArray[$totalCollected + $i%30 - 30]->toArray();
|
80 |
+
if (isset($monthItem['orders_count']) && ($monthItem['orders_count'] > $highestOrderCount)) {
|
81 |
+
$calculatedOrderCount = (int)($monthItem['orders_count']*pow(($grownValue + 1), ($i/365)));
|
82 |
+
if ($calculatedOrderCount > $highestOrderCount)
|
83 |
+
$highestOrderCount = $calculatedOrderCount;
|
84 |
+
}
|
85 |
+
if (isset($monthItem['total_invoiced_amount'])) {
|
86 |
+
$calculatedInvoiceAmout = $monthItem['total_invoiced_amount']*pow(($grownValue + 1), ($i/365));
|
87 |
+
if ($calculatedInvoiceAmout > $highestSales)
|
88 |
+
$highestSales = round($calculatedInvoiceAmout, 2);
|
89 |
+
}
|
90 |
+
|
91 |
+
//last 365 days
|
92 |
+
$yearItem = $resultArray[$totalCollected + $i - 365]->toArray();
|
93 |
+
if (isset($yearItem['orders_count'])) {
|
94 |
+
$calculatedOrderCount = (int)($yearItem['orders_count']*pow(($grownValue + 1), ($i/365)));
|
95 |
+
if ($calculatedOrderCount > $highestOrderCount)
|
96 |
+
$highestOrderCount = $calculatedOrderCount;
|
97 |
+
}
|
98 |
+
if (isset($yearItem['total_invoiced_amount'])) {
|
99 |
+
$calculatedInvoiceAmout = $yearItem['total_invoiced_amount']*pow(($grownValue + 1), ($i/365));
|
100 |
+
if ($calculatedInvoiceAmout > $highestSales)
|
101 |
+
$highestSales = round($calculatedInvoiceAmout, 2);
|
102 |
+
}
|
103 |
+
|
104 |
+
$forecastArray[$i] = array('period' => date('Y-m-d', $dayToReport),
|
105 |
+
'orders_count' => $highestOrderCount,
|
106 |
+
'orders_count_upper' => round($highestOrderCount*1.2),
|
107 |
+
'orders_count_lower' => round($highestOrderCount*0.8),
|
108 |
+
'total_invoiced_amount' => $highestSales,
|
109 |
+
'total_invoiced_amount_upper' => $highestSales*1.2,
|
110 |
+
'total_invoiced_amount_lower' => $highestSales*0.8);
|
111 |
+
}
|
112 |
+
return array('salesforecast' => array('day' => $forecastArray));
|
113 |
+
}
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Staffs.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
*/
|
6 |
+
class Simi_Simitracking_Model_Api_Staffs extends Simi_Simiconnector_Model_Api_Customers {
|
7 |
+
|
8 |
+
protected $_DEFAULT_ORDER = 'entity_id';
|
9 |
+
protected $_RETURN_MESSAGE;
|
10 |
+
|
11 |
+
public function setBuilderQuery() {
|
12 |
+
$data = $this->getData();
|
13 |
+
if ($data['resourceid']) {
|
14 |
+
switch ($data['resourceid']) {
|
15 |
+
case 'login':
|
16 |
+
if (Mage::getModel('simiconnector/customer')->login($data))
|
17 |
+
$this->builderQuery = Mage::getSingleton('customer/session')->getCustomer();
|
18 |
+
else
|
19 |
+
throw new Exception($this->_helper->__('Login Failed'), 4);
|
20 |
+
break;
|
21 |
+
case 'loginWithKeySession':
|
22 |
+
if (Mage::getModel('simitracking/customer')->loginWithKeySession($data))
|
23 |
+
$this->builderQuery = Mage::getSingleton('customer/session')->getCustomer();
|
24 |
+
else
|
25 |
+
throw new Exception($this->_helper->__('Login Failed'), 4);
|
26 |
+
break;
|
27 |
+
case 'logout':
|
28 |
+
if (Mage::getModel('simiconnector/customer')->logout($data)) {
|
29 |
+
if (isset($data['params']) && isset($data['params']['device_token'])) {
|
30 |
+
Mage::getModel('simitracking/device')->deleteDevice($data['params']['device_token']);
|
31 |
+
}
|
32 |
+
$this->builderQuery = Mage::getSingleton('customer/session')->getCustomer();
|
33 |
+
}
|
34 |
+
else
|
35 |
+
throw new Exception($this->_helper->__('Logout Failed'), 4);
|
36 |
+
break;
|
37 |
+
default:
|
38 |
+
break;
|
39 |
+
}
|
40 |
+
} else {
|
41 |
+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
42 |
+
$currentCustomerId = Mage::getSingleton('customer/session')->getId();
|
43 |
+
}
|
44 |
+
$this->builderQuery = Mage::getModel('customer/customer')->getCollection()
|
45 |
+
->addFieldToFilter('entity_id', $currentCustomerId);
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
public function show() {
|
50 |
+
$data = $this->getData();
|
51 |
+
if ($data['resourceid'] == 'logout')
|
52 |
+
return parent::show();
|
53 |
+
$entity = $this->builderQuery;
|
54 |
+
// Staff information
|
55 |
+
$user = Mage::getModel('simitracking/user')->getCollection()->addFieldToFilter('user_email', $entity->getEmail())->getFirstItem();
|
56 |
+
if (!$user->getId())
|
57 |
+
throw new Exception(Mage::helper('simitracking')->__('Your Account has No Tracking Permission'), 4);
|
58 |
+
|
59 |
+
$userInfo = $user->toArray();
|
60 |
+
$roleModel = Mage::getModel('simitracking/role')->load($user->getRoleId());
|
61 |
+
$userInfo['role_title'] = $roleModel->getData('role_title');
|
62 |
+
$userInfo['is_owner_role'] = $roleModel->getData('is_owner_role');
|
63 |
+
|
64 |
+
/*
|
65 |
+
* Register Device and Create Session Id
|
66 |
+
*/
|
67 |
+
// from email and password
|
68 |
+
if (isset($data['params']) && isset($data['params']['device_token'])) {
|
69 |
+
$deviceModel = Mage::getModel('simitracking/device')->saveDevice($data['params'], $user->getData('user_email'));
|
70 |
+
$userInfo['device_data'] = $deviceModel->toArray();
|
71 |
+
}
|
72 |
+
// from qr code
|
73 |
+
if (isset($data['params']['new_token_id']) && isset($data['params']['qr_session_id'])) {
|
74 |
+
$platform = 1;
|
75 |
+
if (isset($data['params']['plaform_id'])) {
|
76 |
+
$platform = $data['params']['plaform_id'];
|
77 |
+
}
|
78 |
+
$deviceModel = Mage::getModel('simitracking/device')->saveDeviceFromQR($data['params']['new_token_id'],$user->getData('user_email'),$platform);
|
79 |
+
$userInfo['device_data'] = $deviceModel->toArray();
|
80 |
+
}
|
81 |
+
|
82 |
+
// Additional Information
|
83 |
+
$userInfo['base_currency'] = Mage::app()->getStore()->getBaseCurrencyCode();
|
84 |
+
$userInfo['device_ip'] = $_SERVER['REMOTE_ADDR'];
|
85 |
+
|
86 |
+
// Permission
|
87 |
+
$permissionCollection = Mage::getModel('simitracking/permission')->getCollection()->addFieldToFilter('role_id', $user->getRoleId());
|
88 |
+
$permissionArray = array();
|
89 |
+
$permissionList = Mage::helper('simitracking')->getPermissions();
|
90 |
+
foreach ($permissionCollection as $permission) {
|
91 |
+
$permissionInfo = $permission->toArray();
|
92 |
+
$permissionInfo['permission_title'] = $permissionList[$permission['permission_id']]['title'];
|
93 |
+
$permissionArray[] = $permissionInfo;
|
94 |
+
}
|
95 |
+
$userInfo['permissions'] = $permissionArray;
|
96 |
+
|
97 |
+
$userInfo['customer_account_information'] = $entity->toArray();
|
98 |
+
return $this->getDetail($userInfo);
|
99 |
+
}
|
100 |
+
}
|
app/code/local/Simi/Simitracking/Model/Api/Stores.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Created by PhpStorm.
|
5 |
+
* User: Max
|
6 |
+
* Date: 5/3/16
|
7 |
+
* Time: 9:37 PM
|
8 |
+
*/
|
9 |
+
class Simi_Simitracking_Model_Api_Stores extends Simi_Simiconnector_Model_Api_Stores {
|
10 |
+
|
11 |
+
protected $_DEFAULT_ORDER = 'group_id';
|
12 |
+
|
13 |
+
public function setBuilderQuery() {
|
14 |
+
$data = $this->getData();
|
15 |
+
if ($data['resourceid']) {
|
16 |
+
$this->builderQuery = Mage::getModel('core/store_group')->load($data['resourceid']);
|
17 |
+
} else {
|
18 |
+
$this->builderQuery = $collection = Mage::getModel('core/store_group')->getCollection();
|
19 |
+
}
|
20 |
+
}
|
21 |
+
}
|
app/code/local/Simi/Simitracking/Model/Customer.php
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
*/
|
6 |
+
class Simi_Simitracking_Model_Customer extends Simi_Simiconnector_Model_Customer {
|
7 |
+
|
8 |
+
protected function _helperCustomer() {
|
9 |
+
return Mage::helper('simiconnector/customer');
|
10 |
+
}
|
11 |
+
|
12 |
+
public function newCustomer($data) {
|
13 |
+
$data = $data['contents'];
|
14 |
+
$checkCustomer = $this->getCustomerByEmail($data->email);
|
15 |
+
if ($checkCustomer->getId()) {
|
16 |
+
throw new Exception($this->_helperCustomer()->__('Account is already exist'), 4);
|
17 |
+
}
|
18 |
+
$customer = $this->_createCustomer($data);
|
19 |
+
$result = array();
|
20 |
+
$result['user_id'] = $customer->getId();
|
21 |
+
return $customer;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function updateCustomer($data, $customer) {
|
25 |
+
$data = $data['contents'];
|
26 |
+
$newPass = $data->new_password;
|
27 |
+
$confPass = $data->com_password;
|
28 |
+
|
29 |
+
$customerData = array(
|
30 |
+
'firstname' => $data->firstname,
|
31 |
+
'lastname' => $data->lastname,
|
32 |
+
'email' => $data->email,
|
33 |
+
);
|
34 |
+
|
35 |
+
$fields = Mage::getConfig()->getFieldset('customer_account');
|
36 |
+
foreach ($fields as $code => $node) {
|
37 |
+
if ($node->is('update') && isset($customerData[$code])) {
|
38 |
+
$customer->setData($code, $customerData[$code]);
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
if ($data->change_password == 1) {
|
43 |
+
$customer->setChangePassword(1);
|
44 |
+
$customer->setPassword($newPass);
|
45 |
+
$customer->setConfirmation($confPass);
|
46 |
+
$customer->setPasswordConfirmation($confPass);
|
47 |
+
}
|
48 |
+
|
49 |
+
$this->updateData($customer, $data);
|
50 |
+
|
51 |
+
$customerErrors = $customer->validate();
|
52 |
+
if (is_array($customerErrors))
|
53 |
+
throw new Exception($this->_helperCustomer()->__('Invalid profile information'), 4);
|
54 |
+
$customer->setConfirmation(null);
|
55 |
+
$customer->save();
|
56 |
+
return $customer;
|
57 |
+
}
|
58 |
+
|
59 |
+
private function _createCustomer($data) {
|
60 |
+
$customer = Mage::getModel('customer/customer')
|
61 |
+
->setFirstname($data->firstname)
|
62 |
+
->setLastname($data->lastname)
|
63 |
+
->setEmail($data->email);
|
64 |
+
$this->updateData($customer, $data);
|
65 |
+
if (!$data->password)
|
66 |
+
$data->password = $customer->generatePassword();
|
67 |
+
$customer->setPassword($data->password);
|
68 |
+
$customer->save();
|
69 |
+
$customer->setConfirmation(null);
|
70 |
+
$customer->save();
|
71 |
+
return $customer;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function updateData($customer, $data) {
|
75 |
+
if (isset($data->day) && $data->day != "") {
|
76 |
+
$birthday = $data->year . "-" . $data->month . "-" . $data->day;
|
77 |
+
$customer->setDob($birthday);
|
78 |
+
}
|
79 |
+
if (isset($data->taxvat)) {
|
80 |
+
$customer->setTaxvat($data->taxvat);
|
81 |
+
}
|
82 |
+
if (isset($data->gender) && $data->gender) {
|
83 |
+
$customer->setGender($data->gender);
|
84 |
+
}
|
85 |
+
if (isset($data->prefix) && $data->prefix) {
|
86 |
+
$customer->setPrefix($data->prefix);
|
87 |
+
}
|
88 |
+
if (isset($data->middlename) && $data->middlename) {
|
89 |
+
$customer->setMiddlename($data->middlename);
|
90 |
+
}
|
91 |
+
if (isset($data->suffix) && $data->suffix) {
|
92 |
+
$customer->setSuffix($data->suffix);
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
public function loginWithKeySession($data) {
|
97 |
+
// required $data['params']['qr_session_id']
|
98 |
+
// required $data['params']['new_token_id']
|
99 |
+
if(!isset($data['params']['qr_session_id']) || !isset($data['params']['new_token_id']))
|
100 |
+
return false;
|
101 |
+
return Mage::helper('simitracking')->continueSessionWithSessionId($data['params']['qr_session_id']);
|
102 |
+
}
|
103 |
+
|
104 |
+
}
|
app/code/local/Simi/Simitracking/Model/Device.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Device extends Mage_Core_Model_Abstract {
|
4 |
+
|
5 |
+
protected $_eventPrefix = 'simitracking_device';
|
6 |
+
protected $_eventObject = 'simitracking_device';
|
7 |
+
|
8 |
+
public function _construct() {
|
9 |
+
parent::_construct();
|
10 |
+
$this->_init('simitracking/device');
|
11 |
+
}
|
12 |
+
|
13 |
+
public function detectMobile() {
|
14 |
+
$user_agent = '';
|
15 |
+
if ($_SERVER["HTTP_USER_AGENT"]) {
|
16 |
+
$user_agent = $_SERVER["HTTP_USER_AGENT"];
|
17 |
+
}
|
18 |
+
if (strstr($user_agent, 'iPhone') || strstr($user_agent, 'iPod')) {
|
19 |
+
return 1;
|
20 |
+
} elseif (strstr($user_agent, 'iPad')) {
|
21 |
+
return 2;
|
22 |
+
} elseif (strstr($user_agent, 'Android')) {
|
23 |
+
return 3;
|
24 |
+
} else {
|
25 |
+
return 1;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
public function createKeyDevice($userEmail) {
|
30 |
+
$existed_device = Mage::getModel('simitracking/device')->getCollection()
|
31 |
+
->addFieldToFilter('is_key_token', 1)
|
32 |
+
->addFieldToFilter('user_email', $userEmail)->getFirstItem();
|
33 |
+
if (!$existed_device->getId()) {
|
34 |
+
$newDevice = Mage::getModel('simitracking/device');
|
35 |
+
$newDevice->setData('is_key_token', 1);
|
36 |
+
$newDevice->setData('user_email', $userEmail);
|
37 |
+
$newDevice->setData('device_token', 'nontoken_' . md5(time() . rand(1000000000, 9999999999)));
|
38 |
+
$newDevice->setData('session_id', md5(time() . rand(1000000000, 9999999999)));
|
39 |
+
$newDevice->setData('plaform_id', 99);
|
40 |
+
$newDevice->setData('session_deadline', time() + 86400 * 3);
|
41 |
+
$newDevice->setData('session_id', md5(time() . rand(1000000000, 9999999999)));
|
42 |
+
$newDevice->save();
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
public function saveDeviceFromQR($qrNewToken, $userEmail, $platformId) {
|
47 |
+
$deviceData = array();
|
48 |
+
$deviceData['device_token'] = $qrNewToken;
|
49 |
+
$deviceData['plaform_id'] = $platformId;
|
50 |
+
return $this->saveDevice($deviceData, $userEmail);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function saveDevice($deviceData, $userEmail = '') {
|
54 |
+
if (!$deviceData['device_token'])
|
55 |
+
return;
|
56 |
+
|
57 |
+
if (isset($deviceData['plaform_id']))
|
58 |
+
$device_id = $deviceData['plaform_id'];
|
59 |
+
else
|
60 |
+
$device_id = $this->detectMobile();
|
61 |
+
|
62 |
+
$existed_device = $this->getCollection()->addFieldToFilter('device_token', $deviceData['device_token'])->getFirstItem();
|
63 |
+
if ($existed_device->getId()) {
|
64 |
+
$this->setId($existed_device->getId());
|
65 |
+
}
|
66 |
+
$this->setData('session_id', md5(time() . rand(1000000000, 9999999999)));
|
67 |
+
$this->setData('session_deadline', time() + 86400 * 3);
|
68 |
+
$this->setData('user_email', $userEmail);
|
69 |
+
$this->setData('device_token', $deviceData['device_token']);
|
70 |
+
$this->setData('plaform_id', $device_id);
|
71 |
+
$this->setData('latitude', $deviceData['latitude']);
|
72 |
+
$this->setData('longitude', $deviceData['longitude']);
|
73 |
+
$this->setData('created_time', now());
|
74 |
+
$this->setData('app_id', $deviceData['app_id']);
|
75 |
+
$this->setData('device_ip', $_SERVER['REMOTE_ADDR']);
|
76 |
+
$this->setData('device_user_agent', $_SERVER['HTTP_USER_AGENT']);
|
77 |
+
$this->save();
|
78 |
+
|
79 |
+
return $this;
|
80 |
+
}
|
81 |
+
|
82 |
+
public function deleteDevice($deviceToken) {
|
83 |
+
$existed_device = $this->getCollection()->addFieldToFilter('device_token', $deviceToken)->getFirstItem();
|
84 |
+
if ($existed_device->getId()) {
|
85 |
+
$existed_device->delete();
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/Device.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_Device extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
$this->_init('simitracking/device', 'entity_id');
|
8 |
+
}
|
9 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/Device/Collection.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_Device_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('simitracking/device');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/Permission.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_Permission extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
$this->_init('simitracking/permission', 'entity_id');
|
8 |
+
}
|
9 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/Permission/Collection.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_Permission_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('simitracking/permission');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/Role.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_Role extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
$this->_init('simitracking/role', 'entity_id');
|
8 |
+
}
|
9 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/Role/Collection.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_Role_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('simitracking/role');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/User.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_User extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
$this->_init('simitracking/user', 'entity_id');
|
8 |
+
}
|
9 |
+
}
|
app/code/local/Simi/Simitracking/Model/Mysql4/User/Collection.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Mysql4_User_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('simitracking/user');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Simi/Simitracking/Model/Observer.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Observer {
|
4 |
+
|
5 |
+
public function orderPlacingCompleted($observer) {
|
6 |
+
if (!Mage::getStoreConfig('simitracking/general/new_order_notification')) {
|
7 |
+
return;
|
8 |
+
}
|
9 |
+
$orderId = $observer->getEvent()->getOrder()->getId();
|
10 |
+
try {
|
11 |
+
$orderProcessingReg = Mage::registry('simi_sent_new_notice_once');
|
12 |
+
if ($orderProcessingReg) {
|
13 |
+
$orderIdArray = explode(",", $orderProcessingReg);
|
14 |
+
if (in_array($orderId, $orderIdArray)) {
|
15 |
+
return;
|
16 |
+
}
|
17 |
+
$orderIdArray[] = $orderId;
|
18 |
+
Mage::register('simi_sent_new_notice_once', implode(",", $orderIdArray));
|
19 |
+
}
|
20 |
+
Mage::register('simi_sent_new_notice_once', $orderId);
|
21 |
+
Mage::helper('simitracking/siminotification')->sendNoticeNewOrder($orderId);
|
22 |
+
} catch (Exception $exc) {
|
23 |
+
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
public function orderSaveAfter($observer) {
|
28 |
+
try {
|
29 |
+
$order = $observer['order'];
|
30 |
+
if ($order->getData('state') == $order->getOrigData('state'))
|
31 |
+
return;
|
32 |
+
|
33 |
+
if ($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) {
|
34 |
+
if (!Mage::getStoreConfig('simitracking/general/order_processing_notification')) {
|
35 |
+
return;
|
36 |
+
}
|
37 |
+
$orderId = $order->getId();
|
38 |
+
|
39 |
+
$orderProcessingReg = Mage::registry('simi_sent_processing_notice_once');
|
40 |
+
if ($orderProcessingReg) {
|
41 |
+
$orderIdArray = explode(",", $orderProcessingReg);
|
42 |
+
if (in_array($orderId, $orderIdArray)) {
|
43 |
+
return;
|
44 |
+
}
|
45 |
+
$orderIdArray[] = $orderId;
|
46 |
+
Mage::register('simi_sent_processing_notice_once', implode(",", $orderIdArray));
|
47 |
+
}
|
48 |
+
Mage::register('simi_sent_processing_notice_once', $orderId);
|
49 |
+
Mage::helper('simitracking/siminotification')->sendNoticeProcessingOrder($orderId);
|
50 |
+
return;
|
51 |
+
} else if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE) {
|
52 |
+
if (!Mage::getStoreConfig('simitracking/general/order_completed_notification')) {
|
53 |
+
return;
|
54 |
+
}
|
55 |
+
$orderId = $order->getId();
|
56 |
+
|
57 |
+
$orderProcessingReg = Mage::registry('simi_sent_complete_notice_once');
|
58 |
+
if ($orderProcessingReg) {
|
59 |
+
$orderIdArray = explode(",", $orderProcessingReg);
|
60 |
+
if (in_array($orderId, $orderIdArray)) {
|
61 |
+
return;
|
62 |
+
}
|
63 |
+
$orderIdArray[] = $orderId;
|
64 |
+
Mage::register('simi_sent_complete_notice_once', implode(",", $orderIdArray));
|
65 |
+
}
|
66 |
+
Mage::register('simi_sent_complete_notice_once', $orderId);
|
67 |
+
Mage::helper('simitracking/siminotification')->sendNoticeCompletedOrder($orderId);
|
68 |
+
return;
|
69 |
+
}
|
70 |
+
} catch (Exception $exc) {
|
71 |
+
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
}
|
app/code/local/Simi/Simitracking/Model/Permission.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Permission extends Mage_Core_Model_Abstract {
|
4 |
+
|
5 |
+
protected $_eventPrefix = 'simitracking_permission';
|
6 |
+
protected $_eventObject = 'simitracking_permission';
|
7 |
+
|
8 |
+
public function _construct() {
|
9 |
+
parent::_construct();
|
10 |
+
$this->_init('simitracking/permission');
|
11 |
+
}
|
12 |
+
|
13 |
+
}
|
app/code/local/Simi/Simitracking/Model/Role.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_Role extends Mage_Core_Model_Abstract {
|
4 |
+
|
5 |
+
protected $_eventPrefix = 'simitracking_role';
|
6 |
+
protected $_eventObject = 'simitracking_role';
|
7 |
+
|
8 |
+
public function _construct() {
|
9 |
+
parent::_construct();
|
10 |
+
$this->_init('simitracking/role');
|
11 |
+
}
|
12 |
+
|
13 |
+
}
|
app/code/local/Simi/Simitracking/Model/Server.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Created by PhpStorm.
|
5 |
+
* User: Max
|
6 |
+
* Date: 5/2/16
|
7 |
+
* Time: 4:20 PM
|
8 |
+
*/
|
9 |
+
class Simi_Simitracking_Model_Server extends Simi_Simiconnector_Model_Server {
|
10 |
+
|
11 |
+
public function initialize(Simi_Simiconnector_Controller_Action $controller) {
|
12 |
+
parent::initialize($controller);
|
13 |
+
$data = $this->getData();
|
14 |
+
if (isset($data['params']) && isset($data['params']['session_id'])) {
|
15 |
+
Mage::helper('simitracking')->continueSessionWithSessionId($data['params']['session_id']);
|
16 |
+
} else if (isset($data['contents_array']) && isset($data['contents_array']['session_id'])) {
|
17 |
+
Mage::helper('simitracking')->continueSessionWithSessionId($data['contents_array']['session_id']);
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
}
|
app/code/local/Simi/Simitracking/Model/User.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Model_User extends Mage_Core_Model_Abstract {
|
4 |
+
|
5 |
+
protected $_eventPrefix = 'simitracking_user';
|
6 |
+
protected $_eventObject = 'simitracking_user';
|
7 |
+
|
8 |
+
public function _construct() {
|
9 |
+
parent::_construct();
|
10 |
+
$this->_init('simitracking/user');
|
11 |
+
}
|
12 |
+
|
13 |
+
}
|
app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/DeviceController.php
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Adminhtml_Simitracking_DeviceController extends Mage_Adminhtml_Controller_Action {
|
4 |
+
|
5 |
+
protected function _initAction() {
|
6 |
+
$this->loadLayout()
|
7 |
+
->_setActiveMenu('simitracking/device')
|
8 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Devices Manager'), Mage::helper('adminhtml')->__('Devices Manager'));
|
9 |
+
return $this;
|
10 |
+
}
|
11 |
+
|
12 |
+
/**
|
13 |
+
* index action
|
14 |
+
*/
|
15 |
+
public function indexAction() {
|
16 |
+
$this->_initAction()
|
17 |
+
->renderLayout();
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* view and edit item action
|
22 |
+
*/
|
23 |
+
public function editAction() {
|
24 |
+
$id = $this->getRequest()->getParam('id');
|
25 |
+
$model = Mage::getModel('simitracking/device')->load($id);
|
26 |
+
|
27 |
+
if ($model->getId() || $id == 0) {
|
28 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
29 |
+
if (!empty($data))
|
30 |
+
$model->setData($data);
|
31 |
+
|
32 |
+
Mage::register('device_data', $model);
|
33 |
+
|
34 |
+
$this->loadLayout();
|
35 |
+
$this->_setActiveMenu('simitracking/device');
|
36 |
+
|
37 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Device Manager'), Mage::helper('adminhtml')->__('Device Manager'));
|
38 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Device News'), Mage::helper('adminhtml')->__('Device News'));
|
39 |
+
|
40 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
41 |
+
$this->_addContent($this->getLayout()->createBlock('simitracking/adminhtml_device_edit'))
|
42 |
+
->_addLeft($this->getLayout()->createBlock('simitracking/adminhtml_device_edit_tabs'));
|
43 |
+
|
44 |
+
$this->renderLayout();
|
45 |
+
} else {
|
46 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('simitracking')->__('Device does not exist'));
|
47 |
+
$this->_redirect('*/*/');
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
public function newAction() {
|
52 |
+
$this->_forward('edit');
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* delete item action
|
57 |
+
*/
|
58 |
+
public function deleteAction() {
|
59 |
+
if ($this->getRequest()->getParam('id') > 0) {
|
60 |
+
try {
|
61 |
+
$model = Mage::getModel('simitracking/device');
|
62 |
+
$model->setId($this->getRequest()->getParam('id'))
|
63 |
+
->delete();
|
64 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Device was successfully deleted'));
|
65 |
+
$this->_redirect('*/*/');
|
66 |
+
} catch (Exception $e) {
|
67 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
68 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
69 |
+
}
|
70 |
+
}
|
71 |
+
$this->_redirect('*/*/');
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* mass delete item(s) action
|
76 |
+
*/
|
77 |
+
public function massDeleteAction() {
|
78 |
+
$deviceIds = $this->getRequest()->getParam('simitracking');
|
79 |
+
|
80 |
+
if (!is_array($deviceIds)) {
|
81 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
82 |
+
} else {
|
83 |
+
try {
|
84 |
+
foreach ($deviceIds as $deviceId) {
|
85 |
+
$device = Mage::getModel('simitracking/device')->load($deviceId);
|
86 |
+
if ($device->getData('is_key_token')!='1')
|
87 |
+
$device->delete();
|
88 |
+
}
|
89 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Total of %d device(s) were successfully deleted', count($bannerIds)));
|
90 |
+
} catch (Exception $e) {
|
91 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
92 |
+
}
|
93 |
+
}
|
94 |
+
$this->_redirect('*/*/index');
|
95 |
+
}
|
96 |
+
|
97 |
+
}
|
app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/RoleController.php
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Adminhtml_Simitracking_RoleController extends Mage_Adminhtml_Controller_Action {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* init layout and set active for current menu
|
7 |
+
*
|
8 |
+
* @return Simi_Simitracking_Adminhtml_Simitracking_RoleController
|
9 |
+
*/
|
10 |
+
protected function _initAction() {
|
11 |
+
$this->loadLayout()
|
12 |
+
->_setActiveMenu('simitracking/role')
|
13 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Role Manager'), Mage::helper('adminhtml')->__('Role Manager'));
|
14 |
+
return $this;
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* index action
|
19 |
+
*/
|
20 |
+
public function indexAction() {
|
21 |
+
$this->_initAction()
|
22 |
+
->renderLayout();
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* view and edit item action
|
27 |
+
*/
|
28 |
+
public function editAction() {
|
29 |
+
$id = $this->getRequest()->getParam('id');
|
30 |
+
$model = Mage::getModel('simitracking/role')->load($id);
|
31 |
+
if ($model->getId() || $id == 0) {
|
32 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
33 |
+
if (!empty($data))
|
34 |
+
$model->setData($data);
|
35 |
+
|
36 |
+
Mage::register('role_data', $model);
|
37 |
+
|
38 |
+
$this->loadLayout();
|
39 |
+
$this->_setActiveMenu('simitracking/role');
|
40 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
41 |
+
$this->_addContent($this->getLayout()->createBlock('simitracking/adminhtml_role_edit'))
|
42 |
+
->_addLeft($this->getLayout()->createBlock('simitracking/adminhtml_role_edit_tabs'));
|
43 |
+
|
44 |
+
$this->renderLayout();
|
45 |
+
} else {
|
46 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('simitracking')->__('Role does not exist'));
|
47 |
+
$this->_redirect('*/*/');
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
public function newAction() {
|
52 |
+
$this->_forward('edit');
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* save item action
|
57 |
+
*/
|
58 |
+
public function saveAction() {
|
59 |
+
if ($data = $this->getRequest()->getPost()) {
|
60 |
+
$model = Mage::getModel('simitracking/role');
|
61 |
+
$model->setData($data)
|
62 |
+
->setId($this->getRequest()->getParam('id'));
|
63 |
+
try {
|
64 |
+
$model->save();
|
65 |
+
if ($model->getId()) {
|
66 |
+
foreach (Mage::getModel('simitracking/permission')->getCollection()->addFieldToFilter('role_id', $model->getId()) as $permissionModel) {
|
67 |
+
$permissionModel->delete();
|
68 |
+
}
|
69 |
+
foreach ($data as $index => $permissions) {
|
70 |
+
if ($permissions == '1' && strpos($index, 'simi_permission_id_') !== false) {
|
71 |
+
$permissionModel = Mage::getModel('simitracking/permission');
|
72 |
+
$permissionModel->setData('role_id', $model->getId());
|
73 |
+
$permissionModel->setData('permission_id', str_replace('simi_permission_id_', '', $index));
|
74 |
+
$permissionModel->save();
|
75 |
+
$model->save();
|
76 |
+
}
|
77 |
+
}
|
78 |
+
}
|
79 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('simitracking')->__('Role was successfully saved'));
|
80 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
81 |
+
|
82 |
+
if ($this->getRequest()->getParam('back')) {
|
83 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
84 |
+
return;
|
85 |
+
}
|
86 |
+
$this->_redirect('*/*/');
|
87 |
+
return;
|
88 |
+
} catch (Exception $e) {
|
89 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
90 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
91 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
}
|
95 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('simitracking')->__('Unable to find item to save'));
|
96 |
+
$this->_redirect('*/*/');
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* delete item action
|
101 |
+
*/
|
102 |
+
public function deleteAction() {
|
103 |
+
if ($this->getRequest()->getParam('id') > 0) {
|
104 |
+
try {
|
105 |
+
$model = Mage::getModel('simitracking/role');
|
106 |
+
$model->setId($this->getRequest()->getParam('id'))
|
107 |
+
->delete();
|
108 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Role was successfully deleted'));
|
109 |
+
$this->_redirect('*/*/');
|
110 |
+
} catch (Exception $e) {
|
111 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
112 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
113 |
+
}
|
114 |
+
}
|
115 |
+
$this->_redirect('*/*/');
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* mass delete item(s) action
|
120 |
+
*/
|
121 |
+
public function massDeleteAction() {
|
122 |
+
$bannerIds = $this->getRequest()->getParam('simitracking');
|
123 |
+
|
124 |
+
if (!is_array($bannerIds)) {
|
125 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
126 |
+
} else {
|
127 |
+
try {
|
128 |
+
foreach ($bannerIds as $bannerId) {
|
129 |
+
$notice = Mage::getModel('simitracking/role')->load($bannerId);
|
130 |
+
$notice->delete();
|
131 |
+
}
|
132 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Total of %d record(s) were successfully deleted', count($bannerIds)));
|
133 |
+
} catch (Exception $e) {
|
134 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
135 |
+
}
|
136 |
+
}
|
137 |
+
$this->_redirect('*/*/index');
|
138 |
+
}
|
139 |
+
|
140 |
+
protected function _isAllowed() {
|
141 |
+
return Mage::getSingleton('admin/session')->isAllowed('simitracking');
|
142 |
+
}
|
143 |
+
|
144 |
+
}
|
app/code/local/Simi/Simitracking/controllers/Adminhtml/Simitracking/UserController.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_Adminhtml_Simitracking_UserController extends Mage_Adminhtml_Controller_Action {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* init layout and set active for current menu
|
7 |
+
*
|
8 |
+
* @return Simi_Simitracking_Adminhtml_Simitracking_UserController
|
9 |
+
*/
|
10 |
+
protected function _initAction() {
|
11 |
+
$this->loadLayout()
|
12 |
+
->_setActiveMenu('simitracking/user')
|
13 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('User Manager'), Mage::helper('adminhtml')->__('User Manager'));
|
14 |
+
return $this;
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* index action
|
19 |
+
*/
|
20 |
+
public function indexAction() {
|
21 |
+
$this->_initAction()
|
22 |
+
->renderLayout();
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* view and edit item action
|
27 |
+
*/
|
28 |
+
public function editAction() {
|
29 |
+
if (Mage::getModel('simitracking/role')->getCollection()->count() == 0)
|
30 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('simitracking')->__('There is No Role Created'));
|
31 |
+
$id = $this->getRequest()->getParam('id');
|
32 |
+
$model = Mage::getModel('simitracking/user')->load($id);
|
33 |
+
if ($model->getId() || $id == 0) {
|
34 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
35 |
+
if (!empty($data))
|
36 |
+
$model->setData($data);
|
37 |
+
|
38 |
+
Mage::register('user_data', $model);
|
39 |
+
|
40 |
+
$this->loadLayout();
|
41 |
+
$this->_setActiveMenu('simitracking/user');
|
42 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
43 |
+
$this->_addContent($this->getLayout()->createBlock('simitracking/adminhtml_user_edit'))
|
44 |
+
->_addLeft($this->getLayout()->createBlock('simitracking/adminhtml_user_edit_tabs'));
|
45 |
+
|
46 |
+
$this->renderLayout();
|
47 |
+
} else {
|
48 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('simitracking')->__('User does not exist'));
|
49 |
+
$this->_redirect('*/*/');
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
public function newAction() {
|
54 |
+
$this->_forward('edit');
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* save item action
|
59 |
+
*/
|
60 |
+
public function saveAction() {
|
61 |
+
if ($data = $this->getRequest()->getPost()) {
|
62 |
+
/*
|
63 |
+
* Profile Image
|
64 |
+
*/
|
65 |
+
if (isset($_FILES['user_profile_image_co']['name']) && $_FILES['user_profile_image_co']['name'] != '') {
|
66 |
+
try {
|
67 |
+
/* Starting upload */
|
68 |
+
$uploader = new Varien_File_Uploader('user_profile_image_co');
|
69 |
+
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
|
70 |
+
$uploader->setAllowRenameFiles(false);
|
71 |
+
$uploader->setFilesDispersion(false);
|
72 |
+
str_replace(" ", "_", $_FILES['user_profile_image_co']['name']);
|
73 |
+
$path = Mage::getBaseDir('media') . DS . 'simi' . DS . 'simitracking' . DS . 'profileimage';
|
74 |
+
if (!is_dir($path)) {
|
75 |
+
try {
|
76 |
+
mkdir($path, 0777, TRUE);
|
77 |
+
} catch (Exception $e) {
|
78 |
+
|
79 |
+
}
|
80 |
+
}
|
81 |
+
$result = $uploader->save($path, $_FILES['user_profile_image_co']['name']);
|
82 |
+
try {
|
83 |
+
chmod($path . '/' . $result['file'], 0777);
|
84 |
+
} catch (Exception $e) {
|
85 |
+
|
86 |
+
}
|
87 |
+
$data['user_profile_image'] = Mage::getBaseUrl('media') . 'simi/simitracking/profileimage/' . $result['file'];
|
88 |
+
} catch (Exception $e) {
|
89 |
+
$data['user_profile_image'] = Mage::getBaseUrl('media') . 'simi/simitracking/profileimage/' . $_FILES['user_profile_image_co']['name'];
|
90 |
+
}
|
91 |
+
}
|
92 |
+
if (isset($data['user_profile_image_co']['delete']) && $data['user_profile_image_co']['delete'] == 1) {
|
93 |
+
try {
|
94 |
+
unlink($data['user_profile_image_co']['value']);
|
95 |
+
} catch (Exception $e) {
|
96 |
+
|
97 |
+
}
|
98 |
+
$data['user_profile_image'] = '';
|
99 |
+
}
|
100 |
+
|
101 |
+
|
102 |
+
$model = Mage::getModel('simitracking/user');
|
103 |
+
$model->setData($data)
|
104 |
+
->setId($this->getRequest()->getParam('id'));
|
105 |
+
try {
|
106 |
+
$model->save();
|
107 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('simitracking')->__('User was successfully saved'));
|
108 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
109 |
+
$customer = Mage::getModel('simitracking/customer')->getCustomerByEmail($model->getData('user_email'));
|
110 |
+
if (!$customer->getId()) {
|
111 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('simitracking')->__('There is no customer account created with this email. Please create an account with the email you added or use another email.'));
|
112 |
+
}
|
113 |
+
Mage::getModel('simitracking/device')->createKeyDevice($model->getData('user_email'));
|
114 |
+
if ($this->getRequest()->getParam('back')) {
|
115 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
116 |
+
return;
|
117 |
+
}
|
118 |
+
$this->_redirect('*/*/');
|
119 |
+
return;
|
120 |
+
} catch (Exception $e) {
|
121 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
122 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
123 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
124 |
+
return;
|
125 |
+
}
|
126 |
+
}
|
127 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('simitracking')->__('Unable to find item to save'));
|
128 |
+
$this->_redirect('*/*/');
|
129 |
+
}
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
/**
|
134 |
+
* delete item action
|
135 |
+
*/
|
136 |
+
public function deleteAction() {
|
137 |
+
if ($this->getRequest()->getParam('id') > 0) {
|
138 |
+
try {
|
139 |
+
$model = Mage::getModel('simitracking/user');
|
140 |
+
$model->setId($this->getRequest()->getParam('id'))
|
141 |
+
->delete();
|
142 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('User was successfully deleted'));
|
143 |
+
$this->_redirect('*/*/');
|
144 |
+
} catch (Exception $e) {
|
145 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
146 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
147 |
+
}
|
148 |
+
}
|
149 |
+
$this->_redirect('*/*/');
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* mass delete item(s) action
|
154 |
+
*/
|
155 |
+
public function massDeleteAction() {
|
156 |
+
$bannerIds = $this->getRequest()->getParam('simitracking');
|
157 |
+
|
158 |
+
if (!is_array($bannerIds)) {
|
159 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
160 |
+
} else {
|
161 |
+
try {
|
162 |
+
foreach ($bannerIds as $bannerId) {
|
163 |
+
$notice = Mage::getModel('simitracking/user')->load($bannerId);
|
164 |
+
$notice->delete();
|
165 |
+
}
|
166 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Total of %d record(s) were successfully deleted', count($bannerIds)));
|
167 |
+
} catch (Exception $e) {
|
168 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
169 |
+
}
|
170 |
+
}
|
171 |
+
$this->_redirect('*/*/index');
|
172 |
+
}
|
173 |
+
|
174 |
+
protected function _isAllowed() {
|
175 |
+
return Mage::getSingleton('admin/session')->isAllowed('simitracking');
|
176 |
+
}
|
177 |
+
|
178 |
+
}
|
app/code/local/Simi/Simitracking/controllers/IndexController.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_IndexController extends Mage_Core_Controller_Front_Action
|
4 |
+
{
|
5 |
+
|
6 |
+
|
7 |
+
public function installDBAction()
|
8 |
+
{
|
9 |
+
$setup = new Mage_Core_Model_Resource_Setup('core_setup');
|
10 |
+
$installer = $setup;
|
11 |
+
$installer->startSetup();
|
12 |
+
|
13 |
+
$installer->run("
|
14 |
+
DROP TABLE IF EXISTS {$installer->getTable('simitracking_user')};
|
15 |
+
|
16 |
+
DROP TABLE IF EXISTS {$installer->getTable('simitracking_notice_history')};
|
17 |
+
|
18 |
+
CREATE TABLE {$installer->getTable('simitracking_user')} (
|
19 |
+
`entity_id` int(11) unsigned NOT NULL auto_increment,
|
20 |
+
`status` smallint(5) unsigned,
|
21 |
+
`user_profile_image` varchar(255) default '',
|
22 |
+
`user_title` varchar(255) default '',
|
23 |
+
`user_email` varchar(255) default '',
|
24 |
+
`is_receive_notification` int (11) default 1,
|
25 |
+
`notification_count` int (11) default 0,
|
26 |
+
`role_id` int (11) NOT NULL,
|
27 |
+
PRIMARY KEY (`entity_id`)
|
28 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
29 |
+
|
30 |
+
|
31 |
+
CREATE TABLE {$installer->getTable('simitracking_notice_history')} (
|
32 |
+
`history_id` int(11) unsigned NOT NULL auto_increment,
|
33 |
+
`notice_title` varchar(255) NULL default '',
|
34 |
+
`notice_content` text NULL default '',
|
35 |
+
`notice_sanbox` tinyint(1) NULL default '0',
|
36 |
+
`storeview_id` int (11),
|
37 |
+
`device_id` int (11),
|
38 |
+
`type` smallint(5) unsigned,
|
39 |
+
`show_popup` smallint(5) unsigned,
|
40 |
+
`created_time` datetime NOT NULL default '0000-00-00 00:00:00',
|
41 |
+
`notice_type` smallint(5) unsigned,
|
42 |
+
`status` smallint(5) unsigned,
|
43 |
+
`devices_pushed` text NULL default '',
|
44 |
+
PRIMARY KEY (`history_id`)
|
45 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
|
46 |
+
|
47 |
+
");
|
48 |
+
$installer->endSetup();
|
49 |
+
echo 'success';
|
50 |
+
}
|
51 |
+
public function addShippingDBAction()
|
52 |
+
{
|
53 |
+
$setup = new Mage_Core_Model_Resource_Setup('core_setup');
|
54 |
+
$installer = $setup;
|
55 |
+
$installer->startSetup();
|
56 |
+
$installer->getConnection()->addColumn($installer->getTable('simitracking/role'), 'shipping_method_show', "text NULL default ''");
|
57 |
+
$installer->endSetup();
|
58 |
+
echo 'success';
|
59 |
+
}
|
60 |
+
}
|
app/code/local/Simi/Simitracking/controllers/RestController.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Simi_Simitracking_RestController extends Simi_Simiconnector_Controller_Action {
|
4 |
+
public function preDispatch()
|
5 |
+
{
|
6 |
+
parent::preDispatch();
|
7 |
+
$enable = (int)Mage::getStoreConfig("simitracking/general/enable");
|
8 |
+
|
9 |
+
if (!$enable) {
|
10 |
+
echo 'SimiTracking Connector was disabled!';
|
11 |
+
header("HTTP/1.0 503");
|
12 |
+
exit();
|
13 |
+
}
|
14 |
+
}
|
15 |
+
|
16 |
+
protected function isHeader() {
|
17 |
+
return true;
|
18 |
+
}
|
19 |
+
|
20 |
+
|
21 |
+
public function v2Action() {
|
22 |
+
ob_start();
|
23 |
+
try {
|
24 |
+
$result = $this->_getServer()
|
25 |
+
->init($this)->run();
|
26 |
+
$this->_printData($result);
|
27 |
+
} catch (Exception $e) {
|
28 |
+
$results = array();
|
29 |
+
$result = array();
|
30 |
+
if (is_array($e->getMessage())) {
|
31 |
+
$messages = $e->getMessage();
|
32 |
+
foreach ($messages as $message) {
|
33 |
+
$result[] = array(
|
34 |
+
'code' => $e->getCode(),
|
35 |
+
'message' => $message,
|
36 |
+
);
|
37 |
+
}
|
38 |
+
} else {
|
39 |
+
$result[] = array(
|
40 |
+
'code' => $e->getCode(),
|
41 |
+
'message' => $e->getMessage(),
|
42 |
+
);
|
43 |
+
}
|
44 |
+
$results['errors'] = $result;
|
45 |
+
$this->_printData($results);
|
46 |
+
}
|
47 |
+
exit();
|
48 |
+
ob_end_flush();
|
49 |
+
}
|
50 |
+
|
51 |
+
protected function _getServer(){
|
52 |
+
return Mage::getSingleton('simitracking/server');
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
app/code/local/Simi/Simitracking/etc/adminhtml.xml
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<menu>
|
4 |
+
<simiconnector>
|
5 |
+
<children>
|
6 |
+
<simitracking module="simitracking" translate="title">
|
7 |
+
<title>Mobile Tracking</title>
|
8 |
+
<sort_order>299</sort_order>
|
9 |
+
<children>
|
10 |
+
<simitracking_user module="simitracking" translate="title">
|
11 |
+
<title>Users</title>
|
12 |
+
<sort_order>1</sort_order>
|
13 |
+
<action>adminhtml/simitracking_user</action>
|
14 |
+
</simitracking_user>
|
15 |
+
<simitracking_role module="simitracking" translate="title">
|
16 |
+
<title>Roles</title>
|
17 |
+
<sort_order>99</sort_order>
|
18 |
+
<action>adminhtml/simitracking_role</action>
|
19 |
+
</simitracking_role>
|
20 |
+
<simitracking_device module="simitracking" translate="title">
|
21 |
+
<title>Devices</title>
|
22 |
+
<sort_order>199</sort_order>
|
23 |
+
<action>adminhtml/simitracking_device</action>
|
24 |
+
</simitracking_device>
|
25 |
+
<simitracking_setting module="simitracking" translate="title">
|
26 |
+
<title>Settings</title>
|
27 |
+
<sort_order>299</sort_order>
|
28 |
+
<action>adminhtml/system_config/edit/section/simitracking</action>
|
29 |
+
</simitracking_setting>
|
30 |
+
</children>
|
31 |
+
</simitracking>
|
32 |
+
</children>
|
33 |
+
</simiconnector>
|
34 |
+
</menu>
|
35 |
+
<acl>
|
36 |
+
<resources>
|
37 |
+
<all>
|
38 |
+
<title>Allow Everything</title>
|
39 |
+
</all>
|
40 |
+
<admin>
|
41 |
+
<children>
|
42 |
+
<system>
|
43 |
+
<children>
|
44 |
+
<config>
|
45 |
+
<children>
|
46 |
+
<simitracking module="simitracking" translate="title">
|
47 |
+
<title>Simi Tracking</title>
|
48 |
+
<sort_order>71</sort_order>
|
49 |
+
</simitracking>
|
50 |
+
</children>
|
51 |
+
</config>
|
52 |
+
</children>
|
53 |
+
</system>
|
54 |
+
<simiconnector>
|
55 |
+
<children>
|
56 |
+
<simitracking module="simitracking" translate="title">
|
57 |
+
<title>Mobile Tracking</title>
|
58 |
+
<sort_order>299</sort_order>
|
59 |
+
<children>
|
60 |
+
<simitracking_user module="simitracking" translate="title">
|
61 |
+
<title>Users</title>
|
62 |
+
<sort_order>1</sort_order>
|
63 |
+
</simitracking_user>
|
64 |
+
<simitracking_role module="simitracking" translate="title">
|
65 |
+
<title>Roles</title>
|
66 |
+
<sort_order>99</sort_order>
|
67 |
+
</simitracking_role>
|
68 |
+
<simitracking_device module="simitracking" translate="title">
|
69 |
+
<title>Devices</title>
|
70 |
+
<sort_order>199</sort_order>
|
71 |
+
</simitracking_device>
|
72 |
+
<simitracking_setting module="simitracking" translate="title">
|
73 |
+
<title>Settings</title>
|
74 |
+
<sort_order>299</sort_order>
|
75 |
+
</simitracking_setting>
|
76 |
+
</children>
|
77 |
+
</simitracking>
|
78 |
+
</children>
|
79 |
+
</simiconnector>
|
80 |
+
</children>
|
81 |
+
</admin>
|
82 |
+
</resources>
|
83 |
+
</acl>
|
84 |
+
</config>
|
app/code/local/Simi/Simitracking/etc/config.xml
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Simi_Simitracking>
|
5 |
+
<version>0.1.2</version>
|
6 |
+
</Simi_Simitracking>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<routers>
|
10 |
+
<simitracking>
|
11 |
+
<use>standard</use>
|
12 |
+
<args>
|
13 |
+
<module>Simi_Simitracking</module>
|
14 |
+
<frontName>simitracking</frontName>
|
15 |
+
</args>
|
16 |
+
</simitracking>
|
17 |
+
</routers>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<simitracking>
|
21 |
+
<file>simitracking.xml</file>
|
22 |
+
</simitracking>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
<translate>
|
26 |
+
<modules>
|
27 |
+
<Simi_Simitracking>
|
28 |
+
<files>
|
29 |
+
<default>Simi_Simitracking.csv</default>
|
30 |
+
</files>
|
31 |
+
</Simi_Simitracking>
|
32 |
+
</modules>
|
33 |
+
</translate>
|
34 |
+
</frontend>
|
35 |
+
<admin>
|
36 |
+
<routers>
|
37 |
+
<adminhtml>
|
38 |
+
<args>
|
39 |
+
<modules>
|
40 |
+
<Simi_Simitracking before="Mage_Adminhtml">Simi_Simitracking_Adminhtml</Simi_Simitracking>
|
41 |
+
</modules>
|
42 |
+
</args>
|
43 |
+
</adminhtml>
|
44 |
+
</routers>
|
45 |
+
</admin>
|
46 |
+
<adminhtml>
|
47 |
+
<layout>
|
48 |
+
<updates>
|
49 |
+
<simitracking>
|
50 |
+
<file>simitracking.xml</file>
|
51 |
+
</simitracking>
|
52 |
+
</updates>
|
53 |
+
</layout>
|
54 |
+
<translate>
|
55 |
+
<modules>
|
56 |
+
<Simi_Simitracking>
|
57 |
+
<files>
|
58 |
+
<default>Simi_Simitracking.csv</default>
|
59 |
+
</files>
|
60 |
+
</Simi_Simitracking>
|
61 |
+
</modules>
|
62 |
+
</translate>
|
63 |
+
</adminhtml>
|
64 |
+
<global>
|
65 |
+
<models>
|
66 |
+
<simitracking>
|
67 |
+
<class>Simi_Simitracking_Model</class>
|
68 |
+
<resourceModel>simitracking_mysql4</resourceModel>
|
69 |
+
</simitracking>
|
70 |
+
<simitracking_mysql4>
|
71 |
+
<class>Simi_Simitracking_Model_Mysql4</class>
|
72 |
+
<entities>
|
73 |
+
<user>
|
74 |
+
<table>simitracking_user</table>
|
75 |
+
</user>
|
76 |
+
<role>
|
77 |
+
<table>simitracking_roles</table>
|
78 |
+
</role>
|
79 |
+
<permission>
|
80 |
+
<table>simitracking_permissions</table>
|
81 |
+
</permission>
|
82 |
+
<device>
|
83 |
+
<table>simitracking_devices</table>
|
84 |
+
</device>
|
85 |
+
</entities>
|
86 |
+
</simitracking_mysql4>
|
87 |
+
</models>
|
88 |
+
<resources>
|
89 |
+
<simitracking_setup>
|
90 |
+
<setup>
|
91 |
+
<module>Simi_Simitracking</module>
|
92 |
+
</setup>
|
93 |
+
<connection>
|
94 |
+
<use>core_setup</use>
|
95 |
+
</connection>
|
96 |
+
</simitracking_setup>
|
97 |
+
<simitracking_write>
|
98 |
+
<connection>
|
99 |
+
<use>core_write</use>
|
100 |
+
</connection>
|
101 |
+
</simitracking_write>
|
102 |
+
<simitracking_read>
|
103 |
+
<connection>
|
104 |
+
<use>core_read</use>
|
105 |
+
</connection>
|
106 |
+
</simitracking_read>
|
107 |
+
</resources>
|
108 |
+
<blocks>
|
109 |
+
<simitracking>
|
110 |
+
<class>Simi_Simitracking_Block</class>
|
111 |
+
</simitracking>
|
112 |
+
</blocks>
|
113 |
+
<helpers>
|
114 |
+
<simitracking>
|
115 |
+
<class>Simi_Simitracking_Helper</class>
|
116 |
+
</simitracking>
|
117 |
+
</helpers>
|
118 |
+
<events>
|
119 |
+
<sales_order_place_after>
|
120 |
+
<observers>
|
121 |
+
<simitracking_observers>
|
122 |
+
<type>singleton</type>
|
123 |
+
<class>simitracking/observer</class>
|
124 |
+
<method>orderPlacingCompleted</method>
|
125 |
+
</simitracking_observers>
|
126 |
+
</observers>
|
127 |
+
</sales_order_place_after>
|
128 |
+
<sales_order_save_after>
|
129 |
+
<observers>
|
130 |
+
<simitracking_observers_order_save_after>
|
131 |
+
<type>singleton</type>
|
132 |
+
<class>simitracking/observer</class>
|
133 |
+
<method>orderSaveAfter</method>
|
134 |
+
</simitracking_observers_order_save_after>
|
135 |
+
</observers>
|
136 |
+
</sales_order_save_after>
|
137 |
+
</events>
|
138 |
+
</global>
|
139 |
+
<default>
|
140 |
+
<simitracking>
|
141 |
+
<general>
|
142 |
+
<enable>1</enable>
|
143 |
+
<new_order_notification>0</new_order_notification>
|
144 |
+
<order_processing_notification>0</order_processing_notification>
|
145 |
+
<order_completed_notification>0</order_completed_notification>
|
146 |
+
</general>
|
147 |
+
</simitracking>
|
148 |
+
</default>
|
149 |
+
</config>
|
app/code/local/Simi/Simitracking/etc/system.xml
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<simitracking translate="label">
|
5 |
+
<label>SimiTracking</label>
|
6 |
+
<sort_order>500</sort_order>
|
7 |
+
</simitracking>
|
8 |
+
</tabs>
|
9 |
+
<sections>
|
10 |
+
<simitracking translate="label" module="simitracking">
|
11 |
+
<class>separator-top</class>
|
12 |
+
<label>SimiTracking Settings</label>
|
13 |
+
<tab>simitracking</tab>
|
14 |
+
<frontend_type>text</frontend_type>
|
15 |
+
<sort_order>1</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 |
+
<general translate="label">
|
21 |
+
<label>General Configuration</label>
|
22 |
+
<frontend_type>text</frontend_type>
|
23 |
+
<sort_order>1</sort_order>
|
24 |
+
<show_in_default>1</show_in_default>
|
25 |
+
<show_in_website>1</show_in_website>
|
26 |
+
<show_in_store>1</show_in_store>
|
27 |
+
<fields>
|
28 |
+
<enable translate="label">
|
29 |
+
<label>Enable</label>
|
30 |
+
<frontend_type>select</frontend_type>
|
31 |
+
<sort_order>1</sort_order>
|
32 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
33 |
+
<show_in_default>1</show_in_default>
|
34 |
+
<show_in_website>1</show_in_website>
|
35 |
+
<show_in_store>1</show_in_store>
|
36 |
+
<comment></comment>
|
37 |
+
</enable>
|
38 |
+
<new_order_notification translate="label">
|
39 |
+
<label>New Order Notification</label>
|
40 |
+
<frontend_type>select</frontend_type>
|
41 |
+
<sort_order>99</sort_order>
|
42 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
43 |
+
<show_in_default>1</show_in_default>
|
44 |
+
<show_in_website>1</show_in_website>
|
45 |
+
<show_in_store>1</show_in_store>
|
46 |
+
<comment></comment>
|
47 |
+
</new_order_notification>
|
48 |
+
<order_processing_notification translate="label">
|
49 |
+
<label>Order Processing Notification</label>
|
50 |
+
<frontend_type>select</frontend_type>
|
51 |
+
<sort_order>199</sort_order>
|
52 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
53 |
+
<show_in_default>1</show_in_default>
|
54 |
+
<show_in_website>1</show_in_website>
|
55 |
+
<show_in_store>1</show_in_store>
|
56 |
+
<comment></comment>
|
57 |
+
</order_processing_notification>
|
58 |
+
<order_completed_notification translate="label">
|
59 |
+
<label>Order Completed Notification</label>
|
60 |
+
<frontend_type>select</frontend_type>
|
61 |
+
<sort_order>299</sort_order>
|
62 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
63 |
+
<show_in_default>1</show_in_default>
|
64 |
+
<show_in_website>1</show_in_website>
|
65 |
+
<show_in_store>2</show_in_store>
|
66 |
+
<comment></comment>
|
67 |
+
</order_completed_notification>
|
68 |
+
</fields>
|
69 |
+
</general>
|
70 |
+
</groups>
|
71 |
+
</simitracking>
|
72 |
+
</sections>
|
73 |
+
</config>
|
app/code/local/Simi/Simitracking/sql/simitracking_setup/mysql4-install-0.1.0.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
$installer->startSetup();
|
5 |
+
$installer->run("
|
6 |
+
DROP TABLE IF EXISTS {$installer->getTable('simitracking_user')};
|
7 |
+
DROP TABLE IF EXISTS {$installer->getTable('simitracking_roles')};
|
8 |
+
DROP TABLE IF EXISTS {$installer->getTable('simitracking_permissions')};
|
9 |
+
DROP TABLE IF EXISTS {$installer->getTable('simitracking_devices')};
|
10 |
+
DROP TABLE IF EXISTS {$installer->getTable('simitracking_notice_history')};
|
11 |
+
|
12 |
+
CREATE TABLE {$installer->getTable('simitracking_user')} (
|
13 |
+
`entity_id` int(11) unsigned NOT NULL auto_increment,
|
14 |
+
`status` smallint(5) unsigned,
|
15 |
+
`user_profile_image` varchar(255) default '',
|
16 |
+
`user_title` varchar(255) default '',
|
17 |
+
`user_email` varchar(255) default '',
|
18 |
+
`is_receive_notification` int (11) default 1,
|
19 |
+
`notification_count` int (11) default 0,
|
20 |
+
`role_id` int (11) NOT NULL,
|
21 |
+
PRIMARY KEY (`entity_id`)
|
22 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
23 |
+
|
24 |
+
CREATE TABLE {$installer->getTable('simitracking_roles')} (
|
25 |
+
`entity_id` int(11) unsigned NOT NULL auto_increment,
|
26 |
+
`role_title` varchar(255) default '',
|
27 |
+
PRIMARY KEY (`entity_id`)
|
28 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
29 |
+
|
30 |
+
CREATE TABLE {$installer->getTable('simitracking_permissions')} (
|
31 |
+
`entity_id` int(11) unsigned NOT NULL auto_increment,
|
32 |
+
`role_id` varchar(255) default '',
|
33 |
+
`permission_id` varchar(255) default '',
|
34 |
+
PRIMARY KEY (`entity_id`)
|
35 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
36 |
+
|
37 |
+
CREATE TABLE {$installer->getTable('simitracking_devices')} (
|
38 |
+
`entity_id` int(11) unsigned NOT NULL auto_increment,
|
39 |
+
`user_email` varchar(255) default '',
|
40 |
+
`device_name` varchar(255) default '',
|
41 |
+
`plaform_id` int (11),
|
42 |
+
`is_key_token` int (11) default 0,
|
43 |
+
`device_token` varchar(255) default '',
|
44 |
+
`device_longitude` varchar(255) default '',
|
45 |
+
`device_latitude` varchar(255) default '',
|
46 |
+
`device_manufacture_number` varchar(255) default '',
|
47 |
+
`device_user_agent` varchar(255) default '',
|
48 |
+
`device_ip` varchar(255) default '',
|
49 |
+
`created_time` datetime NOT NULL default '0000-00-00 00:00:00',
|
50 |
+
`session_id` varchar(255) default '',
|
51 |
+
`session_deadline` int (11),
|
52 |
+
PRIMARY KEY (`entity_id`)
|
53 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
54 |
+
|
55 |
+
CREATE TABLE {$installer->getTable('simitracking_notice_history')} (
|
56 |
+
`history_id` int(11) unsigned NOT NULL auto_increment,
|
57 |
+
`notice_title` varchar(255) NULL default '',
|
58 |
+
`notice_content` text NULL default '',
|
59 |
+
`notice_sanbox` tinyint(1) NULL default '0',
|
60 |
+
`storeview_id` int (11),
|
61 |
+
`device_id` int (11),
|
62 |
+
`type` smallint(5) unsigned,
|
63 |
+
`show_popup` smallint(5) unsigned,
|
64 |
+
`created_time` datetime NOT NULL default '0000-00-00 00:00:00',
|
65 |
+
`notice_type` smallint(5) unsigned,
|
66 |
+
`status` smallint(5) unsigned,
|
67 |
+
`devices_pushed` text NULL default '',
|
68 |
+
PRIMARY KEY (`history_id`)
|
69 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
|
70 |
+
");
|
71 |
+
$installer->endSetup();
|
app/code/local/Simi/Simitracking/sql/simitracking_setup/mysql4-upgrade-0.1.1-0.1.2.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$installer->getConnection()->addColumn($this->getTable('simitracking/role'), 'is_owner_role', 'int (11) default 1');
|
8 |
+
|
9 |
+
$installer->endSetup();
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>simitracking_0117</name>
|
4 |
+
<version>4.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>Simicart License</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>SimiTracking Application Connector</summary>
|
10 |
+
<description>SimiTracking Application Connector</description>
|
11 |
+
<notes>4.0 Stable Version </notes>
|
12 |
+
<authors><author><name>Hải Tạ Hoàng</name><user>Maxta</user><email>max@simicart.com</email></author></authors>
|
13 |
+
<date>2017-02-17</date>
|
14 |
+
<time>06:28:57</time>
|
15 |
+
<contents><target name="magelocal"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="simitracking.xml" hash=""/></dir></dir></dir></dir><dir/><dir name="Simi"><dir name="Simitracking"><dir name="Block"><dir name="Adminhtml"><dir name="Device"><dir name="Edit"><file name="Form.php" hash="036d18067e12bd11f39d9e39d2641801"/><dir name="Renderer"><file name="Datetime.php" hash="81b059f6d6cdf2dca44c6dc3a858f156"/><file name="Selectname.php" hash="d9f8e1883aff776f787b32418ebc4e8a"/></dir><dir name="Tab"><file name="Form.php" hash="a434ab8b1cc478dfeaf631f35d4a3a93"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><file name="Tabs.php" hash="8a41ff373146b5d51af119463ea538eb"/><file name=".DS_Store" hash="b3163c5ab0472eea85b4850c35865d98"/></dir><file name="Edit.php" hash="63ab71f3802c4fd989548267d9a44362"/><file name="Grid.php" hash="aba3152f9e4a17c95359c6162fe01958"/></dir><file name="Device.php" hash="17cb6e33514d04d398fc92e02cf28216"/><dir name="Role"><dir name="Edit"><file name="Form.php" hash="98745e5bcc028184fffd474dd3a68312"/><dir name="Tab"><file name="Form.php" hash="f60c4f0b2a55d1b55c36138bf36c1e73"/></dir><file name="Tabs.php" hash="07f199941fd0fd3b87223b6c1d766041"/></dir><file name="Edit.php" hash="f491adcf8daa34bf621f4f74ccc5d630"/><file name="Grid.php" hash="7c61dcae7545d2a512560dbbac800e77"/></dir><file name="Role.php" hash="720bfd535d758be025639dd07678530f"/><dir name="User"><dir name="Edit"><file name="Form.php" hash="a258a989c740ca83d705960b61ca74c5"/><dir name="Tab"><file name="Form.php" hash="5fb9f203cba0a4ce7a2e41c1c4b85ed4"/></dir><file name="Tabs.php" hash="cc1061243942d039b9c8eee734fa3367"/></dir><file name="Edit.php" hash="85ab3afc7c81a36ef31d8986654f8cd0"/><file name="Grid.php" hash="3830aca04da53fd8e402772926354e95"/></dir><file name="User.php" hash="0d6830aaf8d35a781e48cf14d031a366"/></dir></dir><dir name="Helper"><file name="Data.php" hash="bc2cd2feb89eeff12ba6c53f16fc890c"/><file name="Siminotification.php" hash="63e1712e7999ac68a62a40ab1356e75f"/></dir><dir name="Model"><dir name="Api"><file name="Abandonedcarts.php" hash="056487cb98fb6f6d7c28803417b7eb3e"/><file name="Addresses.php" hash="76a2f668475566fd93c4443eecc7ff5d"/><file name="Bestsellers.php" hash="a084780631437d00cbc7cc5416b124ca"/><file name="Customers.php" hash="6059961fd5ee447112c3e1ab35d62dc3"/><file name="Orders.php" hash="7639212131c1f7806e3ccb276f4af286"/><file name="Permissions.php" hash="1792a04c2427c696f812ce1764d98650"/><file name="Products.php" hash="d24e5f2e1fd08e3c31f2aa9378e117b6"/><file name="Sales.php" hash="d30f71ab1eb138bc1407ecfd5fd32924"/><file name="Salesforecasts.php" hash="f8fb9667567d3f33bb968fff49348304"/><file name="Staffs.php" hash="39cfcbc8068980d1917a86a70480bc2a"/><file name="Stores.php" hash="8dd00a0faba107e393fdc0e1a8627d1d"/></dir><file name="Customer.php" hash="3a69090224c48775f916d83bcff45fe7"/><file name="Device.php" hash="05f8faff09abc1267182258633195206"/><dir name="Mysql4"><dir name="Device"><file name="Collection.php" hash="4afc9c43b92649b32ab9a5784128135d"/></dir><file name="Device.php" hash="4d90365b7307a7e266b2d3686b2c3122"/><dir name="Permission"><file name="Collection.php" hash="5add222dad87cdc858b3331706b91615"/></dir><file name="Permission.php" hash="6ea5abeff3a3d74b33f7123b10b70045"/><dir name="Role"><file name="Collection.php" hash="a9a3150fbe8e67ec531152132d28711b"/></dir><file name="Role.php" hash="325a6b1743d2e8a79553210df9a2fec0"/><dir name="User"><file name="Collection.php" hash="617df728b7566b6f52844eeaa94d55b0"/></dir><file name="User.php" hash="e79702866208f76deb0bf37c31ccfd2c"/></dir><file name="Observer.php" hash="ae24514f45db7809ed799eb88b3811d1"/><file name="Permission.php" hash="65bede053c439288db6cb4ad2e0b703f"/><file name="Role.php" hash="33a701063ee3293905845ff229bb0980"/><file name="Server.php" hash="f5e47775094f55790cf8147ed3c43932"/><file name="User.php" hash="9303f4eeaa8c6ffd10c411fff68bd5ac"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Simitracking"><file name="DeviceController.php" hash="99f1230094d135d1a8132411454f90f6"/><file name="RoleController.php" hash="fcaa7a04ff84e8679786d16153426ee0"/><file name="UserController.php" hash="4c08fcf33f82d3d626606ea6b5b20125"/></dir></dir><file name="IndexController.php" hash="613c4b15910ee97bb8df2c4187297ce7"/><file name="RestController.php" hash="4083fe4d3a054b22d162da5ef0cb08fd"/></dir><dir name="etc"><file name="adminhtml.xml" hash="02345039e416669d4a17b5be31c2f3da"/><file name="config.xml" hash="d7066d4e384ca8d1b82e9a588d4b6168"/><file name="system.xml" hash="129e1b673d0cba6d8e0ab61e0aeae83c"/></dir><dir name="sql"><dir name="simitracking_setup"><file name="mysql4-install-0.1.0.php" hash="90ddbc5bfd18afdd6f34998dbc8dc25f"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="ce000c3d827cad7e2463008d0e857601"/></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|