MocoInsight_Mocoauto - Version 1.2.7

Version Notes

1.2.7

log stats function calculates using direct SQL

1.2.6

StatsAction now returns size of log files

------------------------------------------------------------
1.2.5

Speed up stocklevelAction, now only returns non zero inventory

WishlistAction now includes wishListItemId

-------------------------------------------------------------
1.2.4

Added wishlistsAction
Added unconvertedcartsAction

Fix - log actions now check if table exists

----------------------------------------------------------------
1.2.3

Fix to Observer.php
-------------------------------------------------------------
1.2.2

Added subscribersAction
Added storesAction

--------------------------------------------------------------
1.2.1

ordersAction - now uses billing address as some products (Virtual) won't have a delivery address and checks that object exists

---------------------------------------------------------------
1.2.0

ordersAction - added shpping address
productsAction - added end of record marker

stocklevelsAction - New

Added log_ actions

----------------------------------------------------------------
1.1.7

Added malformed error

Returns API version number with failed calls
----------------------------------------------------------------
1.1.6

Changed API header name to work with sites that use additional authorisation now:

mocoapi: apikey= THE API KEY

----------------------------------------------------------------
1.1.5
Updated stats API now includes:

Version of magento
System date/time
added success true for succesful requests
changed product category to moco_category

Download this release

Release Info

Developer Rob Davies
Extension MocoInsight_Mocoauto
Version 1.2.7
Comparing to
See all releases


Version 1.2.7

