MocoInsight_Mocoauto - Version 1.3.0

Version Notes

1.3.0

Check direct SQL methods defined
exproducts
exstats
report version of php

----------------------------------------------------------
1.2.9

Default tax rate fro products returned with producAction
---------------------------------------------------------
1.2.8

storesAction now returns store config data
----------------------------------------------------------
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.3.0
Comparing to
See all releases


Code changes from version 1.2.9 to 1.3.0

app/code/community/MocoInsight/Mocoauto/controllers/ApiController.php CHANGED
@@ -1,28 +1,28 @@
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
 
@@ -45,7 +45,7 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
45
 
46
  $apiToken = Mage::helper('mocoauto')->getApiToken(false);
47
 
48
- // Check API enabled
49
 
50
  if(!Mage::getStoreConfig('mocoauto/api/enabled')) {
51
  $this->getResponse()
@@ -78,146 +78,303 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
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()
@@ -228,7 +385,6 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
228
  }
229
 
230
 
231
-
232
  public function ordersAction()
233
  {
234
  if(!$this->_authorise()) {
@@ -241,32 +397,31 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
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))
@@ -288,18 +443,17 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
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()
@@ -321,18 +475,17 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
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
 
327
- if($since != 'All'){
328
- $_categoryCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
329
  }
330
 
331
- $categories = array();
332
-
333
- foreach($_categoryCol as $_category) {
334
- $categories[] = $_category->toArray();
335
 
 
 
336
  }
337
 
338
  $this->getResponse()
@@ -354,100 +507,160 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
354
  $page_size = $this->getRequest()->getParam('page_size', 20);
355
  $since = $this->getRequest()->getParam('since', 'All');
356
 
357
- $_productCol = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
358
- $_productCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
359
 
360
- if($since != 'All'){
361
  $_productCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
362
  }
363
 
364
  // Grab an array of tax rates for lookup later
365
 
366
- //$taxClasses = Mage::helper("core")->jsonDecode( Mage::helper("tax")->getAllRatesByProductClass() );
367
- $store = Mage::app()->getStore('default');
368
- $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
369
 
370
  $products = array();
371
- $products[] = array('success' => 'true');
372
  foreach($_productCol as $_product){
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
 
 
375
 
 
 
 
 
 
 
 
376
 
377
- // get all the attributes of the product
 
378
 
379
- $attributes = $_product->getAttributes();
380
-
381
- foreach ($attributes as $attribute) {
382
- $attributeCode = $attribute->getAttributeCode();
383
- $value = $attribute->getFrontend()->getValue($_product);
384
 
 
 
 
 
 
385
 
386
- switch ($attributeCode){
387
- case 'description':
388
- break;
389
- case 'short_description':
390
- break;
391
- default:
392
- $products[] = array($attributeCode => $value);
393
- break;
394
- }
395
 
396
- }
397
-
398
 
399
- // get the tax rate of the product
400
 
 
 
401
 
402
- $taxclassid = $_product->getData('tax_class_id');
403
- if(isset($taxClasses["value_".$taxclassid])){
404
- $taxpercent = $taxClasses["value_".$taxclassid];
405
- } else {
406
- $taxpercent = 'not defined';
407
- }
408
 
409
- $taxpercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
410
- $products[] = array('moco_TaxRate:' => $taxpercent);
 
 
 
 
 
 
411
 
 
 
 
 
 
412
 
413
- // get all the categories of the product
414
 
 
 
 
415
 
416
- $categories = $_product->getCategoryCollection()->addAttributeToSelect('name');
417
-
418
- foreach ($categories as $category) {
419
 
420
- $products[] = array('moco_category' => $category->getID());
421
- }
 
422
 
423
- // if type is configurable get simple product children
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
 
 
 
 
 
 
425
 
 
426
 
427
- if($_product->getTypeID() == 'configurable'){
428
 
429
- $assocProductIDs = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$_product);
430
 
431
- foreach($assocProductIDs as $assocProduct){
 
432
 
433
- $products[] = array('childProductID' => $assocProduct->getID());
434
- }
435
- }
 
436
  // write end of record mark
437
- $products[] = array('moco_end_of_record' => 'True');
438
 
439
- }
440
 
441
-
442
  $this->getResponse()
443
  ->setBody(json_encode(array('products' => $products)))
444
  ->setHttpResponseCode(200)
445
  ->setHeader('Content-type', 'application/json', true);
446
-
447
  return $this;
448
  }
449
 
