Version Notes
First release of the module
Download this release
Release Info
Developer | J2T DESIGN |
Extension | J2t_Mobilestats |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/J2t/Mobilestats/Helper/Data.php +5 -0
- app/code/community/J2t/Mobilestats/Model/Feed.php +104 -0
- app/code/community/J2t/Mobilestats/Model/Observer.php +14 -0
- app/code/community/J2t/Mobilestats/controllers/Adminhtml/StatsController.php +50 -0
- app/code/community/J2t/Mobilestats/controllers/IndexController.php +922 -0
- app/code/community/J2t/Mobilestats/etc/config.xml +64 -0
- app/etc/modules/J2t_Mobilestats.xml +9 -0
- package.xml +32 -0
app/code/community/J2t/Mobilestats/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?PHP
|
2 |
+
|
3 |
+
class J2t_Mobilestats_Helper_Data extends Mage_Core_Helper_Abstract {
|
4 |
+
|
5 |
+
}
|
app/code/community/J2t/Mobilestats/Model/Feed.php
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class J2t_Mobilestats_Model_Feed extends Mage_AdminNotification_Model_Feed {
|
3 |
+
|
4 |
+
const XML_FEED_URL_PATH_J2T = 'system/j2t_all/feed_url_j2t';
|
5 |
+
|
6 |
+
protected $_feedUrlJ2t;
|
7 |
+
|
8 |
+
public function checkUpdate()
|
9 |
+
{
|
10 |
+
if (($this->getFrequency() + $this->getLastUpdate()) > time()) {
|
11 |
+
return $this;
|
12 |
+
}
|
13 |
+
|
14 |
+
$feedData = array();
|
15 |
+
|
16 |
+
$feedXml = $this->getFeedData();
|
17 |
+
|
18 |
+
if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
|
19 |
+
foreach ($feedXml->channel->item as $item) {
|
20 |
+
$feedData[] = array(
|
21 |
+
'severity' => (int)$item->severity,
|
22 |
+
'date_added' => $this->getDate((string)$item->pubDate),
|
23 |
+
'title' => (string)$item->title,
|
24 |
+
'description' => (string)$item->description,
|
25 |
+
'url' => (string)$item->link,
|
26 |
+
);
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
if ($feedData) {
|
31 |
+
Mage::getModel('adminnotification/inbox')->parse(array_reverse($feedData));
|
32 |
+
}
|
33 |
+
|
34 |
+
}
|
35 |
+
|
36 |
+
$this->setLastUpdate();
|
37 |
+
|
38 |
+
return $this;
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Retrieve Last update time
|
44 |
+
*
|
45 |
+
* @return int
|
46 |
+
*/
|
47 |
+
public function getLastUpdate()
|
48 |
+
{
|
49 |
+
return Mage::app()->loadCache('j2t_notifications_lastcheck');
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Set last update time (now)
|
54 |
+
*
|
55 |
+
* @return Mage_AdminNotification_Model_Feed
|
56 |
+
*/
|
57 |
+
public function setLastUpdate()
|
58 |
+
{
|
59 |
+
Mage::app()->saveCache(time(), 'j2t_notifications_lastcheck');
|
60 |
+
return $this;
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
public function getFeedUrl()
|
66 |
+
{
|
67 |
+
if (is_null($this->_feedUrlJ2t)) {
|
68 |
+
$this->_feedUrlJ2t = (Mage::getStoreConfigFlag(self::XML_USE_HTTPS_PATH) ? 'https://' : 'http://')
|
69 |
+
. Mage::getStoreConfig(self::XML_FEED_URL_PATH_J2T);
|
70 |
+
}
|
71 |
+
return $this->_feedUrlJ2t;
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
public function getFeedData()
|
76 |
+
{
|
77 |
+
$curl = new Varien_Http_Adapter_Curl();
|
78 |
+
$curl->setConfig(array(
|
79 |
+
'timeout' => 3
|
80 |
+
));
|
81 |
+
|
82 |
+
$curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
|
83 |
+
$data = $curl->read();
|
84 |
+
if ($data === false) {
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
$data = preg_split('/^\r?$/m', $data, 2);
|
88 |
+
$data = trim($data[1]);
|
89 |
+
$curl->close();
|
90 |
+
|
91 |
+
try {
|
92 |
+
$xml = new SimpleXMLElement($data);
|
93 |
+
}
|
94 |
+
catch (Exception $e) {
|
95 |
+
return false;
|
96 |
+
}
|
97 |
+
|
98 |
+
return $xml;
|
99 |
+
}
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
|
104 |
+
?>
|
app/code/community/J2t/Mobilestats/Model/Observer.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class J2t_Mobilestats_Model_Observer
|
3 |
+
{
|
4 |
+
public function preDispatch(Varien_Event_Observer $observer)
|
5 |
+
{
|
6 |
+
if (Mage::getSingleton('admin/session')->isLoggedIn()) {
|
7 |
+
$feedModel = Mage::getModel('j2t_mobilestats/feed');
|
8 |
+
/* @var $feedModel Mage_AdminNotification_Model_Feed */
|
9 |
+
|
10 |
+
$feedModel->checkUpdate();
|
11 |
+
}
|
12 |
+
|
13 |
+
}
|
14 |
+
}
|
app/code/community/J2t/Mobilestats/controllers/Adminhtml/StatsController.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* J2T MobileStats
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is available through the world-wide-web at this URL:
|
9 |
+
* http://opensource.org/licenses/osl-3.0.php
|
10 |
+
* If you did not receive a copy of the license and are unable to
|
11 |
+
* obtain it through the world-wide-web, please send an email
|
12 |
+
* to license@j2t-design.com so we can send you a copy immediately.
|
13 |
+
*
|
14 |
+
* @category Magento extension
|
15 |
+
* @package J2t_Mobilestats
|
16 |
+
* @copyright Copyright (c) 2012 J2T DESIGN. (http://www.j2t-design.com)
|
17 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
18 |
+
*/
|
19 |
+
class J2t_Mobilestats_Adminhtml_StatsController extends Mage_Adminhtml_Controller_Action
|
20 |
+
{
|
21 |
+
|
22 |
+
|
23 |
+
public function indexAction()
|
24 |
+
{
|
25 |
+
echo "Hello, World.";
|
26 |
+
die;
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
public function statsAction()
|
32 |
+
{
|
33 |
+
echo 'ici';
|
34 |
+
die;
|
35 |
+
/*$response = $this->getResponse();
|
36 |
+
$response->setHeader('HTTP/1.1 200 OK','');
|
37 |
+
$response->setHeader('Pragma', 'public', true);
|
38 |
+
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
|
39 |
+
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
|
40 |
+
$response->setHeader('Last-Modified', date('r'));
|
41 |
+
$response->setHeader('Accept-Ranges', 'bytes');
|
42 |
+
$response->setHeader('Content-Length', strlen($content));
|
43 |
+
$response->setHeader('Content-type', $contentType);
|
44 |
+
$response->setBody($content);
|
45 |
+
$response->sendResponse();*/
|
46 |
+
die;
|
47 |
+
}
|
48 |
+
|
49 |
+
|
50 |
+
}
|
app/code/community/J2t/Mobilestats/controllers/IndexController.php
ADDED
@@ -0,0 +1,922 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* J2T MobileStats
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is available through the world-wide-web at this URL:
|
9 |
+
* http://opensource.org/licenses/osl-3.0.php
|
10 |
+
* If you did not receive a copy of the license and are unable to
|
11 |
+
* obtain it through the world-wide-web, please send an email
|
12 |
+
* to license@j2t-design.com so we can send you a copy immediately.
|
13 |
+
*
|
14 |
+
* @category Magento extension
|
15 |
+
* @package J2t_Mobilestats
|
16 |
+
* @copyright Copyright (c) 2012 J2T DESIGN. (http://www.j2t-design.com)
|
17 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
18 |
+
*/
|
19 |
+
class J2t_Mobilestats_IndexController extends Mage_Core_Controller_Front_Action
|
20 |
+
{
|
21 |
+
public function indexAction()
|
22 |
+
{
|
23 |
+
|
24 |
+
$session = Mage::getSingleton('admin/session');
|
25 |
+
/** @var $session Mage_Admin_Model_Session */
|
26 |
+
$request = Mage::app()->getRequest();
|
27 |
+
|
28 |
+
|
29 |
+
if ($request->getPost('login')) {
|
30 |
+
$postLogin = $request->getPost('login');
|
31 |
+
|
32 |
+
$username = isset($postLogin['username']) ? $postLogin['username'] : '';
|
33 |
+
$password = isset($postLogin['password']) ? $postLogin['password'] : '';
|
34 |
+
//$session->login($username, $password, $request);
|
35 |
+
|
36 |
+
$user = Mage::getModel('admin/user');
|
37 |
+
$user->login($username, $password);
|
38 |
+
if ($user->getId()) {
|
39 |
+
|
40 |
+
echo 'OK';
|
41 |
+
} else {
|
42 |
+
echo 'KO';
|
43 |
+
}
|
44 |
+
}
|
45 |
+
die;
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
public function loginAction()
|
50 |
+
{
|
51 |
+
$return_value = array();
|
52 |
+
$session = Mage::getSingleton('admin/session');
|
53 |
+
/** @var $session Mage_Admin_Model_Session */
|
54 |
+
$request = Mage::app()->getRequest();
|
55 |
+
if ($request->getParam('username') && $request->getParam('password')) {
|
56 |
+
|
57 |
+
$username = ($request->getParam('username')) ? $request->getParam('username') : '';
|
58 |
+
$password = ($request->getParam('password')) ? $request->getParam('password') : '';
|
59 |
+
|
60 |
+
$user = Mage::getModel('admin/user');
|
61 |
+
$user->login($username, $password);
|
62 |
+
if ($user->getId()) {
|
63 |
+
|
64 |
+
$return_value['state'] = 'OK';
|
65 |
+
} else {
|
66 |
+
$return_value['state'] = 'KO';
|
67 |
+
}
|
68 |
+
} else {
|
69 |
+
$return_value['state'] = 'ERROR-URI';
|
70 |
+
}
|
71 |
+
echo $_GET['callback'] . '(' . json_encode($return_value) . ');';
|
72 |
+
die;
|
73 |
+
}
|
74 |
+
|
75 |
+
protected function loginUser($username, $password)
|
76 |
+
{
|
77 |
+
$return_value = array();
|
78 |
+
$session = Mage::getSingleton('admin/session');
|
79 |
+
if ($username && $password) {
|
80 |
+
|
81 |
+
$user = Mage::getModel('admin/user');
|
82 |
+
$user->login($username, $password);
|
83 |
+
if ($user->getId()) {
|
84 |
+
return true;
|
85 |
+
} else {
|
86 |
+
return false;
|
87 |
+
}
|
88 |
+
} else {
|
89 |
+
return false;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
|
94 |
+
public function dashboardAction(){
|
95 |
+
$return_value = array();
|
96 |
+
|
97 |
+
$request = Mage::app()->getRequest();
|
98 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
99 |
+
if ($this->loginUser($username, $password)){
|
100 |
+
//last 24h >> 24h
|
101 |
+
//last 7 days >> 7d
|
102 |
+
//current month >> 1m
|
103 |
+
//YTD >> 1y
|
104 |
+
//2YTD >> 2y
|
105 |
+
|
106 |
+
$period = ($request->getParam('period') != "") ? $request->getParam('period') : "24h";
|
107 |
+
$type = ($request->getParam('type') != "") ? $request->getParam('type') : "quantity";
|
108 |
+
|
109 |
+
///////////////////////////// Summary /////////////////////////////
|
110 |
+
|
111 |
+
$isFilter = $request->getParam('store') || $request->getParam('website') || $request->getParam('group');
|
112 |
+
$period = $request->getParam('period', '24h');
|
113 |
+
|
114 |
+
/* @var $collection Mage_Reports_Model_Mysql4_Order_Collection */
|
115 |
+
$collection = Mage::getResourceModel('reports/order_collection')
|
116 |
+
->addCreateAtPeriodFilter($period)
|
117 |
+
->calculateTotals($isFilter);
|
118 |
+
|
119 |
+
$store_currency = Mage::app()->getStore()->getId();
|
120 |
+
|
121 |
+
if ($request->getParam('store')) {
|
122 |
+
$collection->addFieldToFilter('store_id', $request->getParam('store'));
|
123 |
+
$store_currency = $request->getParam('store');
|
124 |
+
} else if ($request->getParam('website')){
|
125 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
126 |
+
$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
127 |
+
} else if ($request->getParam('group')){
|
128 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
129 |
+
$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
130 |
+
} elseif (!$collection->isLive()) {
|
131 |
+
$collection->addFieldToFilter('store_id',
|
132 |
+
array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId())
|
133 |
+
);
|
134 |
+
}
|
135 |
+
|
136 |
+
$collection->load();
|
137 |
+
|
138 |
+
$totals = $collection->getFirstItem();
|
139 |
+
|
140 |
+
$currency_code = Mage::app()->getStore($store_currency)->getBaseCurrencyCode();
|
141 |
+
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($currency_code);
|
142 |
+
$revenue = $this->renderCurrency($totals->getRevenue(), $currency_code, $rate);
|
143 |
+
$tax = $this->renderCurrency($totals->getTax(), $currency_code, $rate);
|
144 |
+
$shipping = $this->renderCurrency($totals->getShipping(), $currency_code, $rate);
|
145 |
+
|
146 |
+
$return_value['revenue'] = $revenue;
|
147 |
+
$return_value['tax'] = $tax;
|
148 |
+
$return_value['shipping'] = $shipping;
|
149 |
+
$return_value['quantity'] = ($totals->getQuantity()) ? ($totals->getQuantity()*1) : 0;
|
150 |
+
|
151 |
+
///////////////////////////// Summary /////////////////////////////
|
152 |
+
|
153 |
+
//$all_series = $this->getRowsData(array('quantity'), false, $period);
|
154 |
+
$all_series = $this->getRowsData(array($type), false, $period);
|
155 |
+
|
156 |
+
|
157 |
+
/*$axisMaps = array(
|
158 |
+
'x' => 'range',
|
159 |
+
'y' => 'quantity'
|
160 |
+
);*/
|
161 |
+
$axisMaps = array(
|
162 |
+
'x' => 'range',
|
163 |
+
'y' => $type
|
164 |
+
);
|
165 |
+
$axisLabels = array();
|
166 |
+
|
167 |
+
foreach ($axisMaps as $axis => $attr){
|
168 |
+
//$this->setAxisLabels($axis, $this->getRowsData($attr, true));
|
169 |
+
$axisLabels[$axis] = $this->getRowsData($attr, true, $period);
|
170 |
+
}
|
171 |
+
|
172 |
+
/*echo '<pre>';
|
173 |
+
print_r($axisLabels);
|
174 |
+
die;*/
|
175 |
+
|
176 |
+
//$period = '24h';
|
177 |
+
$timezoneLocal = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
|
178 |
+
|
179 |
+
|
180 |
+
if ($request->getParam('store')) {
|
181 |
+
if ($request->getParam('store') != 0){
|
182 |
+
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
list ($dateStart, $dateEnd) = Mage::getResourceModel('reports/order_collection')
|
187 |
+
->getDateRange($period, '', '', true);
|
188 |
+
|
189 |
+
$dateStart->setTimezone($timezoneLocal);
|
190 |
+
$dateEnd->setTimezone($timezoneLocal);
|
191 |
+
|
192 |
+
$dates = array();
|
193 |
+
$dates_mk = array();
|
194 |
+
$datas = array();
|
195 |
+
|
196 |
+
|
197 |
+
$return_label = "";
|
198 |
+
$return_min_tick_size = "";
|
199 |
+
$return_time_format = "";
|
200 |
+
|
201 |
+
while($dateStart->compare($dateEnd) < 0){
|
202 |
+
switch ($period) {
|
203 |
+
case '24h':
|
204 |
+
$d = $dateStart->toString('yyyy-MM-dd HH:00');
|
205 |
+
$d_mk = Varien_Date::toTimestamp($d);//$dateStart->get(Zend_Date::TIMESTAMP);
|
206 |
+
$dateStart->addHour(1);
|
207 |
+
$return_label = $this->__('Sales: Last 24 Hours');
|
208 |
+
$return_min_tick_size = "hour";
|
209 |
+
$return_time_format = "%H:%M";
|
210 |
+
break;
|
211 |
+
case '7d':
|
212 |
+
$d = $dateStart->toString('yyyy-MM-dd');
|
213 |
+
$d_mk = Varien_Date::toTimestamp($d);//$dateStart->get(Zend_Date::TIMESTAMP);
|
214 |
+
$dateStart->addDay(1);
|
215 |
+
$return_label = $this->__('Sales: Last 7 days');
|
216 |
+
$return_min_tick_size = "day";
|
217 |
+
$return_time_format = "%d/%m/%y";
|
218 |
+
break;
|
219 |
+
case '1m':
|
220 |
+
$d = $dateStart->toString('yyyy-MM-dd');
|
221 |
+
$d_mk = Varien_Date::toTimestamp($d);//$dateStart->get(Zend_Date::TIMESTAMP);
|
222 |
+
$dateStart->addDay(1);
|
223 |
+
$return_label = $this->__('Sales: Current month');
|
224 |
+
$return_min_tick_size = "day";
|
225 |
+
$return_time_format = "%d/%m/%y";
|
226 |
+
break;
|
227 |
+
case '1y':
|
228 |
+
$d = $dateStart->toString('yyyy-MM');
|
229 |
+
$d_mk = Varien_Date::toTimestamp($d);//$dateStart->get(Zend_Date::TIMESTAMP);
|
230 |
+
$dateStart->addMonth(1);
|
231 |
+
$return_label = $this->__('Sales: YTD');
|
232 |
+
$return_min_tick_size = "month";
|
233 |
+
$return_time_format = "%d/%m/%y";
|
234 |
+
break;
|
235 |
+
case '2y':
|
236 |
+
$d = $dateStart->toString('yyyy-MM');
|
237 |
+
$d_mk = Varien_Date::toTimestamp($d);//$dateStart->get(Zend_Date::TIMESTAMP);
|
238 |
+
$dateStart->addMonth(1);
|
239 |
+
$return_label = $this->__('Sales: 2YTD');
|
240 |
+
$return_min_tick_size = "month";
|
241 |
+
$return_time_format = "%d/%m/%y";
|
242 |
+
break;
|
243 |
+
}
|
244 |
+
|
245 |
+
foreach ($all_series as $index=>$serie) {
|
246 |
+
if (in_array($d, $axisLabels['x'])) {
|
247 |
+
$datas[$index][] = (float)array_shift($all_series[$index]);
|
248 |
+
} else {
|
249 |
+
$datas[$index][] = 0;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
$dates[] = $d;
|
253 |
+
$dates_mk[] = $d_mk;
|
254 |
+
}
|
255 |
+
|
256 |
+
$dates_arr = array();
|
257 |
+
foreach ($dates_mk as $key => $date_mk){
|
258 |
+
$dates_arr[] = array($date_mk, $datas[$type][$key]);
|
259 |
+
}
|
260 |
+
|
261 |
+
$return_value['mode'] = 'time';
|
262 |
+
//$return_value['time_format'] = '%d/%m/%y';
|
263 |
+
$return_value['time_format'] = $return_time_format;
|
264 |
+
$return_value['min_tick_size'] = $return_min_tick_size;
|
265 |
+
$return_value['label'] = $return_label;
|
266 |
+
|
267 |
+
$return_value['data'] = $dates_arr;
|
268 |
+
|
269 |
+
$return_value['state'] = 'OK';
|
270 |
+
} else {
|
271 |
+
$return_value['state'] = 'KO';
|
272 |
+
}
|
273 |
+
} else {
|
274 |
+
$return_value['state'] = 'ERROR-URI';
|
275 |
+
}
|
276 |
+
|
277 |
+
echo $_GET['callback'] . '(' . json_encode($return_value) . ');';
|
278 |
+
die;
|
279 |
+
}
|
280 |
+
|
281 |
+
protected function getRowsData($attributes = array('quantity'), $single = false, $period = '24h')
|
282 |
+
{
|
283 |
+
$request = Mage::app()->getRequest();
|
284 |
+
$isFilter = $request->getParam('store') || $request->getParam('website') || $request->getParam('group');
|
285 |
+
|
286 |
+
$collection = Mage::getResourceSingleton('reports/order_collection')->prepareSummary($period, 0, 0, $isFilter);
|
287 |
+
if ($isFilter){
|
288 |
+
$collection->addAttributeToFilter('store_id', $request->getParam('store'));
|
289 |
+
}
|
290 |
+
|
291 |
+
$items = $collection->getItems();
|
292 |
+
|
293 |
+
$options = array();
|
294 |
+
foreach ($items as $item){
|
295 |
+
if ($single) {
|
296 |
+
$options[] = max(0, $item->getData($attributes));
|
297 |
+
} else {
|
298 |
+
foreach ((array)$attributes as $attr){
|
299 |
+
$options[$attr][] = max(0, $item->getData($attr));
|
300 |
+
}
|
301 |
+
}
|
302 |
+
}
|
303 |
+
return $options;
|
304 |
+
}
|
305 |
+
|
306 |
+
|
307 |
+
public function testAction(){
|
308 |
+
$return['module_installed'] = 1;
|
309 |
+
|
310 |
+
echo $_GET['callback'] . '(' . json_encode($return) . ');';
|
311 |
+
die;
|
312 |
+
}
|
313 |
+
|
314 |
+
protected function renderCurrency($data, $currency_code, $rate)
|
315 |
+
{
|
316 |
+
if (!$currency_code) {
|
317 |
+
return $data;
|
318 |
+
}
|
319 |
+
|
320 |
+
$data = floatval($data) * $rate;
|
321 |
+
$data = sprintf("%f", $data);
|
322 |
+
$data = Mage::app()->getLocale()->currency($currency_code)->toCurrency($data);
|
323 |
+
return $data;
|
324 |
+
}
|
325 |
+
|
326 |
+
public function newestcustomerAction() {
|
327 |
+
$return_value = array();
|
328 |
+
|
329 |
+
$request = Mage::app()->getRequest();
|
330 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
331 |
+
if ($this->loginUser($username, $password)){
|
332 |
+
// get all most viewed product
|
333 |
+
//data:['Date', 'User', 'Tweet'],
|
334 |
+
//cols: ['15%', '35%', '40%']
|
335 |
+
$return_value['data'] = array($this->__('Customer Name'), $this->__('Number of Orders'), $this->__('Average Order Amount'), $this->__('Total Order Amount'));
|
336 |
+
$return_value['cols'] = array('40%', '20%', '20%', '20%');
|
337 |
+
|
338 |
+
|
339 |
+
$collection = Mage::getResourceModel('reports/customer_collection')
|
340 |
+
->addCustomerName();
|
341 |
+
|
342 |
+
$storeFilter = 0;
|
343 |
+
|
344 |
+
|
345 |
+
$store_currency = Mage::app()->getStore()->getId();
|
346 |
+
|
347 |
+
if ($request->getParam('store')) {
|
348 |
+
$collection->addAttributeToFilter('store_id', $request->getParam('store'));
|
349 |
+
$store_currency = $request->getParam('store');
|
350 |
+
$storeFilter = 1;
|
351 |
+
} else if ($request->getParam('website')){
|
352 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
353 |
+
$collection->addAttributeToFilter('store_id', array('in' => $storeIds));
|
354 |
+
} else if ($request->getParam('group')){
|
355 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
356 |
+
$collection->addAttributeToFilter('store_id', array('in' => $storeIds));
|
357 |
+
}
|
358 |
+
|
359 |
+
$collection->addOrdersStatistics($storeFilter)
|
360 |
+
->orderByCustomerRegistration();
|
361 |
+
|
362 |
+
$collection->setPageSize(10);
|
363 |
+
|
364 |
+
|
365 |
+
|
366 |
+
$return_value['external_call'] = 'customer';
|
367 |
+
$return_value['external_elements'] = array();
|
368 |
+
|
369 |
+
$return_value['content'] = array();
|
370 |
+
|
371 |
+
$currency_code = Mage::app()->getStore($store_currency)->getBaseCurrencyCode();
|
372 |
+
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($currency_code);
|
373 |
+
foreach($collection as $customer) {
|
374 |
+
//'Customer Name', 'Number of Orders', 'Average Order Amount', 'Total Order Amount'
|
375 |
+
$customer_name = $customer->getData('name');
|
376 |
+
$nb_order = $customer->getData('orders_count');
|
377 |
+
|
378 |
+
//$currency_code = Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode();
|
379 |
+
|
380 |
+
$average_amount = $this->renderCurrency($customer->getData('orders_avg_amount'), $currency_code, $rate);
|
381 |
+
$total_amount = $this->renderCurrency($customer->getData('orders_sum_amount'), $currency_code, $rate);
|
382 |
+
|
383 |
+
$return_value['content'][] = array($customer_name, $nb_order, $average_amount, $total_amount);
|
384 |
+
$return_value['external_elements'][] = $customer->getId();
|
385 |
+
|
386 |
+
}
|
387 |
+
$return_value['state'] = 'OK';
|
388 |
+
|
389 |
+
} else {
|
390 |
+
$return_value['state'] = 'KO';
|
391 |
+
}
|
392 |
+
} else {
|
393 |
+
$return_value['state'] = 'ERROR-URI';
|
394 |
+
}
|
395 |
+
|
396 |
+
return $return_value;
|
397 |
+
}
|
398 |
+
|
399 |
+
public function last5searchesAction(){
|
400 |
+
$return_value = array();
|
401 |
+
|
402 |
+
$request = Mage::app()->getRequest();
|
403 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
404 |
+
if ($this->loginUser($username, $password)){
|
405 |
+
|
406 |
+
$collection = Mage::getModel('catalogsearch/query')
|
407 |
+
->getResourceCollection();
|
408 |
+
$collection->setRecentQueryFilter();
|
409 |
+
|
410 |
+
if($request->getParam('store') || $request->getParam('website') || $request->getParam('group')) {
|
411 |
+
if ($request->getParam('store')) {
|
412 |
+
$collection->addFieldToFilter('store_id', $request->getParam('store'));
|
413 |
+
} else if ($request->getParam('website')){
|
414 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
415 |
+
$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
416 |
+
} else if ($request->getParam('group')){
|
417 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
418 |
+
$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
419 |
+
}
|
420 |
+
}
|
421 |
+
$collection->setPageSize(5);
|
422 |
+
|
423 |
+
$return_value['data'] = array($this->__('Search Term'), $this->__('Results'), $this->__('Number of Uses'));
|
424 |
+
$return_value['cols'] = array('50%', '25%', '25%');
|
425 |
+
|
426 |
+
$return_value['content'] = array();
|
427 |
+
foreach($collection as $search) {
|
428 |
+
|
429 |
+
$query_text = $search->getData('query_text');
|
430 |
+
$num_results = $search->getData('num_results');
|
431 |
+
$popularity = $search->getData('popularity');
|
432 |
+
|
433 |
+
|
434 |
+
$return_value['content'][] = array($query_text, $num_results, $popularity);
|
435 |
+
|
436 |
+
}
|
437 |
+
|
438 |
+
$return_value['state'] = 'OK';
|
439 |
+
|
440 |
+
} else {
|
441 |
+
$return_value['state'] = 'KO';
|
442 |
+
}
|
443 |
+
} else {
|
444 |
+
$return_value['state'] = 'ERROR-URI';
|
445 |
+
}
|
446 |
+
|
447 |
+
return $return_value;
|
448 |
+
}
|
449 |
+
|
450 |
+
public function top5searchesAction(){
|
451 |
+
$return_value = array();
|
452 |
+
|
453 |
+
$request = Mage::app()->getRequest();
|
454 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
455 |
+
if ($this->loginUser($username, $password)){
|
456 |
+
|
457 |
+
$collection = Mage::getModel('catalogsearch/query')
|
458 |
+
->getResourceCollection();
|
459 |
+
//$collection->setRecentQueryFilter();
|
460 |
+
|
461 |
+
$storeIds = '';
|
462 |
+
if($request->getParam('store') || $request->getParam('website') || $request->getParam('group')) {
|
463 |
+
if ($request->getParam('store')) {
|
464 |
+
$storeIds = $request->getParam('store');
|
465 |
+
$collection->addFieldToFilter('store_id', $request->getParam('store'));
|
466 |
+
} else if ($request->getParam('website')){
|
467 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
468 |
+
//$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
469 |
+
} else if ($request->getParam('group')){
|
470 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
471 |
+
//$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
472 |
+
}
|
473 |
+
}
|
474 |
+
$collection->setPopularQueryFilter($storeIds);
|
475 |
+
$collection->setPageSize(5);
|
476 |
+
|
477 |
+
$return_value['data'] = array($this->__('Search Term'), $this->__('Results'), $this->__('Number of Uses'));
|
478 |
+
$return_value['cols'] = array('50%', '25%', '25%');
|
479 |
+
|
480 |
+
$return_value['content'] = array();
|
481 |
+
foreach($collection as $search) {
|
482 |
+
|
483 |
+
$name = $search->getData('name');
|
484 |
+
$num_results = $search->getData('num_results');
|
485 |
+
$popularity = $search->getData('popularity');
|
486 |
+
|
487 |
+
|
488 |
+
$return_value['content'][] = array($name, $num_results, $popularity);
|
489 |
+
|
490 |
+
}
|
491 |
+
|
492 |
+
$return_value['state'] = 'OK';
|
493 |
+
|
494 |
+
} else {
|
495 |
+
$return_value['state'] = 'KO';
|
496 |
+
}
|
497 |
+
} else {
|
498 |
+
$return_value['state'] = 'ERROR-URI';
|
499 |
+
}
|
500 |
+
|
501 |
+
return $return_value;
|
502 |
+
}
|
503 |
+
|
504 |
+
public function orderdetailsAction() {
|
505 |
+
$return_value = array();
|
506 |
+
|
507 |
+
$request = Mage::app()->getRequest();
|
508 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
509 |
+
if ($this->loginUser($username, $password)){
|
510 |
+
$order_id = $request->getParam('id');
|
511 |
+
$order_details = Mage::getModel('sales/order')->load($order_id);
|
512 |
+
|
513 |
+
$return_value['content'] = "";
|
514 |
+
|
515 |
+
if ($order_details->getId()){
|
516 |
+
$content = $this->__("Order: %s (%s)", $order_details->getIncrementId(), $order_details->getStatus());
|
517 |
+
$content .= "<br />".$this->__("Nb of items ordered: %s", count($order_details->getAllItems()));
|
518 |
+
|
519 |
+
$currency_code = Mage::app()->getStore($order_details->getStoreId())->getBaseCurrencyCode();
|
520 |
+
$rate = 1;
|
521 |
+
$shipping = $this->renderCurrency($order_details->getShippingAmount(), $currency_code, $rate);
|
522 |
+
$tax = $this->renderCurrency($order_details->getTaxAmount(), $currency_code, $rate);
|
523 |
+
$grand = $this->renderCurrency($order_details->getGrandTotal(), $currency_code, $rate);
|
524 |
+
$discount = $this->renderCurrency($order_details->getDiscountAmount(), $currency_code, $rate);
|
525 |
+
|
526 |
+
$content .= "<br />".$this->__("Discount: %s", $discount);
|
527 |
+
$content .= "<br />".$this->__("Shipping: %s", $shipping);
|
528 |
+
$content .= "<br />".$this->__("Total (tax %s): %s", $tax, $grand);
|
529 |
+
|
530 |
+
$return_value['content'] = $content;
|
531 |
+
}
|
532 |
+
|
533 |
+
$return_value['state'] = 'OK';
|
534 |
+
} else {
|
535 |
+
$return_value['state'] = 'KO';
|
536 |
+
}
|
537 |
+
} else {
|
538 |
+
$return_value['state'] = 'ERROR-URI';
|
539 |
+
}
|
540 |
+
|
541 |
+
echo $_GET['callback'] . '(' . json_encode($return_value) . ');';
|
542 |
+
die;
|
543 |
+
}
|
544 |
+
|
545 |
+
public function customerdetailsAction() {
|
546 |
+
$return_value = array();
|
547 |
+
|
548 |
+
$request = Mage::app()->getRequest();
|
549 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
550 |
+
if ($this->loginUser($username, $password)){
|
551 |
+
$customer_id = $request->getParam('id');
|
552 |
+
$customer_details = Mage::getModel('customer/customer')->load($customer_id);
|
553 |
+
|
554 |
+
$return_value['content'] = "";
|
555 |
+
|
556 |
+
if ($customer_details->getId()){
|
557 |
+
$content = $this->__("Name: %s", $customer_details->getName());
|
558 |
+
$content .= "<br />".$this->__("Email: %s", $customer_details->getEmail());
|
559 |
+
|
560 |
+
|
561 |
+
$group = Mage::getModel('customer/group')->load($customer_details->getGroupId());
|
562 |
+
|
563 |
+
$content .= "<br />".$this->__("Customer Group: %s", $group->getCode());
|
564 |
+
|
565 |
+
$return_value['content'] = $content;
|
566 |
+
}
|
567 |
+
|
568 |
+
$return_value['state'] = 'OK';
|
569 |
+
} else {
|
570 |
+
$return_value['state'] = 'KO';
|
571 |
+
}
|
572 |
+
} else {
|
573 |
+
$return_value['state'] = 'ERROR-URI';
|
574 |
+
}
|
575 |
+
|
576 |
+
echo $_GET['callback'] . '(' . json_encode($return_value) . ');';
|
577 |
+
die;
|
578 |
+
}
|
579 |
+
|
580 |
+
public function last5ordersAction(){
|
581 |
+
$return_value = array();
|
582 |
+
|
583 |
+
$request = Mage::app()->getRequest();
|
584 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
585 |
+
if ($this->loginUser($username, $password)){
|
586 |
+
|
587 |
+
$collection = Mage::getResourceModel('reports/order_collection')
|
588 |
+
->addItemCountExpr()
|
589 |
+
->joinCustomerName('customer')
|
590 |
+
->orderByCreatedAt();
|
591 |
+
|
592 |
+
$store_currency = Mage::app()->getStore()->getId();
|
593 |
+
|
594 |
+
if($request->getParam('store') || $request->getParam('website') || $request->getParam('group')) {
|
595 |
+
if ($request->getParam('store')) {
|
596 |
+
$collection->addAttributeToFilter('store_id', $request->getParam('store'));
|
597 |
+
$store_currency = $request->getParam('store');
|
598 |
+
} else if ($request->getParam('website')){
|
599 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
600 |
+
$collection->addAttributeToFilter('store_id', array('in' => $storeIds));
|
601 |
+
} else if ($request->getParam('group')){
|
602 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
603 |
+
$collection->addAttributeToFilter('store_id', array('in' => $storeIds));
|
604 |
+
}
|
605 |
+
$collection->addRevenueToSelect();
|
606 |
+
} else {
|
607 |
+
$collection->addRevenueToSelect(true);
|
608 |
+
}
|
609 |
+
$collection->setPageSize(5);
|
610 |
+
|
611 |
+
$return_value['data'] = array($this->__('Customer'), $this->__('Items'), $this->__('Grand Total'));
|
612 |
+
$return_value['cols'] = array('50%', '25%', '25%');
|
613 |
+
|
614 |
+
$return_value['external_call'] = 'order';
|
615 |
+
$return_value['external_elements'] = array();
|
616 |
+
|
617 |
+
$currency_code = Mage::app()->getStore($store_currency)->getBaseCurrencyCode();
|
618 |
+
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($currency_code);
|
619 |
+
|
620 |
+
$return_value['content'] = array();
|
621 |
+
foreach($collection as $order) {
|
622 |
+
$customer = $order->getData('customer');
|
623 |
+
$items_count = $order->getData('items_count');
|
624 |
+
|
625 |
+
|
626 |
+
$revenue = $this->renderCurrency($order->getRevenue(), $currency_code, $rate);
|
627 |
+
|
628 |
+
$return_value['content'][] = array($customer, $items_count, $revenue);
|
629 |
+
$return_value['external_elements'][] = $order->getId();
|
630 |
+
|
631 |
+
}
|
632 |
+
|
633 |
+
$return_value['state'] = 'OK';
|
634 |
+
|
635 |
+
} else {
|
636 |
+
$return_value['state'] = 'KO';
|
637 |
+
}
|
638 |
+
} else {
|
639 |
+
$return_value['state'] = 'ERROR-URI';
|
640 |
+
}
|
641 |
+
|
642 |
+
return $return_value;
|
643 |
+
}
|
644 |
+
|
645 |
+
public function mostviewedAction() {
|
646 |
+
$return_value = array();
|
647 |
+
|
648 |
+
$request = Mage::app()->getRequest();
|
649 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
650 |
+
if ($this->loginUser($username, $password)){
|
651 |
+
// get all most viewed product
|
652 |
+
//data:['Date', 'User', 'Tweet'],
|
653 |
+
//cols: ['15%', '35%', '40%']
|
654 |
+
$return_value['data'] = array($this->__('Product Name'), $this->__('Price'), $this->__('Number of Views'));
|
655 |
+
$return_value['cols'] = array('50%', '25%', '25%');
|
656 |
+
|
657 |
+
$store_currency = Mage::app()->getStore()->getId();
|
658 |
+
|
659 |
+
if ($request->getParam('store')){
|
660 |
+
$storeId = (int)$request->getParam('store');
|
661 |
+
$store_currency = $request->getParam('store');
|
662 |
+
} else {
|
663 |
+
$storeIds = Mage::app()->getWebsite(1)->getStoreIds();
|
664 |
+
$storeId = array_pop($storeIds);
|
665 |
+
}
|
666 |
+
|
667 |
+
$collection = Mage::getResourceModel('reports/product_collection')
|
668 |
+
->addAttributeToSelect('*')
|
669 |
+
->addViewsCount()
|
670 |
+
->setStoreId($storeId)
|
671 |
+
->addStoreFilter($storeId);
|
672 |
+
|
673 |
+
$collection->setPageSize(10);
|
674 |
+
$return_value['content'] = array();
|
675 |
+
foreach($collection as $product) {
|
676 |
+
|
677 |
+
//Mage::log($product->getData()
|
678 |
+
$views = $product->getData('views');
|
679 |
+
//$price = $product->getPrice();
|
680 |
+
|
681 |
+
$currency_code = Mage::app()->getStore($store_currency)->getBaseCurrencyCode();
|
682 |
+
|
683 |
+
|
684 |
+
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($currency_code);
|
685 |
+
$price = $this->renderCurrency($product->getPrice(), $currency_code, $rate);
|
686 |
+
|
687 |
+
$name = $product->getName();
|
688 |
+
$return_value['content'][] = array($name, $price, $views);
|
689 |
+
|
690 |
+
}
|
691 |
+
$return_value['state'] = 'OK';
|
692 |
+
|
693 |
+
} else {
|
694 |
+
$return_value['state'] = 'KO';
|
695 |
+
}
|
696 |
+
} else {
|
697 |
+
$return_value['state'] = 'ERROR-URI';
|
698 |
+
}
|
699 |
+
|
700 |
+
return $return_value;
|
701 |
+
}
|
702 |
+
|
703 |
+
|
704 |
+
public function bestsellersAction() {
|
705 |
+
$return_value = array();
|
706 |
+
|
707 |
+
$request = Mage::app()->getRequest();
|
708 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
709 |
+
if ($this->loginUser($username, $password)){
|
710 |
+
$return_value['data'] = array($this->__('Product Name'), $this->__('Price'), $this->__('Quantity Ordered'));
|
711 |
+
$return_value['cols'] = array('50%', '25%', '25%');
|
712 |
+
|
713 |
+
$collection = Mage::getResourceModel('sales/report_bestsellers_collection')
|
714 |
+
->setModel('catalog/product');
|
715 |
+
|
716 |
+
$storeId = '';
|
717 |
+
|
718 |
+
$store_currency = Mage::app()->getStore()->getId();
|
719 |
+
if ($request->getParam('website')) {
|
720 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
721 |
+
$storeId = array_pop($storeIds);
|
722 |
+
} else if ($request->getParam('group')) {
|
723 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
724 |
+
$storeId = array_pop($storeIds);
|
725 |
+
} else if ($request->getParam('store')) {
|
726 |
+
$storeId = (int)$request->getParam('store');
|
727 |
+
$store_currency = $request->getParam('store');
|
728 |
+
}
|
729 |
+
|
730 |
+
$collection->addStoreFilter($storeId);
|
731 |
+
|
732 |
+
$collection->setPageSize(10);
|
733 |
+
|
734 |
+
$currency_code = Mage::app()->getStore($store_currency)->getBaseCurrencyCode();
|
735 |
+
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($currency_code);
|
736 |
+
|
737 |
+
$return_value['content'] = array();
|
738 |
+
foreach($collection as $order) {
|
739 |
+
$product_name = $order->getData('product_name');
|
740 |
+
$product_price = $this->renderCurrency($order->getData('product_price'), $currency_code, $rate);
|
741 |
+
$qty_ordered = $order->getData('qty_ordered');
|
742 |
+
$return_value['content'][] = array($product_name, $product_price, $qty_ordered);
|
743 |
+
}
|
744 |
+
$return_value['state'] = 'OK';
|
745 |
+
|
746 |
+
} else {
|
747 |
+
$return_value['state'] = 'KO';
|
748 |
+
}
|
749 |
+
} else {
|
750 |
+
$return_value['state'] = 'ERROR-URI';
|
751 |
+
}
|
752 |
+
|
753 |
+
return $return_value;
|
754 |
+
}
|
755 |
+
|
756 |
+
|
757 |
+
public function mostcustomerAction() {
|
758 |
+
$return_value = array();
|
759 |
+
|
760 |
+
$request = Mage::app()->getRequest();
|
761 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
762 |
+
if ($this->loginUser($username, $password)){
|
763 |
+
// get all most viewed product
|
764 |
+
//data:['Date', 'User', 'Tweet'],
|
765 |
+
//cols: ['15%', '35%', '40%']
|
766 |
+
$return_value['data'] = array($this->__('Customer Name'), $this->__('Number of Orders'), $this->__('Average Order Amount'), $this->__('Total Order Amount'));
|
767 |
+
$return_value['cols'] = array('40%', '20%', '20%', '20%');
|
768 |
+
|
769 |
+
$collection = Mage::getResourceModel('reports/order_collection');
|
770 |
+
|
771 |
+
$collection
|
772 |
+
->groupByCustomer()
|
773 |
+
->addOrdersCount()
|
774 |
+
->joinCustomerName();
|
775 |
+
|
776 |
+
$collection->setPageSize(10);
|
777 |
+
|
778 |
+
$storeFilter = 0;
|
779 |
+
|
780 |
+
|
781 |
+
$store_currency = Mage::app()->getStore()->getId();
|
782 |
+
if ($request->getParam('store')) {
|
783 |
+
$collection->addAttributeToFilter('store_id', $request->getParam('store'));
|
784 |
+
$store_currency = $request->getParam('store');
|
785 |
+
$storeFilter = 1;
|
786 |
+
} else if ($request->getParam('website')){
|
787 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
788 |
+
$collection->addAttributeToFilter('store_id', array('in' => $storeIds));
|
789 |
+
} else if ($request->getParam('group')){
|
790 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
791 |
+
$collection->addAttributeToFilter('store_id', array('in' => $storeIds));
|
792 |
+
}
|
793 |
+
|
794 |
+
$collection->addSumAvgTotals($storeFilter)
|
795 |
+
->orderByTotalAmount();
|
796 |
+
|
797 |
+
|
798 |
+
$currency_code = Mage::app()->getStore($store_currency)->getBaseCurrencyCode();
|
799 |
+
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($currency_code);
|
800 |
+
|
801 |
+
$return_value['content'] = array();
|
802 |
+
foreach($collection as $customer) {
|
803 |
+
//'Customer Name', 'Number of Orders', 'Average Order Amount', 'Total Order Amount'
|
804 |
+
$customer_name = $customer->getData('name');
|
805 |
+
$nb_order = $customer->getData('orders_count');
|
806 |
+
|
807 |
+
$average_amount = $this->renderCurrency($customer->getData('orders_avg_amount'), $currency_code, $rate);
|
808 |
+
$total_amount = $this->renderCurrency($customer->getData('orders_sum_amount'), $currency_code, $rate);
|
809 |
+
|
810 |
+
$return_value['content'][] = array($customer_name, $nb_order, $average_amount, $total_amount);
|
811 |
+
|
812 |
+
}
|
813 |
+
$return_value['state'] = 'OK';
|
814 |
+
|
815 |
+
} else {
|
816 |
+
$return_value['state'] = 'KO';
|
817 |
+
}
|
818 |
+
} else {
|
819 |
+
$return_value['state'] = 'ERROR-URI';
|
820 |
+
}
|
821 |
+
|
822 |
+
return $return_value;
|
823 |
+
}
|
824 |
+
|
825 |
+
public function tablestatsAction() {
|
826 |
+
//mostviewed
|
827 |
+
//newestcustomer
|
828 |
+
$return_value = array();
|
829 |
+
$return_value['state'] = 'KO';
|
830 |
+
$request = Mage::app()->getRequest();
|
831 |
+
if ($type = $request->getParam('type')){
|
832 |
+
if ($type == 'newestcustomer'){
|
833 |
+
$return_value = $this->newestcustomerAction();
|
834 |
+
} else if ($type == 'mostcustomer') {
|
835 |
+
$return_value = $this->mostcustomerAction();
|
836 |
+
} else if ($type == 'lastfiveorders') {
|
837 |
+
$return_value = $this->last5ordersAction();
|
838 |
+
} else if ($type == 'lastfivesearches'){
|
839 |
+
$return_value = $this->last5searchesAction();
|
840 |
+
} else if ($type == 'topfivesearches'){
|
841 |
+
$return_value = $this->top5searchesAction();
|
842 |
+
} else if ($type == 'bestsellers'){
|
843 |
+
$return_value = $this->bestsellersAction();
|
844 |
+
} else {
|
845 |
+
$return_value = $this->mostviewedAction();
|
846 |
+
}
|
847 |
+
}
|
848 |
+
|
849 |
+
if ($return_value['state'] == 'OK'){
|
850 |
+
$dashboard_main = $this->dashboardMain();
|
851 |
+
$return_value['lifetimesale'] = $dashboard_main['lifetimesale'];
|
852 |
+
$return_value['averageorders'] = $dashboard_main['averageorders'];
|
853 |
+
}
|
854 |
+
|
855 |
+
echo $_GET['callback'] . '(' . json_encode($return_value) . ');';
|
856 |
+
die;
|
857 |
+
}
|
858 |
+
|
859 |
+
public function getstoresAction() {
|
860 |
+
$return_value = array();
|
861 |
+
$request = Mage::app()->getRequest();
|
862 |
+
$return_value['data'] = array();
|
863 |
+
|
864 |
+
//$return_value['data'][] = array('label' => $this->__('All Store Views'), 'value' => 0);
|
865 |
+
if (($username = $request->getParam('username')) && ($password = $request->getParam('password'))) {
|
866 |
+
if ($this->loginUser($username, $password)){
|
867 |
+
$allStores = Mage::app()->getStores();
|
868 |
+
foreach ($allStores as $_eachStoreId => $val)
|
869 |
+
{
|
870 |
+
$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
|
871 |
+
$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
|
872 |
+
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
|
873 |
+
|
874 |
+
|
875 |
+
$return_value['data'][] = array('code' => $_storeCode, 'label' => $_storeName, 'value' => $_storeId);
|
876 |
+
}
|
877 |
+
$return_value['state'] = 'OK';
|
878 |
+
} else {
|
879 |
+
$return_value['state'] = 'KO';
|
880 |
+
}
|
881 |
+
} else {
|
882 |
+
$return_value['state'] = 'ERROR-URI';
|
883 |
+
}
|
884 |
+
echo $_GET['callback'] . '(' . json_encode($return_value) . ');';
|
885 |
+
die;
|
886 |
+
}
|
887 |
+
|
888 |
+
|
889 |
+
protected function dashboardMain() {
|
890 |
+
|
891 |
+
$request = Mage::app()->getRequest();
|
892 |
+
|
893 |
+
$isFilter = $request->getParam('store') || $request->getParam('website') || $request->getParam('group');
|
894 |
+
|
895 |
+
$collection = Mage::getResourceModel('reports/order_collection')
|
896 |
+
->calculateSales($isFilter);
|
897 |
+
|
898 |
+
$store_currency = Mage::app()->getStore()->getId();
|
899 |
+
if ($request->getParam('store')) {
|
900 |
+
$collection->addFieldToFilter('store_id', $request->getParam('store'));
|
901 |
+
$store_currency = $request->getParam('store');
|
902 |
+
} else if ($request->getParam('website')){
|
903 |
+
$storeIds = Mage::app()->getWebsite($request->getParam('website'))->getStoreIds();
|
904 |
+
$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
905 |
+
} else if ($request->getParam('group')){
|
906 |
+
$storeIds = Mage::app()->getGroup($request->getParam('group'))->getStoreIds();
|
907 |
+
$collection->addFieldToFilter('store_id', array('in' => $storeIds));
|
908 |
+
}
|
909 |
+
|
910 |
+
$collection->load();
|
911 |
+
$sales = $collection->getFirstItem();
|
912 |
+
|
913 |
+
$currency_code = Mage::app()->getStore($store_currency)->getBaseCurrencyCode();
|
914 |
+
$rate = Mage::app()->getStore()->getBaseCurrency()->getRate($currency_code);
|
915 |
+
|
916 |
+
$lifetimesale = $this->renderCurrency($sales->getLifetime(), $currency_code, $rate);
|
917 |
+
$averageorders = $this->renderCurrency($sales->getAverage(), $currency_code, $rate);
|
918 |
+
|
919 |
+
return array("lifetimesale" => $lifetimesale, "averageorders" => $averageorders);
|
920 |
+
}
|
921 |
+
|
922 |
+
}
|
app/code/community/J2t/Mobilestats/etc/config.xml
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<modules>
|
5 |
+
<J2t_Mobilestats>
|
6 |
+
<version>1.0.0</version>
|
7 |
+
</J2t_Mobilestats>
|
8 |
+
</modules>
|
9 |
+
|
10 |
+
<global>
|
11 |
+
<models>
|
12 |
+
<j2t_mobilestats>
|
13 |
+
<class>J2t_Mobilestats_Model</class>
|
14 |
+
</j2t_mobilestats>
|
15 |
+
</models>
|
16 |
+
</global>
|
17 |
+
|
18 |
+
<admin>
|
19 |
+
<secure_url>
|
20 |
+
<j2t_mobilestats>/j2tmobilestats</j2t_mobilestats>
|
21 |
+
</secure_url>
|
22 |
+
<routers>
|
23 |
+
<j2t_mobilestats>
|
24 |
+
<use>admin</use>
|
25 |
+
<args>
|
26 |
+
<module>J2t_Mobilestats</module>
|
27 |
+
<frontName>j2tmobilestats_admin</frontName>
|
28 |
+
</args>
|
29 |
+
</j2t_mobilestats>
|
30 |
+
</routers>
|
31 |
+
</admin>
|
32 |
+
|
33 |
+
<adminhtml>
|
34 |
+
<events>
|
35 |
+
<controller_action_predispatch>
|
36 |
+
<observers>
|
37 |
+
<j2t_mobilestats>
|
38 |
+
<class>j2t_mobilestats/observer</class>
|
39 |
+
<method>preDispatch</method>
|
40 |
+
</j2t_mobilestats>
|
41 |
+
</observers>
|
42 |
+
</controller_action_predispatch>
|
43 |
+
</events>
|
44 |
+
</adminhtml>
|
45 |
+
|
46 |
+
<frontend>
|
47 |
+
<routers>
|
48 |
+
<j2t_mobilestats>
|
49 |
+
<use>standard</use>
|
50 |
+
<args>
|
51 |
+
<module>J2t_Mobilestats</module>
|
52 |
+
<frontName>j2tmobilestats</frontName>
|
53 |
+
</args>
|
54 |
+
</j2t_mobilestats>
|
55 |
+
</routers>
|
56 |
+
</frontend>
|
57 |
+
<default>
|
58 |
+
<system>
|
59 |
+
<j2t_all>
|
60 |
+
<feed_url_j2t>j2t-design.net/notifications.rss</feed_url_j2t>
|
61 |
+
</j2t_all>
|
62 |
+
</system>
|
63 |
+
</default>
|
64 |
+
</config>
|
app/etc/modules/J2t_Mobilestats.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<J2t_Mobilestats>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</J2t_Mobilestats>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>J2t_Mobilestats</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>OSL</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>J2T Magento Mobile Stats is creating a bridge between your store and a mobile application!</summary>
|
10 |
+
<description>J2T Magento Mobile Stats is creating a bridge between your store and a mobile application!
|
11 |
+

|
12 |
+
It is possible with this module to check:
|
13 |
+

|
14 |
+
your sales quantity/amount with a graph
|
15 |
+
most viewed products
|
16 |
+
the bestsellers
|
17 |
+
new customers
|
18 |
+
customers that buy the most
|
19 |
+
last 5 orders
|
20 |
+
last 5 search terms
|
21 |
+
top 5 search terms
|
22 |
+
Download the Android or iPhone app to enjoy!
|
23 |
+

|
24 |
+
You simply need to put your store URL and your admin username/password to access to the above details!</description>
|
25 |
+
<notes>First release of the module</notes>
|
26 |
+
<authors><author><name>J2T DESIGN</name><user>j2tdesign</user><email>contact@j2t-design.net</email></author></authors>
|
27 |
+
<date>2012-06-04</date>
|
28 |
+
<time>12:33:03</time>
|
29 |
+
<contents><target name="mageetc"><dir name="modules"><file name="J2t_Mobilestats.xml" hash="00a52e524908924f870a29a0e7dc8773"/></dir></target><target name="magecommunity"><dir name="J2t"><dir name="Mobilestats"><dir name="Helper"><file name="Data.php" hash="02af5abbf0aa772ffed994e5f6a50dd6"/></dir><dir name="Model"><file name="Feed.php" hash="6f534d272658f9869b6bf17b57af82d3"/><file name="Observer.php" hash="fdb1289e305e68eadb5249fc5fd30587"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="StatsController.php" hash="a39c15ae456837f29e24ebd0675e18f4"/></dir><file name="IndexController.php" hash="585cdfac68eab5a5a1d24be08f632b1d"/></dir><dir name="etc"><file name="config.xml" hash="f594f8d20f76f28ecb039d2838c99473"/></dir></dir></dir></target></contents>
|
30 |
+
<compatible/>
|
31 |
+
<dependencies><required><php><min>5.2.0</min><max>5.4.3</max></php></required></dependencies>
|
32 |
+
</package>
|