app/code/community/MocoInsight/Mocoauto/Block/Adminhtml/Config/Buttons/Generate.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MocoInsight_Mocoauto_Block_Adminhtml_Config_Buttons_Generate extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _prepareLayout()
6
+ {
7
+ parent::_prepareLayout();
8
+ if (!$this->getTemplate()) {
9
+ $this->setTemplate('mocoauto/config/button-generate.phtml');
10
+ }
11
+ return $this;
12
+ }
13
+
14
+ public function render(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
17
+ return parent::render($element);
18
+ }
19
+
20
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
21
+ {
22
+ $originalData = $element->getOriginalData();
23
+ $this->addData(array(
24
+ 'button_label' => Mage::helper('mocoauto')->__($originalData['button_label']),
25
+ 'html_id' => $element->getHtmlId(),
26
+ 'url' => Mage::getSingleton('adminhtml/url')->getUrl('*/setup/start')
27
+ ));
28
+
29
+ return $this->_toHtml();
30
+ }
31
+ }
app/code/community/MocoInsight/Mocoauto/Block/Adminhtml/Menu.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MocoInsight_Mocoauto_Block_Adminhtml_Menu extends Mage_Adminhtml_Block_Template
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('page_tabs');
9
+ $this->setTemplate('mocoauto/left-menu.phtml');
10
+ }
11
+ }
app/code/community/MocoInsight/Mocoauto/Helper/Data.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class MocoInsight_Mocoauto_Helper_Data extends Mage_Core_Helper_Abstract
5
+ {
6
+ public function getApiToken($generate = true)
7
+ {
8
+ // Grab any existing token from the admin scope
9
+ $token = Mage::getStoreConfig('mocoauto/api/token', 0);
10
+
11
+ if( (!$token || strlen(trim($token)) == 0) && $generate) {
12
+ $token = $this->setApiToken();
13
+ }
14
+
15
+ return $token;
16
+ }
17
+
18
+ public function setApiToken($token = null)
19
+ {
20
+ if(!$token) {
21
+ $token = md5(time());
22
+ }
23
+ Mage::getModel('core/config')->saveConfig('mocoauto/api/token', $token, 'default');
24
+
25
+ return $token;
26
+ }
27
+ }
app/code/community/MocoInsight/Mocoauto/Helper/JWT.php ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Retrieved 2013-04-29 - commit 82113fd351cea127ded3d07e40eb46865db9e8f2
4
+ // https://github.com/firebase/php-jwt
5
+
6
+ /**
7
+ * JSON Web Token implementation, based on this spec:
8
+ * http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
9
+ *
10
+ * PHP version 5
11
+ *
12
+ * @category Authentication
13
+ * @package Authentication_JWT
14
+ * @author Neuman Vong <neuman@twilio.com>
15
+ * @author Anant Narayanan <anant@php.net>
16
+ * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
17
+ * @link https://github.com/firebase/php-jwt
18
+ */
19
+ /**
20
+ * JSON Web Token implementation, based on this spec:
21
+ * http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
22
+ *
23
+ * @category Authentication
24
+ * @package Authentication_JWT
25
+ * @author Neuman Vong <neuman@twilio.com>
26
+ * @author Anant Narayanan <anant@php.net>
27
+ * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
28
+ * @link https://github.com/firebase/php-jwt
29
+ */
30
+ class JWT
31
+ {
32
+ /**
33
+ * Decodes a JWT string into a PHP object.
34
+ *
35
+ * @param string $jwt The JWT
36
+ * @param string|null $key The secret key
37
+ * @param bool $verify Don't skip verification process
38
+ *
39
+ * @return object The JWT's payload as a PHP object
40
+ * @throws UnexpectedValueException Provided JWT was invalid
41
+ * @throws DomainException Algorithm was not provided
42
+ *
43
+ * @uses jsonDecode
44
+ * @uses urlsafeB64Decode
45
+ */
46
+ public static function decode($jwt, $key = null, $verify = true)
47
+ {
48
+ $tks = explode('.', $jwt);
49
+ if (count($tks) != 3) {
50
+ throw new UnexpectedValueException('Wrong number of segments');
51
+ }
52
+ list($headb64, $bodyb64, $cryptob64) = $tks;
53
+ if (null === ($header = JWT::jsonDecode(JWT::urlsafeB64Decode($headb64)))) {
54
+ throw new UnexpectedValueException('Invalid segment encoding');
55
+ }
56
+ if (null === $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64))) {
57
+ throw new UnexpectedValueException('Invalid segment encoding');
58
+ }
59
+ $sig = JWT::urlsafeB64Decode($cryptob64);
60
+ if ($verify) {
61
+ if (empty($header->alg)) {
62
+ throw new DomainException('Empty algorithm');
63
+ }
64
+ if ($sig != JWT::sign("$headb64.$bodyb64", $key, $header->alg)) {
65
+ throw new UnexpectedValueException('Signature verification failed');
66
+ }
67
+ }
68
+ return $payload;
69
+ }
70
+
71
+ /**
72
+ * Converts and signs a PHP object or array into a JWT string.
73
+ *
74
+ * @param object|array $payload PHP object or array
75
+ * @param string $key The secret key
76
+ * @param string $algo The signing algorithm. Supported
77
+ * algorithms are 'HS256', 'HS384' and 'HS512'
78
+ *
79
+ * @return string A signed JWT
80
+ * @uses jsonEncode
81
+ * @uses urlsafeB64Encode
82
+ */
83
+ public static function encode($payload, $key, $algo = 'HS256')
84
+ {
85
+ $header = array('typ' => 'JWT', 'alg' => $algo);
86
+
87
+ $segments = array();
88
+ $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
89
+ $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
90
+ $signing_input = implode('.', $segments);
91
+
92
+ $signature = JWT::sign($signing_input, $key, $algo);
93
+ $segments[] = JWT::urlsafeB64Encode($signature);
94
+
95
+ return implode('.', $segments);
96
+ }
97
+
98
+ /**
99
+ * Sign a string with a given key and algorithm.
100
+ *
101
+ * @param string $msg The message to sign
102
+ * @param string $key The secret key
103
+ * @param string $method The signing algorithm. Supported
104
+ * algorithms are 'HS256', 'HS384' and 'HS512'
105
+ *
106
+ * @return string An encrypted message
107
+ * @throws DomainException Unsupported algorithm was specified
108
+ */
109
+ public static function sign($msg, $key, $method = 'HS256')
110
+ {
111
+ $methods = array(
112
+ 'HS256' => 'sha256',
113
+ 'HS384' => 'sha384',
114
+ 'HS512' => 'sha512',
115
+ );
116
+ if (empty($methods[$method])) {
117
+ throw new DomainException('Algorithm not supported');
118
+ }
119
+ return hash_hmac($methods[$method], $msg, $key, true);
120
+ }
121
+
122
+ /**
123
+ * Decode a JSON string into a PHP object.
124
+ *
125
+ * @param string $input JSON string
126
+ *
127
+ * @return object Object representation of JSON string
128
+ * @throws DomainException Provided string was invalid JSON
129
+ */
130
+ public static function jsonDecode($input)
131
+ {
132
+ $obj = json_decode($input);
133
+ if (function_exists('json_last_error') && $errno = json_last_error()) {
134
+ JWT::_handleJsonError($errno);
135
+ } else if ($obj === null && $input !== 'null') {
136
+ throw new DomainException('Null result with non-null input');
137
+ }
138
+ return $obj;
139
+ }
140
+
141
+ /**
142
+ * Encode a PHP object into a JSON string.
143
+ *
144
+ * @param object|array $input A PHP object or array
145
+ *
146
+ * @return string JSON representation of the PHP object or array
147
+ * @throws DomainException Provided object could not be encoded to valid JSON
148
+ */
149
+ public static function jsonEncode($input)
150
+ {
151
+ $json = json_encode($input);
152
+ if (function_exists('json_last_error') && $errno = json_last_error()) {
153
+ JWT::_handleJsonError($errno);
154
+ } else if ($json === 'null' && $input !== null) {
155
+ throw new DomainException('Null result with non-null input');
156
+ }
157
+ return $json;
158
+ }
159
+
160
+ /**
161
+ * Decode a string with URL-safe Base64.
162
+ *
163
+ * @param string $input A Base64 encoded string
164
+ *
165
+ * @return string A decoded string
166
+ */
167
+ public static function urlsafeB64Decode($input)
168
+ {
169
+ $remainder = strlen($input) % 4;
170
+ if ($remainder) {
171
+ $padlen = 4 - $remainder;
172
+ $input .= str_repeat('=', $padlen);
173
+ }
174
+ return base64_decode(strtr($input, '-_', '+/'));
175
+ }
176
+
177
+ /**
178
+ * Encode a string with URL-safe Base64.
179
+ *
180
+ * @param string $input The string you want encoded
181
+ *
182
+ * @return string The base64 encode of what you passed in
183
+ */
184
+ public static function urlsafeB64Encode($input)
185
+ {
186
+ return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
187
+ }
188
+
189
+ /**
190
+ * Helper method to create a JSON error.
191
+ *
192
+ * @param int $errno An error number from json_last_error()
193
+ *
194
+ * @return void
195
+ */
196
+ private static function _handleJsonError($errno)
197
+ {
198
+ $messages = array(
199
+ JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
200
+ JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
201
+ JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
202
+ );
203
+ throw new DomainException(
204
+ isset($messages[$errno])
205
+ ? $messages[$errno]
206
+ : 'Unknown JSON error: ' . $errno
207
+ );
208
+ }
209
+
210
+ }
211
+
app/code/community/MocoInsight/Mocoauto/Model/Observer.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MocoInsight_Mocoauto_Model_Observer
4
+ {
5
+ public function setHook(Varien_Event_Observer $observer)
6
+ {
7
+ if (Mage::app()->getFrontController()->getAction()->getFullActionName() === 'adminhtml_dashboard_index')
8
+ {
9
+ $block = $observer->getBlock();
10
+ if ($block->getNameInLayout() === 'dashboard')
11
+ {
12
+ $block->getChild('totals')->setUseAsDashboardHook(true);
13
+ }
14
+ }
15
+ }
16
+
17
+
18
+
19
+ public function insertBlock(Varien_Event_Observer $observer)
20
+ {
21
+ //Mage::log(sprintf("%s->EventName=%s", __METHOD__, $observer->getName()) );
22
+ }
23
+
24
+ public function saveConfig(Varien_Event_Observer $observer) {
25
+ //Mage::log(sprintf("%s->EventName=%s", __METHOD__, $observer->getName()) );
26
+ }
27
+ }
app/code/community/MocoInsight/Mocoauto/Model/Source/Views.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MocoInsight_Mocoauto_Model_Source_Views
4
+ {
5
+ protected $_options;
6
+
7
+ public function toOptionArray($isMultiselect=false)
8
+ {
9
+ if (!$this->_options) {
10
+ try {
11
+ $views = Mage::getModel('mocoauto/api_views')->active();
12
+ foreach($views as $view) {
13
+ $this->_options[] = array(
14
+ 'value' => $view['id'],
15
+ 'label' => $view['title'],
16
+ );
17
+ }
18
+ } catch(Exception $e) {
19
+ // Just don't display anything
20
+ }
21
+
22
+ }
23
+
24
+ $options = $this->_options;
25
+
26
+ if(!$isMultiselect){
27
+ array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
28
+ }
29
+
30
+ return $options;
31
+ }
32
+ }
app/code/community/MocoInsight/Mocoauto/controllers/.ApiController.php.swp ADDED
Binary file
app/code/community/MocoInsight/Mocoauto/controllers/Adminhtml/MocoautoController.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getModuleDir('', 'MocoInsight_Mocoauto') . DS . 'Helper' . DS . 'JWT.php');
4
+
5
+ class MocoInsight_Mocoauto_Adminhtml_MocoautoController extends Mage_Adminhtml_Controller_Action
6
+ {
7
+ protected $_publicActions = array('redirect', 'authenticate');
8
+
9
+ public function redirectAction()
10
+ {
11
+ $type = $this->getRequest()->getParam('type');
12
+ $id = $this->getRequest()->getParam('id');
13
+
14
+ if($id && $type && in_array($type, array('settings'))) {
15
+ switch($type) {
16
+ case 'settings':
17
+ $this->_redirect('adminhtml/system_config/edit/section/mocoauto');
18
+ break;
19
+
20
+ }
21
+ } else {
22
+ $this->_redirect(Mage::getSingleton('admin/session')->getUser()->getStartupPageUrl());
23
+ }
24
+ }
25
+
26
+ public function generateAction()
27
+ {
28
+ try {
29
+ Mage::helper('mocoauto')->setApiToken();
30
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mocoauto')->__('Successfully generated new API token'));
31
+ } catch(Exception $e) {
32
+ Mage::getSingleton('adminhtml/session')->addError($e->getCode() . ': ' . $e->getMessage());
33
+ }
34
+
35
+ $this->_redirect('adminhtml/system_config/edit/section/mocoauto');
36
+ }
37
+ }
app/code/community/MocoInsight/Mocoauto/controllers/ApiController.php ADDED
@@ -0,0 +1,802 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Version 1.2.7
3
+ //
4
+ // Make sure you update version in /var/www/html/app/code/community/MocoInsight/Mocoauto/etc/config.xml
5
+ //
6
+ // DEBUG example "Mage::log('DBG Count: '.$customercount);"
7
+ //
8
+ // Provides the following actions via a RestAPI
9
+ //
10
+ // statsAction
11
+ // ordersAction
12
+ // customersAction
13
+ // categoriesAction
14
+ // productsAction
15
+ // stocklevelsAction
16
+ // log_urlAction
17
+ // log_url_infoAction
18
+ // log_visitorAction
19
+ // log_visitor_infoAction
20
+ // log_customerAction
21
+ // subscribersAction
22
+ // storesAction
23
+ // unconvertedcartsAction
24
+ // wishlistsAction
25
+ // installinfoAction
26
+ //
27
+ //
28
+
29
+
30
+ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Action
31
+ {
32
+
33
+ public function _authorise()
34
+ {
35
+
36
+ $apiversion = (String)Mage::getConfig()->getNode()->modules->MocoInsight_Mocoauto->version;
37
+
38
+ $tokenString = $this->getRequest()->getHeader('mocoapi');
39
+
40
+ $token = null;
41
+ $matches = array();
42
+ if(preg_match('/apikey="([a-z0-9]+)"/', $tokenString, $matches)) {
43
+ $token = $matches[1];
44
+ }
45
+
46
+ $apiToken = Mage::helper('mocoauto')->getApiToken(false);
47
+
48
+ // Check API enabled
49
+
50
+ if(!Mage::getStoreConfig('mocoauto/api/enabled')) {
51
+ $this->getResponse()
52
+ ->setBody(json_encode(array('success' => false, 'message' => 'API access disabled', 'MocoAPI version' => $apiversion)))
53
+ ->setHttpResponseCode(403)
54
+ ->setHeader('Content-type', 'application/json', true);
55
+ return false;
56
+ }
57
+
58
+ // Check the token passed in the header
59
+ if(!$token || $token != $apiToken) {
60
+ $this->getResponse()
61
+ ->setBody(json_encode(array('success' => false, 'message' => 'Not authorised','MocoAPI version' => $apiversion)))
62
+ ->setHttpResponseCode(401)
63
+ ->setHeader('Content-type', 'application/json', true);
64
+ return false;
65
+ }
66
+
67
+
68
+ // Check the URL doesnt have anything apended to it
69
+ if(substr_count($this->getRequest()->getPathInfo(), '/') !=3) {
70
+ $this->getResponse()
71
+ ->setBody(json_encode(array('success' => false, 'message' => 'Malformed url')))
72
+ ->setHttpResponseCode(401)
73
+ ->setHeader('Content-type', 'application/json', true);
74
+ return false;
75
+ }
76
+
77
+
78
+ return true;
79
+ }
80
+
81
+ public function statsAction() // Return the number of Product, Orders and Customers with optional since filter
82
+ {
83
+ if(!$this->_authorise()) {
84
+ return $this;
85
+ }
86
+
87
+ $currentSystemTime = date('Y-m-d H:i:s', time());
88
+
89
+
90
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
91
+
92
+ $since = $this->getRequest()->getParam('since','All');
93
+
94
+ $_productCol = Mage::getModel('catalog/product')->getCollection();
95
+ if($since != 'All'){
96
+ $_productCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
97
+ }
98
+ $productcount = $_productCol->getSize();
99
+
100
+ $_orderCol = Mage::getModel('sales/order')->getCollection();
101
+ if($since != 'All'){
102
+ $_orderCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
103
+ }
104
+ $ordercount = $_orderCol->getSize();
105
+
106
+ $_customerCol = Mage::getModel('customer/customer')->getCollection();
107
+ if($since != 'All'){
108
+ $_customerCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
109
+ }
110
+ $customercount = $_customerCol->getSize();
111
+
112
+
113
+ $_categoryCol = Mage::getModel('catalog/category')->getCollection();
114
+ if($since != 'All'){
115
+ $_categoryCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
116
+ }
117
+ $categorycount = $_categoryCol->getSize();
118
+
119
+ $_wishlistCol = Mage::getModel('wishlist/wishlist')-> getCollection();
120
+ if($since != 'All'){
121
+ $_wishlistCol->addFieldToFilter('updated_at', array('gteq' =>$since));
122
+ }
123
+ $wishlistcount = $_wishlistCol->getSize();
124
+
125
+ $_cartsCol = Mage::getResourceModel('sales/quote_collection')->addFieldToFilter('is_active', '1');
126
+ if($since != 'All'){
127
+ $_cartsCol->addFieldToFilter('updated_at', array('gteq' =>$since));
128
+ }
129
+ $cartscount = $_cartsCol->getSize();
130
+
131
+ $_subscriberCol = Mage::getModel('newsletter/subscriber')-> getCollection();
132
+
133
+ $subscribercount = $_subscriberCol->getSize();
134
+
135
+ $tablename = 'log_url'; // Set the table name here
136
+
137
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
138
+
139
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
140
+ $logurlcount = " table does not exist";
141
+ }
142
+ else{
143
+ $query = 'select count(*) AS id from ' . $tablename;
144
+ $log_urlcount = $_read->fetchOne($query);
145
+ }
146
+
147
+
148
+ $tablename = 'log_url_info'; // Set the table name here
149
+
150
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
151
+
152
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
153
+ $log_url_infocount = " table does not exist";
154
+ }
155
+ else{
156
+ $query = 'select count(*) AS id from ' . $tablename;
157
+ $log_url_infocount = $_read->fetchOne($query);
158
+ }
159
+
160
+ $tablename = 'log_visitor'; // Set the table name here
161
+
162
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
163
+
164
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
165
+ $log_visitorcount = " table does not exist";
166
+ }
167
+ else{
168
+ $query = 'select count(*) AS id from ' . $tablename;
169
+ $log_visitorcount = $_read->fetchOne($query);
170
+ }
171
+
172
+ $tablename = 'log_visitor_info'; // Set the table name here
173
+
174
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
175
+
176
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
177
+ $log_visitor_infocount = " table does not exist";
178
+ }
179
+ else{
180
+ $query = 'select count(*) AS id from ' . $tablename;
181
+ $log_visitor_infocount = $_read->fetchOne($query);
182
+ }
183
+
184
+ $tablename = 'log_customer'; // Set the table name here
185
+
186
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
187
+
188
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
189
+ $log_countcount = " table does not exist";
190
+ }
191
+ else{
192
+ $query = 'select count(*) AS id from ' . $tablename;
193
+ $log_customercount = $_read->fetchOne($query);
194
+ }
195
+
196
+
197
+
198
+ $magentoVersion = Mage::getVersion();
199
+
200
+ $apiversion = (String)Mage::getConfig()->getNode()->modules->MocoInsight_Mocoauto->version;
201
+
202
+ $stats = array(
203
+ 'success' => 'true',
204
+ 'Since' => $since,
205
+ 'Products' => $productcount,
206
+ 'Orders' => $ordercount,
207
+ 'Customers' => $customercount,
208
+ 'Categories' => $categorycount,
209
+ 'Wish lists' => $wishlistcount,
210
+ 'Unconverted carts' => $cartscount,
211
+ 'Subscribers' => $subscribercount,
212
+ 'log_url' => $log_urlcount,
213
+ 'log_url_info' => $log_url_infocount,
214
+ 'log_visitor' => $log_visitorcount,
215
+ 'log_visitor_info' => $log_visitor_infocount,
216
+ 'log_customer' => $log_customercount,
217
+ 'System Date Time' => $currentSystemTime,
218
+ 'Magento Version' => $magentoVersion,
219
+ 'MocoAPI Version' => $apiversion
220
+
221
+ );
222
+
223
+ $this->getResponse()
224
+ ->setBody(json_encode($stats))
225
+ ->setHttpResponseCode(200)
226
+ ->setHeader('Content-type', 'application/json', true);
227
+ return $this;
228
+ }
229
+
230
+
231
+
232
+ public function ordersAction()
233
+ {
234
+ if(!$this->_authorise()) {
235
+ return $this;
236
+ }
237
+
238
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
239
+
240
+ $offset = $this->getRequest()->getParam('offset', 0);
241
+ $page_size = $this->getRequest()->getParam('page_size', 20);
242
+ $since = $this->getRequest()->getParam('since','All');
243
+
244
+ $_orderCol = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('*');
245
+ $_orderCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
246
+
247
+ if($since != 'All'){
248
+ $_orderCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
249
+ }
250
+
251
+ $orders = array();
252
+
253
+ foreach($_orderCol as $_order) {
254
+ $orders[] = $_order->toArray();
255
+
256
+
257
+ if(is_object($_order->getBillingAddress())){
258
+
259
+ $_billing_address = $_order->getBillingAddress();
260
+ $orders[] = $_billing_address->toArray();
261
+ }
262
+
263
+ $_orderItemsCol = $_order->getItemsCollection();
264
+
265
+ foreach($_orderItemsCol as $_orderitem){
266
+
267
+ $orders[] = $_orderitem->toArray();
268
+ }
269
+ }
270
+
271
+ $this->getResponse()
272
+ ->setBody(json_encode($orders))
273
+ ->setHttpResponseCode(200)
274
+ ->setHeader('Content-type', 'application/json', true);
275
+ return $this;
276
+ }
277
+
278
+
279
+ public function customersAction()
280
+ {
281
+ if(!$this->_authorise()) {
282
+ return $this;
283
+ }
284
+
285
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
286
+
287
+ $offset = $this->getRequest()->getParam('offset', 0);
288
+ $page_size = $this->getRequest()->getParam('page_size', 20);
289
+ $since = $this->getRequest()->getParam('since', 'All');
290
+
291
+ $_customerCol = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
292
+ $_customerCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
293
+
294
+ if($since != 'All'){
295
+ $_customerCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
296
+ }
297
+
298
+ $customers = array();
299
+
300
+ foreach($_customerCol as $_customer) {
301
+ $customers[] = $_customer->toArray();
302
+
303
+ }
304
+
305
+ $this->getResponse()
306
+ ->setBody(json_encode($customers))
307
+ ->setHttpResponseCode(200)
308
+ ->setHeader('Content-type', 'application/json', true);
309
+ return $this;
310
+ }
311
+
312
+ public function categoriesAction()
313
+ {
314
+ if(!$this->_authorise()) {
315
+ return $this;
316
+ }
317
+
318
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
319
+
320
+ $offset = $this->getRequest()->getParam('offset', 0);
321
+ $page_size = $this->getRequest()->getParam('page_size', 20);
322
+ $since = $this->getRequest()->getParam('since', 'All');
323
+
324
+ $_categoryCol = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*');
325
+ $_categoryCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
326
+ $_categoryCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
327
+
328
+ $categories = array();
329
+
330
+ foreach($_categoryCol as $_category) {
331
+ $categories[] = $_category->toArray();
332
+
333
+ }
334
+
335
+ $this->getResponse()
336
+ ->setBody(json_encode($categories))
337
+ ->setHttpResponseCode(200)
338
+ ->setHeader('Content-type', 'application/json', true);
339
+ return $this;
340
+ }
341
+
342
+ public function productsAction()
343
+ {
344
+ if(!$this->_authorise()) {
345
+ return $this;
346
+ }
347
+
348
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
349
+
350
+ $offset = $this->getRequest()->getParam('offset', 0);
351
+ $page_size = $this->getRequest()->getParam('page_size', 20);
352
+ $since = $this->getRequest()->getParam('since', 'All');
353
+
354
+ $_productCol = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
355
+ $_productCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
356
+
357
+ if($since != 'All'){
358
+ $_productCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
359
+ }
360
+
361
+
362
+ $products = array();
363
+ $products[] = array('success' => 'true');
364
+ foreach($_productCol as $_product){
365
+
366
+
367
+
368
+
369
+ // get all the attributes of the product
370
+
371
+ $attributes = $_product->getAttributes();
372
+
373
+ foreach ($attributes as $attribute) {
374
+ $attributeCode = $attribute->getAttributeCode();
375
+ $value = $attribute->getFrontend()->getValue($_product);
376
+
377
+
378
+ switch ($attributeCode){
379
+ case 'description':
380
+ break;
381
+ case 'short_description':
382
+ break;
383
+ default:
384
+ $products[] = array($attributeCode => $value);
385
+ break;
386
+ }
387
+
388
+ }
389
+
390
+
391
+ // get all the categories of the product
392
+
393
+
394
+ $categories = $_product->getCategoryCollection()->addAttributeToSelect('name');
395
+
396
+ foreach ($categories as $category) {
397
+
398
+ $products[] = array('moco_category' => $category->getID());
399
+ }
400
+
401
+ // if type is configurable get simple product children
402
+
403
+
404
+
405
+ if($_product->getTypeID() == 'configurable'){
406
+
407
+ $assocProductIDs = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$_product);
408
+
409
+ foreach($assocProductIDs as $assocProduct){
410
+
411
+ $products[] = array('childProductID' => $assocProduct->getID());
412
+ }
413
+ }
414
+ // write end of record mark
415
+ $products[] = array('moco_end_of_record' => 'True');
416
+
417
+ }
418
+
419
+
420
+ $this->getResponse()
421
+ ->setBody(json_encode(array('products' => $products)))
422
+ ->setHttpResponseCode(200)
423
+ ->setHeader('Content-type', 'application/json', true);
424
+
425
+ return $this;
426
+ }
427
+
428
+ public function stocklevelsAction()
429
+ {
430
+ if(!$this->_authorise()) {
431
+ return $this;
432
+ }
433
+
434
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
435
+
436
+ $offset = $this->getRequest()->getParam('offset', 0);
437
+ $page_size = $this->getRequest()->getParam('page_size', 1000);
438
+
439
+ $_productCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()->addFieldToFilter('qty', array("neq" => 0));
440
+
441
+
442
+ $_productCollection->getSelect()->limit($page_size, ($offset * $page_size))->order('product_id');
443
+
444
+ $stocklevels = array();
445
+ $stocklevels[] = array('success' => 'true');
446
+ foreach($_productCollection as $_product){
447
+
448
+ $stocklevels[] = array(($_product->getOrigData('product_id')) => $_product->getQty());
449
+ }
450
+
451
+
452
+ $this->getResponse()
453
+ ->setBody(json_encode(array('stocklevels' => $stocklevels)))
454
+ ->setHttpResponseCode(200)
455
+ ->setHeader('Content-type', 'application/json', true);
456
+
457
+ return $this;
458
+ }
459
+
460
+
461
+
462
+ public function log_urlAction()
463
+ {
464
+ $tablename = 'log_url'; // Set the table name here
465
+
466
+ if(!$this->_authorise()) {
467
+ return $this;
468
+ }
469
+
470
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
471
+
472
+ $offset = $this->getRequest()->getParam('offset', 0);
473
+ $page_size = $this->getRequest()->getParam('page_size', 20);
474
+ $since = $this->getRequest()->getParam('since', 'All');
475
+
476
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
477
+
478
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
479
+ $readresults=array($tablename ." table does not exist");
480
+ }
481
+ else{
482
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
483
+ $readresults = $_read->fetchAll($query);
484
+ }
485
+
486
+ $this->getResponse()
487
+ ->setBody(json_encode($readresults))
488
+ ->setHttpResponseCode(200)
489
+ ->setHeader('Content-type', 'application/json', true);
490
+ return $this;
491
+ }
492
+
493
+ public function log_url_infoAction()
494
+ {
495
+ $tablename = 'log_url_info'; // Set the table name here
496
+
497
+ if(!$this->_authorise()) {
498
+ return $this;
499
+ }
500
+
501
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
502
+
503
+ $offset = $this->getRequest()->getParam('offset', 0);
504
+ $page_size = $this->getRequest()->getParam('page_size', 20);
505
+ $since = $this->getRequest()->getParam('since', 'All');
506
+
507
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
508
+
509
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
510
+ $readresults=array($tablename ." table does not exist");
511
+ }
512
+ else{
513
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
514
+ $readresults = $_read->fetchAll($query);
515
+ }
516
+
517
+ $this->getResponse()
518
+ ->setBody(json_encode($readresults))
519
+ ->setHttpResponseCode(200)
520
+ ->setHeader('Content-type', 'application/json', true);
521
+ return $this;
522
+
523
+ }
524
+ public function log_visitorAction()
525
+ {
526
+ $tablename = 'log_visitor'; // Set the table name here
527
+
528
+ if(!$this->_authorise()) {
529
+ return $this;
530
+ }
531
+
532
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
533
+
534
+ $offset = $this->getRequest()->getParam('offset', 0);
535
+ $page_size = $this->getRequest()->getParam('page_size', 20);
536
+ $since = $this->getRequest()->getParam('since', 'All');
537
+
538
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
539
+
540
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
541
+ $readresults=array($tablename ." table does not exist");
542
+ }
543
+ else{
544
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
545
+ $readresults = $_read->fetchAll($query);
546
+ }
547
+
548
+ $this->getResponse()
549
+ ->setBody(json_encode($readresults))
550
+ ->setHttpResponseCode(200)
551
+ ->setHeader('Content-type', 'application/json', true);
552
+ return $this;
553
+
554
+ }
555
+
556
+ public function log_visitor_infoAction()
557
+ {
558
+ $tablename = 'log_visitor_info'; // Set the table name here
559
+
560
+ if(!$this->_authorise()) {
561
+ return $this;
562
+ }
563
+
564
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
565
+
566
+ $offset = $this->getRequest()->getParam('offset', 0);
567
+ $page_size = $this->getRequest()->getParam('page_size', 20);
568
+ $since = $this->getRequest()->getParam('since', 'All');
569
+
570
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
571
+
572
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
573
+ $readresults=array($tablename ." table does not exist");
574
+ }
575
+ else{
576
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
577
+ $readresults = $_read->fetchAll($query);
578
+ }
579
+
580
+ $this->getResponse()
581
+ ->setBody(json_encode($readresults))
582
+ ->setHttpResponseCode(200)
583
+ ->setHeader('Content-type', 'application/json', true);
584
+ return $this;
585
+
586
+ }
587
+
588
+
589
+ public function log_customerAction()
590
+ {
591
+ $tablename = 'log_customer'; // Set the table name here
592
+
593
+ if(!$this->_authorise()) {
594
+ return $this;
595
+ }
596
+
597
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
598
+
599
+ $offset = $this->getRequest()->getParam('offset', 0);
600
+ $page_size = $this->getRequest()->getParam('page_size', 20);
601
+ $since = $this->getRequest()->getParam('since', 'All');
602
+
603
+ $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
604
+
605
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
606
+ $readresults=array($tablename ." table does not exist");
607
+ }
608
+ else{
609
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
610
+ $readresults = $_read->fetchAll($query);
611
+ }
612
+
613
+ $this->getResponse()
614
+ ->setBody(json_encode($readresults))
615
+ ->setHttpResponseCode(200)
616
+ ->setHeader('Content-type', 'application/json', true);
617
+ return $this;
618
+
619
+ }
620
+ public function subscribersAction()
621
+ {
622
+ if(!$this->_authorise()) {
623
+ return $this;
624
+ }
625
+
626
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
627
+
628
+ $offset = $this->getRequest()->getParam('offset', 0);
629
+ $page_size = $this->getRequest()->getParam('page_size', 20);
630
+ $since = $this->getRequest()->getParam('since', 'All');
631
+
632
+ $_subscribersCol = Mage::getModel('newsletter/subscriber')->getCollection(); //->addAttributeToSelect('*');
633
+ $_subscribersCol->getSelect()->limit($page_size, ($offset * $page_size)); //->order('updated_at');
634
+
635
+ // if($since != 'All'){
636
+ // $_subscribersCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
637
+ // }
638
+
639
+ $subscribers = array();
640
+
641
+ foreach($_subscribersCol as $_subscriber) {
642
+ $subscribers[] = $_subscriber->toArray();
643
+
644
+ }
645
+
646
+ $this->getResponse()
647
+ ->setBody(json_encode($subscribers))
648
+ ->setHttpResponseCode(200)
649
+ ->setHeader('Content-type', 'application/json', true);
650
+ return $this;
651
+ }
652
+
653
+ public function storesAction()
654
+ {
655
+ if(!$this->_authorise()) {
656
+ return $this;
657
+ }
658
+
659
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
660
+
661
+
662
+
663
+ $stores = array();
664
+
665
+ foreach (Mage::app()->getWebsites() as $_website) {
666
+ foreach ($_website->getGroups() as $group) {
667
+ $stores[] = array($_website->getName() => $_website->getId());
668
+ $_stores = $group->getStores();
669
+ foreach ($_stores as $_store) {
670
+
671
+ $stores[] = $_store->toArray();
672
+
673
+ }
674
+ }
675
+ }
676
+
677
+
678
+
679
+ $this->getResponse()
680
+ ->setBody(json_encode($stores))
681
+ ->setHttpResponseCode(200)
682
+ ->setHeader('Content-type', 'application/json', true);
683
+ return $this;
684
+ }
685
+
686
+ public function unconvertedcartsAction()
687
+ {
688
+ if(!$this->_authorise()) {
689
+ return $this;
690
+ }
691
+
692
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
693
+
694
+ $offset = $this->getRequest()->getParam('offset', 0);
695
+ $page_size = $this->getRequest()->getParam('page_size', 20);
696
+ $since = $this->getRequest()->getParam('since', 'All');
697
+
698
+ $_cartsCol = Mage::getResourceModel('sales/quote_collection')->addFieldToFilter('is_active', '1');
699
+
700
+ $_cartsCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
701
+
702
+ if($since != 'All'){
703
+ $_cartsCol->addFieldToFilter('updated_at', array('gteq' =>$since));
704
+ }
705
+
706
+ $carts = array();
707
+
708
+ foreach($_cartsCol as $_cart) {
709
+
710
+ $carts[] = array('moco_start_of_cart_record' => 'True');
711
+ $carts[] = $_cart->toArray();
712
+
713
+ $_cartItemsCol = $_cart -> getItemsCollection();
714
+
715
+ foreach($_cartItemsCol as $_cartitem){
716
+ //$carts[] = $_cartitem->toArray();
717
+ $carts[] = array('product_id' => $_cartitem->getProductId());
718
+ $carts[] = array('product_qty' => $_cartitem->getQty());
719
+ $carts[] = array('updated_at' => $_cartitem->getUpdatedAt());
720
+
721
+ }
722
+ $carts[] = array('moco_end_of_cart_record' => 'True');
723
+ }
724
+
725
+ $this->getResponse()
726
+ ->setBody(json_encode($carts))
727
+ ->setHttpResponseCode(200)
728
+ ->setHeader('Content-type', 'application/json', true);
729
+ return $this;
730
+ }
731
+
732
+ public function wishlistsAction()
733
+ {
734
+ if(!$this->_authorise()) {
735
+ return $this;
736
+ }
737
+
738
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
739
+
740
+ $offset = $this->getRequest()->getParam('offset', 0);
741
+ $page_size = $this->getRequest()->getParam('page_size', 20);
742
+ $since = $this->getRequest()->getParam('since', 'All');
743
+
744
+ $_wishlistCol = Mage::getModel('wishlist/wishlist')-> getCollection();
745
+
746
+ $_wishlistCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
747
+
748
+ if($since != 'All'){
749
+ $_wishlistCol->addFieldToFilter('updated_at', array('gteq' =>$since));
750
+ }
751
+
752
+ $wishlists = array();
753
+
754
+ foreach($_wishlistCol as $_wishlist) {
755
+
756
+ $wishlists[] = array('moco_start_of_wishlist_record' => 'True');
757
+
758
+ $wishlists[] = $_wishlist->toArray();
759
+ $_wishlistitemsCol = $_wishlist->getItemCollection();
760
+ foreach($_wishlistitemsCol as $_wishlistitem){
761
+ $wishlists[] = array('wishlist_item_id' => $_wishlistitem->getId());
762
+ $wishlists[] = array('product_id' => $_wishlistitem->getProductId());
763
+ $wishlists[] = array('product_qty' => $_wishlistitem->getQty());
764
+ $wishlists[] = array('added_at' => $_wishlistitem->getAddedAt());
765
+ }
766
+
767
+ $wishlists[] = array('moco_end_of_wishlist_record' => 'True');
768
+ }
769
+
770
+ $this->getResponse()
771
+ ->setBody(json_encode($wishlists))
772
+ ->setHttpResponseCode(200)
773
+ ->setHeader('Content-type', 'application/json', true);
774
+ return $this;
775
+ }
776
+
777
+ public function installinfoAction()
778
+ {
779
+ if(!$this->_authorise()) {
780
+ return $this;
781
+ }
782
+
783
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
784
+
785
+
786
+ $installinfo = array();
787
+
788
+
789
+ $installinfo[] = array('moco install info' => 'True');
790
+ $installinfo[] = array('Base URL' => Mage::getBaseUrl());
791
+ $installinfo[] = array('Home URL' => Mage::helper('core/url')->getHomeUrl());
792
+ $installinfo[] = array('Home URL' => Mage::getBaseDir());
793
+
794
+
795
+ $this->getResponse()
796
+ ->setBody(json_encode($installinfo))
797
+ ->setHttpResponseCode(200)
798
+ ->setHeader('Content-type', 'application/json', true);
799
+ return $this;
800
+ }
801
+
802
+ }
app/code/community/MocoInsight/Mocoauto/etc/config.xml ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ -->
4
+ <config>
5
+ <modules>
6
+ <MocoInsight_Mocoauto>
7
+ <version>1.2.7</version>
8
+ </MocoInsight_Mocoauto>
9
+ </modules>
10
+ <global>
11
+ <models>
12
+ <mocoauto>
13
+ <class>MocoInsight_Mocoauto_Model</class>
14
+ </mocoauto>
15
+ </models>
16
+ <helpers>
17
+ <mocoauto>
18
+ <class>MocoInsight_Mocoauto_Helper</class>
19
+ </mocoauto>
20
+ </helpers>
21
+ <blocks>
22
+ <mocoauto>
23
+ <class>MocoInsight_Mocoauto_Block</class>
24
+ </mocoauto>
25
+ </blocks>
26
+ <resources>
27
+ <mocoauto_setup>
28
+ <setup>
29
+ <module>MocoInsight_Mocoauto</module>
30
+ </setup>
31
+ <connection>
32
+ <use>directory_setup</use>
33
+ </connection>
34
+ </mocoauto_setup>
35
+ <mocoauto_write>
36
+ <connection>
37
+ <use>core_write</use>
38
+ </connection>
39
+ </mocoauto_write>
40
+ <mocoauto_read>
41
+ <connection>
42
+ <use>core_read</use>
43
+ </connection>
44
+ </mocoauto_read>
45
+ </resources>
46
+ </global>
47
+ <frontend>
48
+ <routers>
49
+ <mocoauto>
50
+ <use>standard</use>
51
+ <args>
52
+ <module>MocoInsight_Mocoauto</module>
53
+ <frontName>mocoauto</frontName>
54
+ </args>
55
+ </mocoauto>
56
+ </routers>
57
+ <layout>
58
+ <updates>
59
+ <mocoauto>
60
+ <file>mocoauto.xml</file>
61
+ </mocoauto>
62
+ </updates>
63
+ </layout>
64
+ </frontend>
65
+ <admin>
66
+ <routers>
67
+ <adminhtml>
68
+ <args>
69
+ <modules>
70
+ <MocoInsight_Mocoauto before="Mage_Adminhtml">MocoInsight_Mocoauto_Adminhtml</MocoInsight_Mocoauto>
71
+ </modules>
72
+ </args>
73
+ </adminhtml>
74
+ </routers>
75
+ </admin>
76
+ <adminhtml>
77
+ <layout>
78
+ <updates>
79
+ <mocoauto>
80
+ <file>mocoauto.xml</file>
81
+ </mocoauto>
82
+ </updates>
83
+ </layout>
84
+ <translate>
85
+ <modules>
86
+ <translations>
87
+ <files>
88
+ <default>MocoInsight_Mocoauto.csv</default>
89
+ </files>
90
+ </translations>
91
+ </modules>
92
+ </translate>
93
+ <events>
94
+ <core_block_abstract_prepare_layout_after>
95
+ <observers>
96
+ <mocoauto>
97
+ <class>mocoauto/observer</class>
98
+ <method>setHook</method>
99
+ </mocoauto>
100
+ </observers>
101
+ </core_block_abstract_prepare_layout_after>
102
+ <core_block_abstract_to_html_after>
103
+ <observers>
104
+ <mocoauto>
105
+ <class>mocoauto/observer</class>
106
+ <method>insertBlock</method>
107
+ </mocoauto>
108
+ </observers>
109
+ </core_block_abstract_to_html_after>
110
+ <admin_system_config_changed_section_mocoauto>
111
+ <observers>
112
+ <mocoauto>
113
+ <class>mocoauto/observer</class>
114
+ <method>saveConfig</method>
115
+ </mocoauto>
116
+ </observers>
117
+ </admin_system_config_changed_section_mocoauto>
118
+ </events>
119
+ <menu>
120
+ <mocoauto translate="title" module="mocoauto">
121
+ <title>Mocoauto</title>
122
+ <sort_order>99999</sort_order>
123
+ <children>
124
+ <mocoauto_settings module="mocoauto">
125
+ <title>Settings</title>
126
+ <action>adminhtml/system_config/edit/section/mocoauto</action>
127
+ <sort_order>2</sort_order>
128
+ </mocoauto_settings>
129
+ </children>
130
+ </mocoauto>
131
+ </menu>
132
+ <acl>
133
+ <resources>
134
+ <admin>
135
+ <children>
136
+ <mocoauto>
137
+ <children>
138
+ <mocoauto_settings translate="title" module="mocoauto">
139
+ <title>Settings</title>
140
+ </mocoauto_settings>
141
+ </children>
142
+ </mocoauto>
143
+ <system>
144
+ <children>
145
+ <config>
146
+ <children>
147
+ <mocoauto translate="title" module="mocoauto">
148
+ <title>Mocoauto</title>
149
+ </mocoauto>
150
+ </children>
151
+ </config>
152
+ </children>
153
+ </system>
154
+ </children>
155
+ </admin>
156
+ </resources>
157
+ </acl>
158
+ </adminhtml>
159
+ </config>
app/code/community/MocoInsight/Mocoauto/etc/system.xml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ -->
4
+ <config>
5
+ <sections>
6
+ <mocoauto translate="label" module="mocoauto">
7
+ <label>Mocoauto</label>
8
+ <class>mocoauto-section</class>
9
+ <tab>mocoauto_extensions</tab>
10
+ <frontend_type>text</frontend_type>
11
+ <sort_order>999999</sort_order>
12
+ <show_in_default>1</show_in_default>
13
+ <show_in_website>1</show_in_website>
14
+ <show_in_store>1</show_in_store>
15
+ <groups>
16
+ <api translate="label comment">
17
+ <label>API Details</label>
18
+ <comment>Required for moco connector to access your site.</comment>
19
+ <frontend_type>text</frontend_type>
20
+ <sort_order>40</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ <fields>
25
+ <enabled translate="label">
26
+ <label>API Enabled</label>
27
+ <frontend_type>select</frontend_type>
28
+ <source_model>adminhtml/system_config_source_yesno</source_model>
29
+ <sort_order>1</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </enabled>
34
+ <token translate="label">
35
+ <label>API Token</label>
36
+ <frontend_type>label</frontend_type>
37
+ <sort_order>1</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>0</show_in_store>
41
+ </token>
42
+ <generate translate="button_label">
43
+ <label></label>
44
+ <button_label>Generate new token</button_label>
45
+ <frontend_model>mocoauto/adminhtml_config_buttons_generate</frontend_model>
46
+ <sort_order>3</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ </generate>
51
+ </fields>
52
+ </api>
53
+ </groups>
54
+ </mocoauto>
55
+ </sections>
56
+ </config>
app/design/adminhtml/default/default/layout/mocoauto.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ -->
4
+ <layout>
5
+ <adminhtml_system_config_edit>
6
+ <reference name="head">
7
+ <action method="addCss"><stylesheet>mocoauto/mocoauto.css</stylesheet></action>
8
+ </reference>
9
+ </adminhtml_system_config_edit>
10
+ </layout>
app/design/adminhtml/default/default/template/mocoauto/config/button-generate.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ ?>
3
+ <button style="" onclick="setLocation('<?php echo $this->getUrl('adminhtml/mocoauto/generate'); ?>');" class="scalable" type="button" id="<?php echo $this->getHtmlId() ?>">
4
+ <span><?php echo $this->escapeHtml($this->getButtonLabel()) ?></span>
5
+ </button>
app/design/adminhtml/default/default/template/mocoauto/config/link.phtml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+
3
+ ?>
4
+ <a href="<?php echo $this->getLinkUrl(); ?>" target="_blank"><?php echo $this->getLabel(); ?></a>
app/design/frontend/base/default/layout/mocoauto.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+
4
+ -->
5
+ <layout version="0.1.0">
6
+ </layout>
app/etc/modules/MocoInsight_Mocoauto.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <MocoInsight_Mocoauto>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </MocoInsight_Mocoauto>
8
+ </modules>
9
+ </config>
app/locale/en_US/MocoInsight_Mocoauto.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ API Details,API Details
2
+ API Enabled,API Enabled
3
+ API Token,API Token
4
+ Save Config, Save Config
5
+ Settings,Settings
package.xml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>MocoInsight_Mocoauto</name>
4
+ <version>1.2.7</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v1.0.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>API plugin for mocoinsight</summary>
10
+ <description>This plugin provides sucure API access for mocoinsight.com - Advanced Magento Reporting&#xD;
11
+ &#xD;
12
+ &#xD;
13
+ </description>
14
+ <notes>1.2.7&#xD;
15
+ &#xD;
16
+ log stats function calculates using direct SQL&#xD;
17
+ &#xD;
18
+ &#xD;
19
+ 1.2.6&#xD;
20
+ &#xD;
21
+ StatsAction now returns size of log files&#xD;
22
+ &#xD;
23
+ ------------------------------------------------------------&#xD;
24
+ 1.2.5&#xD;
25
+ &#xD;
26
+ Speed up stocklevelAction, now only returns non zero inventory&#xD;
27
+ &#xD;
28
+ WishlistAction now includes wishListItemId&#xD;
29
+ &#xD;
30
+ -------------------------------------------------------------&#xD;
31
+ 1.2.4&#xD;
32
+ &#xD;
33
+ Added wishlistsAction&#xD;
34
+ Added unconvertedcartsAction&#xD;
35
+ &#xD;
36
+ Fix - log actions now check if table exists&#xD;
37
+ &#xD;
38
+ ----------------------------------------------------------------&#xD;
39
+ 1.2.3&#xD;
40
+ &#xD;
41
+ Fix to Observer.php&#xD;
42
+ -------------------------------------------------------------&#xD;
43
+ 1.2.2&#xD;
44
+ &#xD;
45
+ Added subscribersAction&#xD;
46
+ Added storesAction&#xD;
47
+ &#xD;
48
+ --------------------------------------------------------------&#xD;
49
+ 1.2.1&#xD;
50
+ &#xD;
51
+ ordersAction - now uses billing address as some products (Virtual) won't have a delivery address and checks that object exists&#xD;
52
+ &#xD;
53
+ &#xD;
54
+ &#xD;
55
+ &#xD;
56
+ &#xD;
57
+ ---------------------------------------------------------------&#xD;
58
+ 1.2.0&#xD;
59
+ &#xD;
60
+ ordersAction - added shpping address&#xD;
61
+ productsAction - added end of record marker&#xD;
62
+ &#xD;
63
+ stocklevelsAction - New&#xD;
64
+ &#xD;
65
+ Added log_ actions&#xD;
66
+ &#xD;
67
+ ----------------------------------------------------------------&#xD;
68
+ 1.1.7&#xD;
69
+ &#xD;
70
+ Added malformed error&#xD;
71
+ &#xD;
72
+ Returns API version number with failed calls&#xD;
73
+ ----------------------------------------------------------------&#xD;
74
+ 1.1.6&#xD;
75
+ &#xD;
76
+ Changed API header name to work with sites that use additional authorisation now:&#xD;
77
+ &#xD;
78
+ mocoapi: apikey= THE API KEY&#xD;
79
+ &#xD;
80
+ &#xD;
81
+ ----------------------------------------------------------------&#xD;
82
+ 1.1.5&#xD;
83
+ Updated stats API now includes:&#xD;
84
+ &#xD;
85
+ Version of magento&#xD;
86
+ System date/time&#xD;
87
+ added success true for succesful requests&#xD;
88
+ changed product category to moco_category</notes>
89
+ <authors><author><name>Rob Davies</name><user>mocoinsight</user><email>rob.davies@mocoinsight.com</email></author></authors>
90
+ <date>2014-02-12</date>
91
+ <time>03:06:22</time>
92
+ <contents><target name="magecommunity"><dir name="MocoInsight"><dir name="Mocoauto"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Config"><dir name="Buttons"><file name="Generate.php" hash="7690d026d99e31732279e6aa5b6b1def"/></dir></dir><file name="Menu.php" hash="1017af5f89545915f3f28be637e07a0c"/></dir></dir><dir name="Helper"><file name="Data.php" hash="4b53061397fec9446830ef218aba4055"/><file name="JWT.php" hash="6610b92191eccedb8edcf993730c3dc0"/></dir><dir name="Model"><file name="Observer.php" hash="c2cc2f396fedd682268457d17dd045b1"/><dir name="Source"><file name="Views.php" hash="c1ddaf4c7bb51c3907dd72b4e21b1897"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="MocoautoController.php" hash="6665fb22806ef20ee59e88a638ca6359"/></dir><file name="ApiController.php" hash="380664bbd46290c4b697ec14cf56838d"/><file name=".ApiController.php.swp" hash="02ad5d9cc02dbbeca8812f2ca95b30cf"/></dir><dir name="etc"><file name="config.xml" hash="9d14d02edf850e9b3c98885dff4fa509"/><file name="system.xml" hash="5d86b7d939b85826c7ac4d4496f80900"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="mocoauto.xml" hash="7dd142354c78e773490c552bbcc3b408"/></dir><dir name="template"><dir name="mocoauto"><dir><dir name="config"><file name="button-generate.phtml" hash="d2ff89c8f1f78e748ac998bd13e61750"/><file name="link.phtml" hash="75c61cac6bdd33ed914f8618b5698598"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mocoauto.xml" hash="a12a0e1dc675b9ac675181373299e36a"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="MocoInsight_Mocoauto.xml" hash="1ec387f21726f6c7ea3ea216c47340d9"/></dir></target><target name="magelocale"><dir name="en_US"><file name="MocoInsight_Mocoauto.csv" hash="9b508561f871f93fa3158014baebf02b"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="mocoauto"><file name="button.png" hash="58e62edb7f4be46e3b29c0bb774c7ad7"/><file name="icon.png" hash="b5bfce535c987d1e9e604823ac4b3943"/><file name="mocoauto.css" hash="3cd28072e5c2f2b656dd04c06288165b"/></dir></dir></dir></dir></target></contents>
93
+ <compatible/>
94
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
95
+ </package>
skin/adminhtml/default/default/mocoauto/button.png ADDED
Binary file
skin/adminhtml/default/default/mocoauto/icon.png ADDED
Binary file
skin/adminhtml/default/default/mocoauto/mocoauto.css ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ul.tabs a.mocoauto-section,
3
+ ul.tabs a.mocoauto-section:hover {
4
+ border-bottom: 1px solid #BEBEBE;
5
+ padding: 0.5em 0.5em 0 1.5em;
6
+ text-indent: -9999px;
7
+ }
8
+
9
+ ul.tabs a.mocoauto-section.active,
10
+ ul.tabs a.mocoauto-section.active:hover {
11
+ background: none repeat scroll 0 0 white;
12
+ }
13
+
14
+ button.mocoauto span {
15
+ background-image: url("button.png");
16
+ padding-left: 16px;
17
+ }