450
- public function stocklevelsAction()
451
  {
452
  if(!$this->_authorise()) {
453
  return $this;
@@ -459,15 +672,13 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
459
  $page_size = $this->getRequest()->getParam('page_size', 1000);
460
 
461
  $_productCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()->addFieldToFilter('qty', array("neq" => 0));
462
-
463
-
464
  $_productCollection->getSelect()->limit($page_size, ($offset * $page_size))->order('product_id');
465
 
466
  $stocklevels = array();
467
  $stocklevels[] = array('success' => 'true');
468
- foreach($_productCollection as $_product){
469
 
470
- $stocklevels[] = array(($_product->getOrigData('product_id')) => $_product->getQty());
 
471
  }
472
 
473
 
@@ -475,16 +686,15 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
475
  ->setBody(json_encode(array('stocklevels' => $stocklevels)))
476
  ->setHttpResponseCode(200)
477
  ->setHeader('Content-type', 'application/json', true);
478
-
479
  return $this;
480
  }
481
 
482
 
483
 
484
- public function log_urlAction()
485
- {
486
- $tablename = 'log_url'; // Set the table name here
487
-
488
  if(!$this->_authorise()) {
489
  return $this;
490
  }
@@ -497,13 +707,13 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
497
 
498
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
499
 
500
- if(!$_read ->isTableExists($tablename)){ //Table does not exist
501
- $readresults=array($tablename ." table does not exist");
502
- }
503
- else{
504
- $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
505
- $readresults = $_read->fetchAll($query);
506
- }
507
 
508
  $this->getResponse()
509
  ->setBody(json_encode($readresults))
@@ -512,8 +722,8 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
512
  return $this;
513
  }
514
 
515
- public function log_url_infoAction()
516
- {
517
  $tablename = 'log_url_info'; // Set the table name here
518
 
519
  if(!$this->_authorise()) {
@@ -528,13 +738,13 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
528
 
529
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
530
 
531
- if(!$_read ->isTableExists($tablename)){ //Table does not exist
532
- $readresults=array($tablename ." table does not exist");
533
- }
534
- else{
535
- $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
536
- $readresults = $_read->fetchAll($query);
537
- }
538
 
539
  $this->getResponse()
540
  ->setBody(json_encode($readresults))
@@ -542,9 +752,10 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
542
  ->setHeader('Content-type', 'application/json', true);
543
  return $this;
544
 
545
- }
546
- public function log_visitorAction()
547
- {
 
548
  $tablename = 'log_visitor'; // Set the table name here
549
 
550
  if(!$this->_authorise()) {
@@ -559,24 +770,23 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
559
 
560
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
561
 
562
- if(!$_read ->isTableExists($tablename)){ //Table does not exist
563
- $readresults=array($tablename ." table does not exist");
564
- }
565
- else{
566
- $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
567
- $readresults = $_read->fetchAll($query);
568
- }
569
 
570
  $this->getResponse()
571
  ->setBody(json_encode($readresults))
572
  ->setHttpResponseCode(200)
573
  ->setHeader('Content-type', 'application/json', true);
574
  return $this;
 
575
 
576
- }
577
-
578
- public function log_visitor_infoAction()
579
- {
580
  $tablename = 'log_visitor_info'; // Set the table name here
581
 
582
  if(!$this->_authorise()) {
@@ -591,25 +801,24 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
591
 
592
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
593
 
594
- if(!$_read ->isTableExists($tablename)){ //Table does not exist
595
- $readresults=array($tablename ." table does not exist");
596
- }
597
- else{
598
- $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
599
- $readresults = $_read->fetchAll($query);
600
- }
601
 
602
  $this->getResponse()
603
  ->setBody(json_encode($readresults))
604
  ->setHttpResponseCode(200)
605
  ->setHeader('Content-type', 'application/json', true);
606
  return $this;
607
-
608
  }
609
 
610
 
611
- public function log_customerAction()
612
- {
613
  $tablename = 'log_customer'; // Set the table name here
614
 
615
  if(!$this->_authorise()) {
@@ -624,21 +833,21 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
624
 
625
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
626
 
627
- if(!$_read ->isTableExists($tablename)){ //Table does not exist
628
- $readresults=array($tablename ." table does not exist");
629
- }
630
- else{
631
- $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
632
- $readresults = $_read->fetchAll($query);
633
- }
634
 
635
  $this->getResponse()
636
  ->setBody(json_encode($readresults))
637
  ->setHttpResponseCode(200)
638
  ->setHeader('Content-type', 'application/json', true);
639
  return $this;
 
640
 
641
- }
642
  public function subscribersAction()
643
  {
644
  if(!$this->_authorise()) {
@@ -654,15 +863,10 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
654
  $_subscribersCol = Mage::getModel('newsletter/subscriber')->getCollection(); //->addAttributeToSelect('*');
655
  $_subscribersCol->getSelect()->limit($page_size, ($offset * $page_size)); //->order('updated_at');
656
 
657
- // if($since != 'All'){
658
- // $_subscribersCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
659
- // }
660
-
661
  $subscribers = array();
662
 
663
  foreach($_subscribersCol as $_subscriber) {
664
- $subscribers[] = $_subscriber->toArray();
665
-
666
  }
667
 
668
  $this->getResponse()
@@ -680,23 +884,20 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
680
 
681
  $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
682
 
683
-
684
-
685
  $stores = array();
686
 
687
  foreach (Mage::app()->getWebsites() as $_website) {
688
- foreach ($_website->getGroups() as $group) {
689
- $stores[] = array('website name' => $_website->getName(), 'website Id' => $_website->getId());
690
- $_stores = $group->getStores();
691
- foreach ($_stores as $_store) {
692
-
693
- $storeInfo = $_store->toArray();
694
- $storeInfo['tax/calculation/price_includes_tax'] = Mage::getStoreConfig('tax/calculation/price_includes_tax', $_store->getStoreId());
695
- $storeInfo['tax/defaults/country'] = Mage::getStoreConfig('tax/defaults/country', $_store->getStoreId());
696
- $stores[] = $storeInfo;
697
- }
698
- }
699
- }
700
 
701
  $this->getResponse()
702
  ->setBody(json_encode($stores))
@@ -718,7 +919,6 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
718
  $since = $this->getRequest()->getParam('since', 'All');
719
 
720
  $_cartsCol = Mage::getResourceModel('sales/quote_collection')->addFieldToFilter('is_active', '1');
721
-
722
  $_cartsCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
723
 
724
  if($since != 'All'){
@@ -728,20 +928,17 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
728
  $carts = array();
729
 
730
  foreach($_cartsCol as $_cart) {
731
-
732
- $carts[] = array('moco_start_of_cart_record' => 'True');
733
- $carts[] = $_cart->toArray();
734
-
735
- $_cartItemsCol = $_cart -> getItemsCollection();
736
-
737
- foreach($_cartItemsCol as $_cartitem){
738
- //$carts[] = $_cartitem->toArray();
739
- $carts[] = array('product_id' => $_cartitem->getProductId());
740
- $carts[] = array('product_qty' => $_cartitem->getQty());
741
- $carts[] = array('updated_at' => $_cartitem->getUpdatedAt());
742
-
743
- }
744
- $carts[] = array('moco_end_of_cart_record' => 'True');
745
  }
746
 
747
  $this->getResponse()
@@ -764,7 +961,6 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
764
  $since = $this->getRequest()->getParam('since', 'All');
765
 
766
  $_wishlistCol = Mage::getModel('wishlist/wishlist')-> getCollection();
767
-
768
  $_wishlistCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
769
 
770
  if($since != 'All'){
@@ -774,19 +970,17 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
774
  $wishlists = array();
775
 
776
  foreach($_wishlistCol as $_wishlist) {
 
 
 
 
 
 
 
 
 
777
 
778
- $wishlists[] = array('moco_start_of_wishlist_record' => 'True');
779
-
780
- $wishlists[] = $_wishlist->toArray();
781
- $_wishlistitemsCol = $_wishlist->getItemCollection();
782
- foreach($_wishlistitemsCol as $_wishlistitem){
783
- $wishlists[] = array('wishlist_item_id' => $_wishlistitem->getId());
784
- $wishlists[] = array('product_id' => $_wishlistitem->getProductId());
785
- $wishlists[] = array('product_qty' => $_wishlistitem->getQty());
786
- $wishlists[] = array('added_at' => $_wishlistitem->getAddedAt());
787
- }
788
-
789
- $wishlists[] = array('moco_end_of_wishlist_record' => 'True');
790
  }
791
 
792
  $this->getResponse()
@@ -804,14 +998,12 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
804
 
805
  $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
806
 
807
-
808
  $installinfo = array();
809
 
810
-
811
  $installinfo[] = array('moco install info' => 'True');
812
  $installinfo[] = array('Base URL' => Mage::getBaseUrl());
813
  $installinfo[] = array('Home URL' => Mage::helper('core/url')->getHomeUrl());
814
- $installinfo[] = array('Home URL' => Mage::getBaseDir());
815
 
816
 
817
  $this->getResponse()
@@ -820,5 +1012,4 @@ class MocoInsight_Mocoauto_ApiController extends Mage_Core_Controller_Front_Acti
820
  ->setHeader('Content-type', 'application/json', true);
821
  return $this;
822
  }
823
-
824
  }
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
 
45
 
46
  $apiToken = Mage::helper('mocoauto')->getApiToken(false);
47
 
48
+ // Check API enabled
49
 
50
  if(!Mage::getStoreConfig('mocoauto/api/enabled')) {
51
  $this->getResponse()
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
  $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
89
+ $since = $this->getRequest()->getParam('since','All');
90
 
91
+ $_productCol = Mage::getModel('catalog/product')->getCollection();
92
+ if($since != 'All'){
 
 
93
  $_productCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
94
+ }
95
+ $productcount = $_productCol->getSize();
96
 
97
  $_orderCol = Mage::getModel('sales/order')->getCollection();
98
+ if($since != 'All'){
99
  $_orderCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
100
+ }
101
+ $ordercount = $_orderCol->getSize();
102
 
103
  $_customerCol = Mage::getModel('customer/customer')->getCollection();
104
+ if($since != 'All'){
105
  $_customerCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
106
+ }
107
+ $customercount = $_customerCol->getSize();
108
 
109
 
110
  $_categoryCol = Mage::getModel('catalog/category')->getCollection();
111
+ if($since != 'All'){
112
  $_categoryCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
113
+ }
114
+ $categorycount = $_categoryCol->getSize();
115
 
116
  $_wishlistCol = Mage::getModel('wishlist/wishlist')-> getCollection();
117
+ if($since != 'All'){
118
+ $_wishlistCol->addFieldToFilter('updated_at', array('gteq' =>$since));
119
  }
120
+ $wishlistcount = $_wishlistCol->getSize();
121
 
122
+ $_cartsCol = Mage::getResourceModel('sales/quote_collection')->addFieldToFilter('is_active', '1');
123
  if($since != 'All'){
124
+ $_cartsCol->addFieldToFilter('updated_at', array('gteq' =>$since));
125
+ }
126
+ $cartscount = $_cartsCol->getSize();
127
 
128
+ $_subscriberCol = Mage::getModel('newsletter/subscriber')-> getCollection();
129
 
130
+ $subscribercount = $_subscriberCol->getSize();
131
+ //
132
+ // Check size of log files
133
+ // 1. Check if isTableExists method is defined (It appears Magento v1.5.0.1 defines it differently)
134
+ // 2. Then check if each table exists
135
+ // 3. Then get size of the 5 tables.
136
 
 
137
 
138
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
139
 
140
+ if (method_exists($_read, 'isTableExists')){
141
+
142
+ $tablename = 'log_url'; // Set the table name here
143
+
144
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
145
+ $logurlcount = "table does not exist";
146
+ }
147
+ else{
148
  $query = 'select count(*) AS id from ' . $tablename;
149
  $log_urlcount = $_read->fetchOne($query);
150
+ }
151
 
152
+ $tablename = 'log_url_info'; // Set the table name here
153
 
154
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
155
+ $log_url_infocount = "table does not exist";
156
+ }
157
+ else{
158
+ $query = 'select count(*) AS id from ' . $tablename;
159
+ $log_url_infocount = $_read->fetchOne($query);
160
+ }
161
 
162
+ $tablename = 'log_visitor'; // Set the table name here
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
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
175
+ $log_visitor_infocount = "table does not exist";
176
+ }
177
+ else{
178
+ $query = 'select count(*) AS id from ' . $tablename;
179
+ $log_visitor_infocount = $_read->fetchOne($query);
180
+ }
181
 
182
+ $tablename = 'log_customer'; // Set the table name here
183
+
184
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
185
+ $log_countcount = "table does not exist";
186
+ }
187
+ else{
188
  $query = 'select count(*) AS id from ' . $tablename;
189
+ $log_customercount = $_read->fetchOne($query);
190
+ }
191
+
192
+ }
193
+ else {
194
+ $log_urlcount = "isTableExists is an undefined method";
195
+ $log_url_infocount = "isTableExists is an undefined method";
196
+ $log_visitorcount = "isTableExists is an undefined method";
197
+ $log_visitor_infocount = "isTableExists is an undefined method";
198
+ $log_customercount = "isTableExists is an undefined method";
199
+
200
+ }
201
+
202
+
203
+
204
+ $magentoVersion = Mage::getVersion();
205
+ $apiversion = (String)Mage::getConfig()->getNode()->modules->MocoInsight_Mocoauto->version;
206
+ $phpversion = phpversion();
207
+
208
+ $stats = array(
209
+ 'success' => 'true',
210
+ 'Since' => $since,
211
+ 'Products' => $productcount,
212
+ 'Orders' => $ordercount,
213
+ 'Customers' => $customercount,
214
+ 'Categories' => $categorycount,
215
+ 'Wish lists' => $wishlistcount,
216
+ 'Unconverted carts' => $cartscount,
217
+ 'Subscribers' => $subscribercount,
218
+ 'log_url' => $log_urlcount,
219
+ 'log_url_info' => $log_url_infocount,
220
+ 'log_visitor' => $log_visitorcount,
221
+ 'log_visitor_info' => $log_visitor_infocount,
222
+ 'log_customer' => $log_customercount,
223
+ 'System Date Time' => $currentSystemTime,
224
+ 'Magento Version' => $magentoVersion,
225
+ 'MocoAPI Version' => $apiversion,
226
+ 'PHP Version' => $phpversion
227
+ );
228
+
229
+ $this->getResponse()
230
+ ->setBody(json_encode($stats))
231
+ ->setHttpResponseCode(200)
232
+ ->setHeader('Content-type', 'application/json', true);
233
+ return $this;
234
+ }
235
+
236
+ public function exstatsAction()
237
+ {
238
+ if(!$this->_authorise()) {
239
+ return $this;
240
  }
241
 
242
+ $currentSystemTime = date('Y-m-d H:i:s', time());
243
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
244
+ $since = $this->getRequest()->getParam('since','All');
245
+
246
+ $_productCol = Mage::getModel('catalog/product')->getCollection();
247
+ if($since != 'All'){
248
+ $_productCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
249
+ }
250
+ $productcount = $_productCol->getSize();
251
+
252
+ $_orderCol = Mage::getModel('sales/order')->getCollection();
253
+ if($since != 'All'){
254
+ $_orderCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
255
+ }
256
+ $ordercount = $_orderCol->getSize();
257
+
258
+ $_customerCol = Mage::getModel('customer/customer')->getCollection();
259
+ if($since != 'All'){
260
+ $_customerCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
261
+ }
262
+ $customercount = $_customerCol->getSize();
263
 
 
264
 
265
+ $_categoryCol = Mage::getModel('catalog/category')->getCollection();
266
+ if($since != 'All'){
267
+ $_categoryCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
268
  }
269
+ $categorycount = $_categoryCol->getSize();
270
+
271
+ $_wishlistCol = Mage::getModel('wishlist/wishlist')-> getCollection();
272
+ if($since != 'All'){
273
+ $_wishlistCol->addFieldToFilter('updated_at', array('gteq' =>$since));
274
  }
275
+ $wishlistcount = $_wishlistCol->getSize();
276
+
277
+ $_cartsCol = Mage::getResourceModel('sales/quote_collection')->addFieldToFilter('is_active', '1');
278
+ if($since != 'All'){
279
+ $_cartsCol->addFieldToFilter('updated_at', array('gteq' =>$since));
280
+ }
281
+ $cartscount = $_cartsCol->getSize();
282
+
283
+ $_subscriberCol = Mage::getModel('newsletter/subscriber')-> getCollection();
284
+
285
+ $subscribercount = $_subscriberCol->getSize();
286
+ //
287
+ // Check size of log files
288
+ // 1. Check if isTableExists method is defined (It appears Magento v1.5.0.1 defines it differently)
289
+ // 2. Then check if each table exists
290
+ // 3. Then get size of the 5 tables.
291
 
 
292
 
293
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
294
 
295
+ if (method_exists($_read, 'isTableExists')){
296
+
297
+ $tablename = 'log_url'; // Set the table name here
298
+
299
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
300
+ $logurlcount = "table does not exist";
301
+ }
302
+ else{
303
  $query = 'select count(*) AS id from ' . $tablename;
304
+ $log_urlcount = $_read->fetchOne($query);
305
+ }
306
 
307
+ $tablename = 'log_url_info'; // Set the table name here
308
 
309
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
310
+ $log_url_infocount = "table does not exist";
311
+ }
312
+ else{
313
+ $query = 'select count(*) AS id from ' . $tablename;
314
+ $log_url_infocount = $_read->fetchOne($query);
315
+ }
316
 
317
+ $tablename = 'log_visitor'; // Set the table name here
318
 
319
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
320
+ $log_visitorcount = "table does not exist";
321
+ }
322
+ else{
323
+ $query = 'select count(*) AS id from ' . $tablename;
324
+ $log_visitorcount = $_read->fetchOne($query);
325
+ }
326
 
327
+ $tablename = 'log_visitor_info'; // Set the table name here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
330
+ $log_visitor_infocount = "table does not exist";
331
+ }
332
+ else{
333
+ $query = 'select count(*) AS id from ' . $tablename;
334
+ $log_visitor_infocount = $_read->fetchOne($query);
335
+ }
336
+
337
+ $tablename = 'log_customer'; // Set the table name here
338
+
339
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
340
+ $log_countcount = "table does not exist";
341
+ }
342
+ else{
343
+ $query = 'select count(*) AS id from ' . $tablename;
344
+ $log_customercount = $_read->fetchOne($query);
345
+ }
346
+
347
+ }
348
+ else {
349
+ $log_urlcount = "isTableExists is an undefined method";
350
+ $log_url_infocount = "isTableExists is an undefined method";
351
+ $log_visitorcount = "isTableExists is an undefined method";
352
+ $log_visitor_infocount = "isTableExists is an undefined method";
353
+ $log_customercount = "isTableExists is an undefined method";
354
+
355
+ }
356
+
357
+ $magentoVersion = Mage::getVersion();
358
+ $apiversion = (String)Mage::getConfig()->getNode()->modules->MocoInsight_Mocoauto->version;
359
+
360
+ $stats = array(
361
+ 'success' => 'true',
362
+ 'Since' => $since,
363
+ 'Products' => $productcount,
364
+ 'Orders' => $ordercount,
365
+ 'Customers' => $customercount,
366
+ 'Categories' => $categorycount,
367
+ 'Wish lists' => $wishlistcount,
368
+ 'Unconverted carts' => $cartscount,
369
+ 'Subscribers' => $subscribercount,
370
+ 'log_url' => $log_urlcount,
371
+ 'log_url_info' => $log_url_infocount,
372
+ 'log_visitor' => $log_visitorcount,
373
+ 'log_visitor_info' => $log_visitor_infocount,
374
+ 'log_customer' => $log_customercount,
375
+ 'System Date Time' => $currentSystemTime,
376
+ 'Magento Version' => $magentoVersion,
377
+ 'MocoAPI Version' => $apiversion
378
  );
379
 
380
  $this->getResponse()
385
  }
386
 
387
 
 
388
  public function ordersAction()
389
  {
390
  if(!$this->_authorise()) {
397
  $page_size = $this->getRequest()->getParam('page_size', 20);
398
  $since = $this->getRequest()->getParam('since','All');
399
 
400
+ $_orderCol = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('*');
401
  $_orderCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
402
 
403
+ if($since != 'All'){
404
+ $_orderCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
405
  }
406
 
407
+ $orders = array();
408
 
409
+ foreach($_orderCol as $_order) {
410
+ $orders[] = $_order->toArray();
411
 
412
 
413
+ if(is_object($_order->getBillingAddress())){
414
 
415
+ $_billing_address = $_order->getBillingAddress();
416
+ $orders[] = $_billing_address->toArray();
417
+ }
418
 
419
+ $_orderItemsCol = $_order->getItemsCollection();
420
 
421
+ foreach($_orderItemsCol as $_orderitem){
422
+ $orders[] = $_orderitem->toArray();
423
+ }
424
+ }
 
425
 
426
  $this->getResponse()
427
  ->setBody(json_encode($orders))
443
  $page_size = $this->getRequest()->getParam('page_size', 20);
444
  $since = $this->getRequest()->getParam('since', 'All');
445
 
446
+ $_customerCol = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
447
  $_customerCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
448
 
449
+ if($since != 'All'){
450
+ $_customerCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
451
  }
452
 
453
+ $customers = array();
 
 
 
454
 
455
+ foreach($_customerCol as $_customer) {
456
+ $customers[] = $_customer->toArray();
457
  }
458
 
459
  $this->getResponse()
475
  $page_size = $this->getRequest()->getParam('page_size', 20);
476
  $since = $this->getRequest()->getParam('since', 'All');
477
 
478
+ $_categoryCol = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*');
479
  $_categoryCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
480
 
481
+ if($since != 'All'){
482
+ $_categoryCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
483
  }
484
 
485
+ $categories = array();
 
 
 
486
 
487
+ foreach($_categoryCol as $_category) {
488
+ $categories[] = $_category->toArray();
489
  }
490
 
491
  $this->getResponse()
507
  $page_size = $this->getRequest()->getParam('page_size', 20);
508
  $since = $this->getRequest()->getParam('since', 'All');
509
 
510
+ $_productCol = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
511
+ $_productCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
512
 
513
+ if($since != 'All'){
514
  $_productCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
515
  }
516
 
517
  // Grab an array of tax rates for lookup later
518
 
519
+
520
+ $store = Mage::app()->getStore('default');
521
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
522
 
523
  $products = array();
524
+ $products[] = array('success' => 'true');
525
  foreach($_productCol as $_product){
526
 
527
+ // get all the attributes of the product
528
+ $attributes = $_product->getAttributes();
529
+
530
+ foreach ($attributes as $attribute) {
531
+ $attributeCode = $attribute->getAttributeCode();
532
+ $value = $attribute->getFrontend()->getValue($_product);
533
+
534
+ switch ($attributeCode){
535
+ case 'description':
536
+ break;
537
+ case 'short_description':
538
+ break;
539
+ default:
540
+ $products[] = array($attributeCode => $value);
541
+ break;
542
+ }
543
+ }
544
+
545
 
546
+ // get the tax rate of the product
547
 
548
+ $taxclassid = $_product->getData('tax_class_id');
549
+ if(isset($taxClasses["value_".$taxclassid])){
550
+ $taxpercent = $taxClasses["value_".$taxclassid];
551
+ }
552
+ else {
553
+ $taxpercent = 'not defined';
554
+ }
555
 
556
+ $taxpercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
557
+ $products[] = array('moco_TaxRate:' => $taxpercent);
558
 
559
+ // get all the categories of the product
 
 
 
 
560
 
561
+ $categories = $_product->getCategoryCollection()->addAttributeToSelect('name');
562
+
563
+ foreach ($categories as $category) {
564
+ $products[] = array('moco_category' => $category->getID());
565
+ }
566
 
567
+ // if type is configurable get simple product children
 
 
 
 
 
 
 
 
568
 
 
 
569
 
 
570
 
571
+ if($_product->getTypeID() == 'configurable'){
572
+ $assocProductIDs = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$_product);
573
 
574
+ foreach($assocProductIDs as $assocProduct){
575
+ $products[] = array('childProductID' => $assocProduct->getID());
576
+ }
577
+ }
578
+ // write end of record mark
579
+ $products[] = array('moco_end_of_record' => 'True');
580
 
581
+ }
582
+
583
+ $this->getResponse()
584
+ ->setBody(json_encode(array('products' => $products)))
585
+ ->setHttpResponseCode(200)
586
+ ->setHeader('Content-type', 'application/json', true);
587
+ return $this;
588
+ }
589
 
590
+ public function exproductsAction() // previous version of API
591
+ {
592
+ if(!$this->_authorise()) {
593
+ return $this;
594
+ }
595
 
596
+ $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
597
 
598
+ $offset = $this->getRequest()->getParam('offset', 0);
599
+ $page_size = $this->getRequest()->getParam('page_size', 20);
600
+ $since = $this->getRequest()->getParam('since', 'All');
601
 
602
+ $_productCol = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
603
+ $_productCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
 
604
 
605
+ if($since != 'All'){
606
+ $_productCol->addAttributeToFilter('updated_at', array('gteq' =>$since));
607
+ }
608
 
609
+ $products = array();
610
+ $products[] = array('success' => 'true');
611
+ foreach($_productCol as $_product){
612
+
613
+ // get all the attributes of the product
614
+ $attributes = $_product->getAttributes();
615
+
616
+ foreach ($attributes as $attribute) {
617
+ $attributeCode = $attribute->getAttributeCode();
618
+ $value = $attribute->getFrontend()->getValue($_product);
619
+
620
+ switch ($attributeCode){
621
+ case 'description':
622
+ break;
623
+ case 'short_description':
624
+ break;
625
+ default:
626
+ $products[] = array($attributeCode => $value);
627
+ break;
628
+ }
629
+ }
630
+
631
+
632
+ // get all the categories of the product
633
 
634
+ $categories = $_product->getCategoryCollection()->addAttributeToSelect('name');
635
+
636
+ foreach ($categories as $category) {
637
+ $products[] = array('moco_category' => $category->getID());
638
+ }
639
 
640
+ // if type is configurable get simple product children
641
 
 
642
 
 
643
 
644
+ if($_product->getTypeID() == 'configurable'){
645
+ $assocProductIDs = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$_product);
646
 
647
+ foreach($assocProductIDs as $assocProduct){
648
+ $products[] = array('childProductID' => $assocProduct->getID());
649
+ }
650
+ }
651
  // write end of record mark
652
+ $products[] = array('moco_end_of_record' => 'True');
653
 
654
+ }
655
 
 
656
  $this->getResponse()
657
  ->setBody(json_encode(array('products' => $products)))
658
  ->setHttpResponseCode(200)
659
  ->setHeader('Content-type', 'application/json', true);
 
660
  return $this;
661
  }
662
 
663
+ public function stocklevelsAction()
664
  {
665
  if(!$this->_authorise()) {
666
  return $this;
672
  $page_size = $this->getRequest()->getParam('page_size', 1000);
673
 
674
  $_productCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()->addFieldToFilter('qty', array("neq" => 0));
 
 
675
  $_productCollection->getSelect()->limit($page_size, ($offset * $page_size))->order('product_id');
676
 
677
  $stocklevels = array();
678
  $stocklevels[] = array('success' => 'true');
 
679
 
680
+ foreach($_productCollection as $_product){
681
+ $stocklevels[] = array(($_product->getOrigData('product_id')) => $_product->getQty());
682
  }
683
 
684
 
686
  ->setBody(json_encode(array('stocklevels' => $stocklevels)))
687
  ->setHttpResponseCode(200)
688
  ->setHeader('Content-type', 'application/json', true);
 
689
  return $this;
690
  }
691
 
692
 
693
 
694
+ public function log_urlAction()
695
+ {
696
+ $tablename = 'log_url'; // Set the table name here
697
+
698
  if(!$this->_authorise()) {
699
  return $this;
700
  }
707
 
708
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
709
 
710
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
711
+ $readresults=array($tablename ." table does not exist");
712
+ }
713
+ else{
714
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
715
+ $readresults = $_read->fetchAll($query);
716
+ }
717
 
718
  $this->getResponse()
719
  ->setBody(json_encode($readresults))
722
  return $this;
723
  }
724
 
725
+ public function log_url_infoAction()
726
+ {
727
  $tablename = 'log_url_info'; // Set the table name here
728
 
729
  if(!$this->_authorise()) {
738
 
739
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
740
 
741
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
742
+ $readresults=array($tablename ." table does not exist");
743
+ }
744
+ else{
745
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
746
+ $readresults = $_read->fetchAll($query);
747
+ }
748
 
749
  $this->getResponse()
750
  ->setBody(json_encode($readresults))
752
  ->setHeader('Content-type', 'application/json', true);
753
  return $this;
754
 
755
+ }
756
+
757
+ public function log_visitorAction()
758
+ {
759
  $tablename = 'log_visitor'; // Set the table name here
760
 
761
  if(!$this->_authorise()) {
770
 
771
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
772
 
773
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
774
+ $readresults=array($tablename ." table does not exist");
775
+ }
776
+ else{
777
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
778
+ $readresults = $_read->fetchAll($query);
779
+ }
780
 
781
  $this->getResponse()
782
  ->setBody(json_encode($readresults))
783
  ->setHttpResponseCode(200)
784
  ->setHeader('Content-type', 'application/json', true);
785
  return $this;
786
+ }
787
 
788
+ public function log_visitor_infoAction()
789
+ {
 
 
790
  $tablename = 'log_visitor_info'; // Set the table name here
791
 
792
  if(!$this->_authorise()) {
801
 
802
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
803
 
804
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
805
+ $readresults=array($tablename ." table does not exist");
806
+ }
807
+ else{
808
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
809
+ $readresults = $_read->fetchAll($query);
810
+ }
811
 
812
  $this->getResponse()
813
  ->setBody(json_encode($readresults))
814
  ->setHttpResponseCode(200)
815
  ->setHeader('Content-type', 'application/json', true);
816
  return $this;
 
817
  }
818
 
819
 
820
+ public function log_customerAction()
821
+ {
822
  $tablename = 'log_customer'; // Set the table name here
823
 
824
  if(!$this->_authorise()) {
833
 
834
  $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
835
 
836
+ if(!$_read ->isTableExists($tablename)){ //Table does not exist
837
+ $readresults=array($tablename ." table does not exist");
838
+ }
839
+ else{
840
+ $query = 'select * from ' . $tablename . ' limit ' . $offset . ',' . $page_size;
841
+ $readresults = $_read->fetchAll($query);
842
+ }
843
 
844
  $this->getResponse()
845
  ->setBody(json_encode($readresults))
846
  ->setHttpResponseCode(200)
847
  ->setHeader('Content-type', 'application/json', true);
848
  return $this;
849
+ }
850
 
 
851
  public function subscribersAction()
852
  {
853
  if(!$this->_authorise()) {
863
  $_subscribersCol = Mage::getModel('newsletter/subscriber')->getCollection(); //->addAttributeToSelect('*');
864
  $_subscribersCol->getSelect()->limit($page_size, ($offset * $page_size)); //->order('updated_at');
865
 
 
 
 
 
866
  $subscribers = array();
867
 
868
  foreach($_subscribersCol as $_subscriber) {
869
+ $subscribers[] = $_subscriber->toArray();
 
870
  }
871
 
872
  $this->getResponse()
884
 
885
  $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
886
 
 
 
887
  $stores = array();
888
 
889
  foreach (Mage::app()->getWebsites() as $_website) {
890
+ foreach ($_website->getGroups() as $group) {
891
+ $stores[] = array('website name' => $_website->getName(), 'website Id' => $_website->getId());
892
+ $_stores = $group->getStores();
893
+ foreach ($_stores as $_store) {
894
+ $storeInfo = $_store->toArray();
895
+ $storeInfo['tax/calculation/price_includes_tax'] = Mage::getStoreConfig('tax/calculation/price_includes_tax', $_store->getStoreId());
896
+ $storeInfo['tax/defaults/country'] = Mage::getStoreConfig('tax/defaults/country', $_store->getStoreId());
897
+ $stores[] = $storeInfo;
898
+ }
899
+ }
900
+ }
 
901
 
902
  $this->getResponse()
903
  ->setBody(json_encode($stores))
919
  $since = $this->getRequest()->getParam('since', 'All');
920
 
921
  $_cartsCol = Mage::getResourceModel('sales/quote_collection')->addFieldToFilter('is_active', '1');
 
922
  $_cartsCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
923
 
924
  if($since != 'All'){
928
  $carts = array();
929
 
930
  foreach($_cartsCol as $_cart) {
931
+ $carts[] = array('moco_start_of_cart_record' => 'True');
932
+ $carts[] = $_cart->toArray();
933
+ $_cartItemsCol = $_cart -> getItemsCollection();
934
+
935
+ foreach($_cartItemsCol as $_cartitem){
936
+ //$carts[] = $_cartitem->toArray();
937
+ $carts[] = array('product_id' => $_cartitem->getProductId());
938
+ $carts[] = array('product_qty' => $_cartitem->getQty());
939
+ $carts[] = array('updated_at' => $_cartitem->getUpdatedAt());
940
+ }
941
+ $carts[] = array('moco_end_of_cart_record' => 'True');
 
 
 
942
  }
943
 
944
  $this->getResponse()
961
  $since = $this->getRequest()->getParam('since', 'All');
962
 
963
  $_wishlistCol = Mage::getModel('wishlist/wishlist')-> getCollection();
 
964
  $_wishlistCol->getSelect()->limit($page_size, ($offset * $page_size))->order('updated_at');
965
 
966
  if($since != 'All'){
970
  $wishlists = array();
971
 
972
  foreach($_wishlistCol as $_wishlist) {
973
+ $wishlists[] = array('moco_start_of_wishlist_record' => 'True');
974
+ $wishlists[] = $_wishlist->toArray();
975
+ $_wishlistitemsCol = $_wishlist->getItemCollection();
976
+ foreach($_wishlistitemsCol as $_wishlistitem){
977
+ $wishlists[] = array('wishlist_item_id' => $_wishlistitem->getId());
978
+ $wishlists[] = array('product_id' => $_wishlistitem->getProductId());
979
+ $wishlists[] = array('product_qty' => $_wishlistitem->getQty());
980
+ $wishlists[] = array('added_at' => $_wishlistitem->getAddedAt());
981
+ }
982
 
983
+ $wishlists[] = array('moco_end_of_wishlist_record' => 'True');
 
 
 
 
 
 
 
 
 
 
 
984
  }
985
 
986
  $this->getResponse()
998
 
999
  $sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
1000
 
 
1001
  $installinfo = array();
1002
 
 
1003
  $installinfo[] = array('moco install info' => 'True');
1004
  $installinfo[] = array('Base URL' => Mage::getBaseUrl());
1005
  $installinfo[] = array('Home URL' => Mage::helper('core/url')->getHomeUrl());
1006
+ $installinfo[] = array('Home URL' => Mage::getBaseDir());
1007
 
1008
 
1009
  $this->getResponse()
1012
  ->setHeader('Content-type', 'application/json', true);
1013
  return $this;
1014
  }
 
1015
  }
app/code/community/MocoInsight/Mocoauto/etc/config.xml CHANGED
@@ -4,7 +4,7 @@
4
  <config>
5
  <modules>
6
  <MocoInsight_Mocoauto>
7
- <version>1.2.9</version>
8
  </MocoInsight_Mocoauto>
9
  </modules>
10
  <global>
4
  <config>
5
  <modules>
6
  <MocoInsight_Mocoauto>
7
+ <version>1.3.0</version>
8
  </MocoInsight_Mocoauto>
9
  </modules>
10
  <global>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>MocoInsight_Mocoauto</name>
4
- <version>1.2.9</version>
5
  <stability>stable</stability>
6
  <license>OSL v1.0.0</license>
7
  <channel>community</channel>
@@ -11,7 +11,15 @@
11
  &#xD;
12
  &#xD;
13
  </description>
14
- <notes>1.2.9&#xD;
 
 
 
 
 
 
 
 
15
  &#xD;
16
  Default tax rate fro products returned with producAction&#xD;
17
  ---------------------------------------------------------&#xD;
@@ -95,9 +103,9 @@ System date/time&#xD;
95
  added success true for succesful requests&#xD;
96
  changed product category to moco_category</notes>
97
  <authors><author><name>Rob Davies</name><user>mocoinsight</user><email>rob.davies@mocoinsight.com</email></author></authors>
98
- <date>2014-03-25</date>
99
- <time>02:56:07</time>
100
- <contents><target name="magecommunity"><dir name="MocoInsight"><dir name="Mocoauto"><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="5711d1342cb1b7484b86ef93559262f6"/></dir><dir name="etc"><file name="config.xml" hash="84bd43a55b57471a2604989fc2b3cd10"/><file name="system.xml" hash="5d86b7d939b85826c7ac4d4496f80900"/></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 name="config"><file name="button-generate.phtml" hash="d2ff89c8f1f78e748ac998bd13e61750"/><file name="link.phtml" hash="75c61cac6bdd33ed914f8618b5698598"/></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>
101
  <compatible/>
102
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
103
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>MocoInsight_Mocoauto</name>
4
+ <version>1.3.0</version>
5
  <stability>stable</stability>
6
  <license>OSL v1.0.0</license>
7
  <channel>community</channel>
11
  &#xD;
12
  &#xD;
13
  </description>
14
+ <notes>1.3.0&#xD;
15
+ &#xD;
16
+ Check direct SQL methods defined&#xD;
17
+ exproducts&#xD;
18
+ exstats&#xD;
19
+ report version of php&#xD;
20
+ &#xD;
21
+ ----------------------------------------------------------&#xD;
22
+ 1.2.9&#xD;
23
  &#xD;
24
  Default tax rate fro products returned with producAction&#xD;
25
  ---------------------------------------------------------&#xD;
103
  added success true for succesful requests&#xD;
104
  changed product category to moco_category</notes>
105
  <authors><author><name>Rob Davies</name><user>mocoinsight</user><email>rob.davies@mocoinsight.com</email></author></authors>
106
+ <date>2014-04-11</date>
107
+ <time>05:31:54</time>
108
+ <contents><target name="magecommunity"><dir name="MocoInsight"><dir name="Mocoauto"><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="98fdd4670b3a49eec963a473bae5bd9d"/></dir><dir name="etc"><file name="config.xml" hash="6719aa22ec5a7e624e4cecc7957306fa"/><file name="system.xml" hash="5d86b7d939b85826c7ac4d4496f80900"/></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 name="config"><file name="button-generate.phtml" hash="d2ff89c8f1f78e748ac998bd13e61750"/><file name="link.phtml" hash="75c61cac6bdd33ed914f8618b5698598"/></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>
109
  <compatible/>
110
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
111
  </package>