Expertrec_Recommendation - Version 1.2.16

Version Notes

Expertrec Recommendation plugin for magento sites.

Download this release

Release Info

Developer melchi
Extension Expertrec_Recommendation
Version 1.2.16
Comparing to
See all releases


Code changes from version 1.2.15 to 1.2.16

app/code/community/Expertrec/Recommendation/controllers/ApiController.php CHANGED
@@ -26,8 +26,8 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
26
  const CONFIG_SECRET = 'expertrec/general/secret';
27
  const PUSHED_FEED_PAGES = 'expertrec/general/expertrec_feed_pushed_pages';
28
 
29
- const BUILD_NO = "1494484439";
30
- const EXPERTREC_VERSION = "1.2.15";
31
  private $_password;
32
  private $_storeId = array();
33
 
@@ -755,13 +755,22 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
755
  return $result;
756
  }
757
 
 
 
 
 
 
 
 
 
 
 
758
  /********
759
  Debug -- add logs
760
  ********/
761
  public function printLog($string,$var,$debug){
762
  if ($debug == 1) {
763
- $logger = Mage::getSingleton('expertrec_recommendation/log');
764
- $logger->log($string.$var);
765
  }
766
  }
767
 
@@ -770,10 +779,9 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
770
  */
771
  public function getMidSecret(){
772
 
773
- $logger = Mage::getSingleton('expertrec_recommendation/log');
774
  $feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
775
 
776
- $logger->log(" Get mid and secret started ");
777
 
778
  $mid = Mage::getStoreConfig(self::MERCHANT_ID);
779
  $secret = Mage::getStoreConfig(self::CONFIG_SECRET);
@@ -818,18 +826,18 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
818
  $data = json_decode($response->getBody(),true);
819
  $mid = $data['merchantid'];
820
  $secret = $data['secret'];
821
- //$logger->log("data ".print_r($data,1));
 
 
822
 
823
  // update mid and secret
824
  Mage::helper("expertrec_recommendation")
825
- ->saveConfig('secret',$data['secret'])
826
- ->saveConfig('mid',$data['merchantid'])
827
- ->clearCache();
828
-
829
- $logger->log(" Generated new mid and secret ");
830
  }
831
  catch (Zend_Http_Client_Exception $e) {
832
- $logger->log(sprintf($apiUrl ." Failed to create mid&secret because HTTP error: %s ", $e->getMessage()),Zend_Log::ERR);
833
  }
834
  }
835
  else{
@@ -841,7 +849,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
841
  $storedMid = $mid;
842
  $feedConfig->setMerchantId($storedMid);
843
 
844
- $logger->log(" Fetched mid ans secret ");
845
 
846
  return $data;
847
 
@@ -852,9 +860,6 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
852
  */
853
  public function getDebugInfo($mid){
854
 
855
- $logger = Mage::getSingleton('expertrec_recommendation/log');
856
- $logger->log(" GetDebugInfo started ");
857
-
858
  $apiUrl = 'https://magento.expertrec.com/4561bd2ff542abec2f0247b1c1b759f2/';
859
  $finalUrl = $apiUrl.$mid;
860
 
@@ -871,17 +876,17 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
871
 
872
  $data = json_decode($response->getBody(),true);
873
  $debug = $data['debug'];
874
- //$logger->log("data ".print_r($data,1));
875
 
876
  // update debug status
877
  Mage::helper("expertrec_recommendation")
878
  ->saveConfig('debug',$debug)
879
  ->clearCache();
880
 
881
- $logger->log(" Debug status added to db as ".$debug);
882
  }
883
  catch (Zend_Http_Client_Exception $e) {
884
- $logger->log(sprintf($apiUrl ." Failed to set debug status because HTTP error: %s ", $e->getMessage()),Zend_Log::ERR);
885
  }
886
 
887
  $this->printLog('**********************************************************','',$debug);
@@ -895,12 +900,11 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
895
  */
896
  public function getProductCount($finalUrl,$secret,$debug){
897
 
898
- // $logger = Mage::getSingleton('expertrec_recommendation/log');
899
- $this->printLog('getProductCount : Started productcounting ','',$debug);
900
 
901
  $filter = Mage::getSingleton('expertrec_recommendation/feed_feedfilter');
902
 
903
- $this->printLog('getProductCount : Colleting allstores ','',$debug);
904
 
905
  try{
906
 
@@ -911,7 +915,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
911
  $websiteId = $store->getWebsiteId();
912
  $website = Mage::app()->getWebsite($websiteId);
913
 
914
- $this->printLog('getProductCount : Collecting info of store # ',$storeId,$debug);
915
 
916
  $this->_storeId[] = $storeId;
917
 
@@ -919,43 +923,43 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
919
  $collection = $filter->addBasicFilter($website,$store);
920
  $count = $collection->getSize();
921
 
922
- $this->printLog('getProductCount : Collecting product count of store as ',$count,$debug);
923
 
924
  $array[] = array('wid' => $websiteId, 'sid' => $storeId, 'total_products' => $count);
925
 
926
  }
927
  $collection->clear();
928
 
929
- // $logger->log("p-count ".print_r($array,1));
930
 
931
  $array_count = array('site_host' => $_SERVER['HTTP_HOST'], 'secret' => $secret, 'product_count' => $array );
932
 
933
- $this->printLog('getProductCount : Finished collecting all stores product count ','',$debug);
934
 
935
  $finalurl = $finalUrl.'product_count';
936
 
937
- $this->printLog('getProductCount : Adding product_count and send the array to endpoint as ',$finalurl,$debug);
938
 
939
  // sending request
940
  $response = Mage::getModel('expertrec_recommendation/api_request')
941
  ->setPrepareRequestStatus(false)
942
  ->setUserId('expertrec')
943
  ->setUrl($finalurl)
944
- ->setMethod(Zend_Http_Client::GET)
945
  ->setData($array_count)
946
  ->setHeader("Content-Type",'application/json')
947
  ->setPrepareRequestStatus(true)
948
  ->sendRequest();
949
 
950
- // $logger->log('UserFeedPush_Track: request with product count sent');
951
  if(!$response) {
952
- // $logger->log('UserFeedPush_Track: request failed for total_count');
953
- $this->printLog('getProductCount : Request failed for product_count on ',$finalurl,$debug);
 
 
954
  }
955
  }
956
  catch (Exception $e) {
957
- // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
958
- $this->printLog('getProductCount : Exception on collecting product-count ',$e->getMessage(),$debug);
959
  }
960
 
961
  $this->printLog('**********************************************************','',$debug);
@@ -967,53 +971,51 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
967
  */
968
  public function getCurrency($finalUrl,$debug){
969
 
970
- // $logger = Mage::getSingleton('expertrec_recommendation/log');
971
- $this->printLog('getCurrency : Started getCurrency','',$debug);
972
 
973
  try{
974
 
975
  $baseCurrency = Mage::app()->getStore()->getBaseCurrencyCode();
976
  $currCurrency = Mage::app()->getStore()->getCurrentCurrencyCode();
977
 
978
- $this->printLog('getCurrency : Collecting currency info ','',$debug);
979
 
980
  $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
981
 
982
  $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
983
  $allCurrencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
984
 
985
- $this->printLog('getCurrency : Collecting all currency rates ','',$debug);
986
 
987
  $array_currency = array(
988
  'baseCurrency' => $baseCurrency,
989
  'currCurrency' => $currCurrency,
990
  'currencyRates' => $allCurrencyRates);
991
 
992
- // $logger->log("currency ".print_r($array_currency,1));
993
  $finalurl = $finalUrl.'currency';
994
 
995
- $this->printLog('getCurrency : Add currency and send array to endpoint as ',$finalurl,$debug);
996
 
997
  // sending request
998
  $response = Mage::getModel('expertrec_recommendation/api_request')
999
  ->setPrepareRequestStatus(false)
1000
  ->setUserId('expertrec')
1001
  ->setUrl($finalurl)
1002
- ->setMethod(Zend_Http_Client::GET)
1003
  ->setData($array_currency)
1004
  ->setHeader("Content-Type",'application/json')
1005
  ->setPrepareRequestStatus(true)
1006
  ->sendRequest();
1007
 
1008
- // $logger->log('UserFeedPush_Track: request with currency details sent');
1009
  if(!$response) {
1010
- // $logger->log('UserFeedPush_Track: request failed for total_count');
1011
- $this->printLog('getCurrency : Request failed for currency info ','',$debug);
1012
-
 
1013
  }
1014
  }catch (Exception $e) {
1015
- // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1016
- $this->printLog('getCurrency : Exception on collecting Currency info ',$e->getMessage(),$debug);
1017
  }
1018
 
1019
  $this->printLog('**********************************************************','',$debug);
@@ -1024,22 +1026,23 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1024
  Get all categories
1025
  */
1026
  public function getCategories($finalUrl,$debug){
1027
-
1028
- // $logger = Mage::getSingleton('expertrec_recommendation/log');
1029
- $this->printLog('getCategories : Started getCategories','',$debug);
1030
 
1031
  try{
 
 
1032
 
1033
  $category = Mage::getModel('catalog/category');
1034
  $tree = $category->getTreeModel();
1035
  $tree->load();
1036
  $ids = $tree->getCollection()->getAllIds();
1037
 
1038
- $this->printLog('getCategories : Collecting tree of category id ','',$debug);
1039
 
1040
  if ($ids){
1041
 
1042
- $this->printLog('getCategories : If the ids are not null, then iterate','',$debug);
1043
 
1044
  for($i=0;$i<count($ids);$i++){
1045
 
@@ -1047,7 +1050,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1047
  $cat = Mage::getModel('catalog/category');
1048
  $cat->load($id);
1049
 
1050
- $this->printLog('getCategories : Collecting catagory name and info for id # ',$id,$debug);
1051
 
1052
  $entity_id = $cat->getId();
1053
  $name = $cat->getName();
@@ -1070,35 +1073,32 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1070
  $category_path = implode(chr(3), $pathNameArray);
1071
  $catarr['cat_name_path'] = $category_path;
1072
 
1073
- $categoryArray[$i]=$catarr;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1074
  }
 
1075
  }
1076
- // $logger->log("categories : ".print_r($categoryArray,1));
1077
-
1078
- $finalurl = $finalUrl.'all-category';
1079
-
1080
- $this->printLog('getCategories : Add all-category and send the array to endpoint as ',$finalurl,$debug);
1081
-
1082
- // sending request
1083
- $response = Mage::getModel('expertrec_recommendation/api_request')
1084
- ->setPrepareRequestStatus(false)
1085
- ->setUserId('expertrec')
1086
- ->setUrl($finalurl)
1087
- ->setMethod(Zend_Http_Client::POST)
1088
- ->setData($categoryArray)
1089
- ->setHeader("Content-Type",'application/json')
1090
- ->setPrepareRequestStatus(true)
1091
- ->sendRequest();
1092
-
1093
- // $logger->log('UserFeedPush_Track: request with category details sent');
1094
- if(!$response) {
1095
-
1096
- // $logger->log('UserFeedPush_Track: request failed for cartegory');
1097
- $this->printLog('getCategories : Request failed for cartegory','',$debug);
1098
- }
1099
  }catch (Exception $e) {
1100
- // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1101
- $this->printLog('getCategories : Exception on collecting categories ',$e->getMessage(),$debug);
1102
  }
1103
 
1104
  $this->printLog('**********************************************************','',$debug);
@@ -1108,77 +1108,64 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1108
  /*
1109
  Get popular product query
1110
  */
1111
- public function getPopularQuerries($finalUrl,$debug){
1112
 
1113
- // $logger = Mage::getSingleton('expertrec_recommendation/log');
1114
- $this->printLog('getPopularQuerries : Started get_popular_queries','',$debug);
1115
 
1116
  try{
1117
 
 
 
1118
  $feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
1119
 
1120
  foreach ($this->_storeId as $storeId) {
 
1121
 
1122
- $this->printLog('getPopularQuerries : Collecting popular_queries for store # ',$storeId,$debug);
1123
 
1124
  $collection = Mage::getResourceModel('catalogsearch/query_collection')
1125
  ->addStoreFilter($storeId)
1126
  ->setStoreId($storeId);
1127
  $collection->getSelect()->where('query_text != "__empty__"');
1128
- // $collection->setPageSize($feedConfig->pageSize);
1129
- // $pageEnd = $feedConfig->pageEnd;
1130
- // $lastPageNumber = $collection->getLastPageNumber();
1131
- // if($pageEnd != 0 && $pageEnd < $lastPageNumber){
1132
- // $pages = $pageEnd;
1133
- // }else{
1134
- // $pages = $lastPageNumber;
1135
- // }
1136
- // $logger->log("Total no. of pages for which we are collecting popular products feed in this reqeust: #".$pages);
1137
- // for($currentPage = $feedConfig->pageStart; $currentPage <= $pages; $currentPage++) {
1138
- // $logger->log("Collecting popular products feed for page: #".$currentPage);
1139
- // $collection->setCurPage($currentPage);
1140
- foreach ($collection as $suggestion) {
1141
- $value = $suggestion->getData();
1142
- $array[] = $value;
1143
- }
1144
- // }
1145
- }
1146
 
1147
- $finalurl = $finalUrl.'popular_querries';
 
 
 
1148
 
1149
- $this->printLog('getPopularQuerries : Added popular_querries and send array to endpoint as ',$finalurl,$debug);
1150
- // $logger->log("value ".print_r($array,1));
1151
- // sending request
1152
- $response = Mage::getModel('expertrec_recommendation/api_request')
1153
- ->setPrepareRequestStatus(false)
1154
- ->setUserId('expertrec')
1155
- ->setUrl($finalurl)
1156
- ->setMethod(Zend_Http_Client::POST)
1157
- ->setData($array)
1158
- ->setHeader("Content-Type",'application/json')
1159
- ->setPrepareRequestStatus(true)
1160
- ->sendRequest();
1161
 
1162
- // $logger->log('UserFeedPush_Track: request with popularproduct details sent');
1163
- if(!$response) {
1164
- // $logger->log('UserFeedPush_Track: request failed for popularproduct');
1165
- $this->printLog('getPopularQuerries : Request failed for popularproduct ','',$debug);
 
 
1166
  }
1167
- }catch (Exception $e) {
1168
- // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1169
- $this->printLog('getPopularQuerries : Exception on collecting popular_queries ',$e->getMessage(),$debug);
 
1170
  }
1171
 
1172
  $this->printLog('**********************************************************','',$debug);
1173
 
1174
  }
1175
-
1176
  /*
1177
  Push feed per product
1178
  */
1179
  public function getFeedData(){
1180
-
1181
- $logger = Mage::getSingleton('expertrec_recommendation/log');
1182
 
1183
  // update db to 1 once feed pushed
1184
  Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_push','1');
@@ -1194,13 +1181,14 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1194
  $mid = $data['merchantid'];
1195
  $secret = $data['secret'];
1196
 
 
1197
  $debug = $this->getDebugInfo($mid);
1198
 
1199
  if(!isset($debug)){
1200
  $debug = 1; // default in debug mode
1201
  }
1202
 
1203
- $logger->log(" Debug status is ".$debug);
1204
 
1205
  // feedUrl as api to userpushfeed
1206
  $feedUrl = "https://feed.expertrec.com/magento/n01eba6261ad7f174cd3a16523e86e65/";
@@ -1208,9 +1196,9 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1208
  // finalurl added with merchant id
1209
  $finalUrl = $feedUrl.''.$mid.'/';
1210
 
1211
- $this->printLog('getFeedData : Adding mid to feedendpoint as',$finalUrl,$debug);
1212
 
1213
- $this->printLog('getFeedData : Calling get product count ','',$debug);
1214
 
1215
  // calculate number of products and send
1216
  $this->getProductCount($finalUrl,$secret,$debug);
@@ -1219,21 +1207,20 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1219
  // check for feed pushed
1220
  $feed_pushed_page_info = Mage::getStoreConfig(self::PUSHED_FEED_PAGES);
1221
 
1222
- $this->printLog('getFeedData : Fetching pushed_feed_pages info from db as ',$feed_pushed_page_info,$debug);
1223
 
1224
  $feed_pushed_page_info_array = explode(',', $feed_pushed_page_info);
1225
  $store_Id_pushed = $feed_pushed_page_info_array[0];
1226
  $pages_pushed = $feed_pushed_page_info_array[1];
1227
 
1228
- $this->printLog('getFeedData : Checking for pushed_store_ids as ',$store_Id_pushed,$debug);
1229
 
1230
  if($store_Id_pushed == 0){
1231
 
1232
- $this->printLog('getFeedData : Calling get currency ','',$debug);
1233
 
1234
  // collect currencies
1235
  $this->getCurrency($finalUrl,$debug);
1236
-
1237
 
1238
  }
1239
 
@@ -1248,7 +1235,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1248
  if (isset($storedHeaders)){
1249
  $header = explode(',', $storedHeaders);
1250
 
1251
- $this->printLog('getFeedData : Collect headers ','',$debug);
1252
  }
1253
  else{
1254
  $header = array();
@@ -1256,21 +1243,23 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1256
 
1257
  $finalurl = $finalUrl.'product';
1258
 
1259
- $this->printLog('getFeedData : Added product to endpoint as ',$finalurl,$debug);
1260
 
1261
  if(!empty($header)){
1262
 
1263
  $stores = count($this->_storeId);
1264
 
1265
- $this->printLog('getFeedData : Headers are not empty & get no.of stores as ',$stores,$debug);
 
 
1266
 
1267
  foreach ($this->_storeId as $storeId) {
1268
 
1269
- $this->printLog('getFeedData : Collecting store info of store_id # ',$storeId,$debug);
1270
 
1271
  if($storeId < $store_Id_pushed){
1272
 
1273
- $this->printLog('getFeedData : In order to resume from last pull, skip store_id as it pulled # ',$storeId,$debug);
1274
 
1275
  continue;
1276
  }
@@ -1279,12 +1268,12 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1279
  $websiteId = $oStore->getWebsiteId();
1280
  $website = Mage::app()->getWebsite($websiteId);
1281
 
1282
- $this->printLog('getFeedData : Get store and website info for store # ',$storeId,$debug);
1283
 
1284
  $collection=$filter->addBasicFilter($website,$oStore)
1285
  ->setPageSize($feedConfig->pageSize);
1286
 
1287
- $this->printLog('getFeedData : Get product collection ','',$debug);
1288
 
1289
  $pageEnd = $feedConfig->pageEnd;
1290
  $lastPageNumber = $collection->getLastPageNumber();
@@ -1295,34 +1284,33 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1295
  $pages = $lastPageNumber;
1296
  }
1297
 
1298
- $this->printLog('getFeedData : Total no. of pages with products in this store is ',$pages,$debug);
1299
 
1300
- // $logger->log("Total no. of pages for which we are collecting feed in this reqeust: #".$pages." for store #".$storeId);
1301
  for($currentPage = $feedConfig->pageStart; $currentPage <= $pages; $currentPage++) {
1302
  if($storeId <= $store_Id_pushed && $currentPage < $pages_pushed){
1303
 
1304
- $this->printLog('getFeedData : In order to resume from last pull, skip page as it pulled ',$currentPage,$debug);
1305
 
1306
  continue;
1307
  }
1308
  else{
1309
 
1310
- $this->printLog('getFeedData : Collecting products for page ',$currentPage,$debug);
1311
 
1312
- // $logger->log("Collecting feed for page: #".$currentPage);
1313
  $collection->setCurPage($currentPage);
1314
  // get all products
1315
  foreach ($collection as $product) {
1316
  try{
1317
 
1318
- $this->printLog('getFeedData : Collecting info of product_id # ',$product->getId(),$debug);
1319
 
1320
  $resultArray = $formatter->prepareRow($header,$product);
1321
  $resultArray['storeId'] = $storeId;
1322
  $resultArray['websiteId'] = $websiteId;
1323
- // $logger->log("res ".print_r($resultArray,1));
1324
 
1325
- $this->printLog('getFeedData : Send request to endpoint as',$finalurl,$debug);
1326
 
1327
  // sending request
1328
  $response = Mage::getModel('expertrec_recommendation/api_request')
@@ -1334,22 +1322,20 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1334
  ->setHeader("Content-Type",'application/json')
1335
  ->setPrepareRequestStatus(true)
1336
  ->sendRequest();
1337
- // $logger->log('UserFeedPush_Track: request succeded for product with Id #'.$product->getId().' of store '.$storeId);
1338
  if(!$response) {
1339
 
1340
- // $logger->log('UserFeedPush_Track: request failed for product with Id #'.$product->getId());
1341
- $this->printLog('getFeedData : Request failed for product with Id #',$product->getId(),$debug);
1342
  }
1343
  $page = $storeId.','.$currentPage;
1344
 
1345
- $this->printLog('getFeedData : Updating, sent pages and store info in db as ',$page,$debug);
1346
 
1347
  Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1348
  }
1349
  catch (Exception $e) {
1350
 
1351
- // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1352
- $this->printLog('getFeedData : Exception on collecting Product info ',$e->getMessage(),$debug);
1353
  }
1354
  } // if page is not pushed
1355
  } // foreach collection
@@ -1358,22 +1344,22 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1358
  } // if store is not pushed
1359
  $stores--;
1360
 
1361
- $this->printLog('getFeedData : Reduce store count to keep track of no.of stores pushed as ',$stores,$debug);
1362
  } // for each store
1363
  $page = '0,0';
1364
 
1365
- $this->printLog('getFeedData : Once all stores with pages pushed, update pushed_feed in db as',$page,$debug);
1366
 
1367
  Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1368
  } // if not empty headers
1369
  // check for feed completion
1370
  if($stores == 0){
1371
 
1372
- $this->printLog('getFeedData : After completing product push, stores remainig are ',$stores,$debug);
1373
 
1374
  $array = array('completed' => 1, );
1375
 
1376
- $this->printLog('getFeedData : Send completed request to endpoint ','',$debug);
1377
 
1378
  $response = Mage::getModel('expertrec_recommendation/api_request')
1379
  ->setPrepareRequestStatus(false)
@@ -1384,27 +1370,28 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1384
  ->setHeader("Content-Type",'application/json')
1385
  ->setPrepareRequestStatus(true)
1386
  ->sendRequest();
1387
- // $logger->log('UserFeedPush_Track: request completed');
1388
  if(!$response) {
1389
- // $logger->log('UserFeedPush_Track: Request not complete');
1390
- $this->printLog('getFeedData : Request failed for completed info ','',$debug);
 
1391
  }
1392
  }
1393
  }catch (Exception $e) {
1394
- // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1395
- $this->printLog('getFeedData : Exception on sending completed info ',$e->getMessage(),$debug);
1396
  }
1397
 
1398
- $this->printLog('getFeedData : Calling get all-categories ','',$debug);
1399
 
1400
  // collect all catagories
1401
  $this->getCategories($finalUrl,$debug);
1402
 
1403
- $this->printLog('getFeedData : Calling getPopularQuerries','',$debug);
1404
 
1405
- $this->getPopularQuerries($finalUrl,$debug);
 
1406
 
1407
- $logger->logMemoryUsage();
1408
 
1409
  }
1410
 
@@ -1413,15 +1400,14 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1413
  */
1414
  public function bgProcess(){
1415
 
1416
- $logger = Mage::getSingleton('expertrec_recommendation/log');
1417
- $logger->log(" Background process for pull-feed started ");
1418
 
1419
  ob_end_clean();
1420
  //avoid apache to kill the php running
1421
  ignore_user_abort(true);
1422
  ob_start();//start buffer output
1423
 
1424
- echo "pull feed started in background";
1425
  //close session file on server side to avoid blocking other requests
1426
  session_write_close();
1427
 
@@ -1432,6 +1418,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1432
  ob_end_flush();
1433
  flush();
1434
 
 
1435
  $this->getFeedData();
1436
 
1437
  }
@@ -1444,7 +1431,10 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1444
  Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
1445
  Mage::app()->getResponse()->sendResponse();
1446
 
 
 
1447
  $this->bgProcess();
 
1448
  }
1449
 
1450
  /*
@@ -1452,19 +1442,19 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
1452
  */
1453
  public function pullFeedAction(){
1454
 
1455
- $logger = Mage::getSingleton('expertrec_recommendation/log');
1456
-
1457
  try{
1458
 
1459
- $logger->log(" Pull Feed started in background ");
1460
  // background process
1461
  $this->bgProcess();
1462
 
1463
  }catch (Exception $e) {
1464
 
1465
- $logger->log(" Not able to pull the feed : ".$e->getMessage());
1466
- $logger->log(' Backtrace in pull feed : '.mageDebugBacktrace(true, true, true));
 
1467
  }
 
1468
  }
1469
 
1470
  }
26
  const CONFIG_SECRET = 'expertrec/general/secret';
27
  const PUSHED_FEED_PAGES = 'expertrec/general/expertrec_feed_pushed_pages';
28
 
29
+ const BUILD_NO = "1494571967";
30
+ const EXPERTREC_VERSION = "1.2.16";
31
  private $_password;
32
  private $_storeId = array();
33
 
755
  return $result;
756
  }
757
 
758
+ /*
759
+ logger
760
+ */
761
+ public function logger(){
762
+
763
+ $logger = Mage::getSingleton('expertrec_recommendation/log');
764
+ return $logger;
765
+
766
+ }
767
+
768
  /********
769
  Debug -- add logs
770
  ********/
771
  public function printLog($string,$var,$debug){
772
  if ($debug == 1) {
773
+ $this->logger()->log($string.$var);
 
774
  }
775
  }
776
 
779
  */
780
  public function getMidSecret(){
781
 
 
782
  $feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
783
 
784
+ $this->logger()->log('Pull-Feed : Get-mid-secret started ');
785
 
786
  $mid = Mage::getStoreConfig(self::MERCHANT_ID);
787
  $secret = Mage::getStoreConfig(self::CONFIG_SECRET);
826
  $data = json_decode($response->getBody(),true);
827
  $mid = $data['merchantid'];
828
  $secret = $data['secret'];
829
+ //$this->logger()->log('data '.print_r($data,1));
830
+
831
+ $this->logger()->log('Pull-Feed : Generated new mid and secret ');
832
 
833
  // update mid and secret
834
  Mage::helper("expertrec_recommendation")
835
+ ->saveConfig('secret',$data['secret'])
836
+ ->saveConfig('mid',$data['merchantid'])
837
+ ->clearCache();
 
 
838
  }
839
  catch (Zend_Http_Client_Exception $e) {
840
+ $this->logger()->log('Pull-Feed : ERROR : '.sprintf($apiUrl .' Failed to create mid&secret because HTTP error: %s ', $e->getMessage()),Zend_Log::ERR);
841
  }
842
  }
843
  else{
849
  $storedMid = $mid;
850
  $feedConfig->setMerchantId($storedMid);
851
 
852
+ $this->logger()->log('Pull-Feed : Fetched mid-secret and stored in config');
853
 
854
  return $data;
855
 
860
  */
861
  public function getDebugInfo($mid){
862
 
 
 
 
863
  $apiUrl = 'https://magento.expertrec.com/4561bd2ff542abec2f0247b1c1b759f2/';
864
  $finalUrl = $apiUrl.$mid;
865
 
876
 
877
  $data = json_decode($response->getBody(),true);
878
  $debug = $data['debug'];
879
+ //$this->logger()->log('data '.print_r($data,1));
880
 
881
  // update debug status
882
  Mage::helper("expertrec_recommendation")
883
  ->saveConfig('debug',$debug)
884
  ->clearCache();
885
 
886
+ $this->logger()->log('Pull-Feed : Debug status added to db as '.$debug);
887
  }
888
  catch (Zend_Http_Client_Exception $e) {
889
+ $this->logger()->log('Pull-Feed : ERROR : '.sprintf($apiUrl .' Failed to set debug status because HTTP error: %s ', $e->getMessage()),Zend_Log::ERR);
890
  }
891
 
892
  $this->printLog('**********************************************************','',$debug);
900
  */
901
  public function getProductCount($finalUrl,$secret,$debug){
902
 
903
+ $this->printLog('Pull-Feed : getProductCount : Started product_count ','',$debug);
 
904
 
905
  $filter = Mage::getSingleton('expertrec_recommendation/feed_feedfilter');
906
 
907
+ $this->printLog('Pull-Feed : getProductCount : Collecting allstores ','',$debug);
908
 
909
  try{
910
 
915
  $websiteId = $store->getWebsiteId();
916
  $website = Mage::app()->getWebsite($websiteId);
917
 
918
+ $this->printLog('Pull-Feed : getProductCount : Collecting info of store # ',$storeId,$debug);
919
 
920
  $this->_storeId[] = $storeId;
921
 
923
  $collection = $filter->addBasicFilter($website,$store);
924
  $count = $collection->getSize();
925
 
926
+ $this->printLog('Pull-Feed : getProductCount : Collecting product_count of store as ',$count,$debug);
927
 
928
  $array[] = array('wid' => $websiteId, 'sid' => $storeId, 'total_products' => $count);
929
 
930
  }
931
  $collection->clear();
932
 
933
+ // $this->logger()->log('p-count '.print_r($array,1));
934
 
935
  $array_count = array('site_host' => $_SERVER['HTTP_HOST'], 'secret' => $secret, 'product_count' => $array );
936
 
937
+ $this->printLog('Pull-Feed : getProductCount : Finished collecting all stores product_count ','',$debug);
938
 
939
  $finalurl = $finalUrl.'product_count';
940
 
941
+ $this->printLog('Pull-Feed : getProductCount : Adding product_count and send the array to endpoint as ',$finalurl,$debug);
942
 
943
  // sending request
944
  $response = Mage::getModel('expertrec_recommendation/api_request')
945
  ->setPrepareRequestStatus(false)
946
  ->setUserId('expertrec')
947
  ->setUrl($finalurl)
948
+ ->setMethod(Zend_Http_Client::POST)
949
  ->setData($array_count)
950
  ->setHeader("Content-Type",'application/json')
951
  ->setPrepareRequestStatus(true)
952
  ->sendRequest();
953
 
 
954
  if(!$response) {
955
+ $this->logger()->log('Pull-Feed : ERROR : Request failed for product_count on '.$finalurl);
956
+ }
957
+ else{
958
+ $this->logger()->log('Pull-Feed : Request with product_count sent successfully');
959
  }
960
  }
961
  catch (Exception $e) {
962
+ $this->logger()->log('Pull-Feed : ERROR : Exception on collecting product_count '.$e->getMessage());
 
963
  }
964
 
965
  $this->printLog('**********************************************************','',$debug);
971
  */
972
  public function getCurrency($finalUrl,$debug){
973
 
974
+ $this->printLog('Pull-Feed : getCurrency : Started currency','',$debug);
 
975
 
976
  try{
977
 
978
  $baseCurrency = Mage::app()->getStore()->getBaseCurrencyCode();
979
  $currCurrency = Mage::app()->getStore()->getCurrentCurrencyCode();
980
 
981
+ $this->printLog('Pull-Feed : getCurrency : Collecting currency info ','',$debug);
982
 
983
  $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
984
 
985
  $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
986
  $allCurrencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
987
 
988
+ $this->printLog('Pull-Feed : getCurrency : Collecting all currency rates ','',$debug);
989
 
990
  $array_currency = array(
991
  'baseCurrency' => $baseCurrency,
992
  'currCurrency' => $currCurrency,
993
  'currencyRates' => $allCurrencyRates);
994
 
995
+ // $this->logger()->log('currency '.print_r($array_currency,1));
996
  $finalurl = $finalUrl.'currency';
997
 
998
+ $this->printLog('Pull-Feed : getCurrency : Add currency and send array to endpoint as ',$finalurl,$debug);
999
 
1000
  // sending request
1001
  $response = Mage::getModel('expertrec_recommendation/api_request')
1002
  ->setPrepareRequestStatus(false)
1003
  ->setUserId('expertrec')
1004
  ->setUrl($finalurl)
1005
+ ->setMethod(Zend_Http_Client::POST)
1006
  ->setData($array_currency)
1007
  ->setHeader("Content-Type",'application/json')
1008
  ->setPrepareRequestStatus(true)
1009
  ->sendRequest();
1010
 
 
1011
  if(!$response) {
1012
+ $this->logger()->log('Pull-Feed : ERROR : Request failed for currency details');
1013
+ }
1014
+ else{
1015
+ $this->logger()->log('Pull-Feed : Request with currency details sent successfully');
1016
  }
1017
  }catch (Exception $e) {
1018
+ $this->logger()->log('Pull-Feed : ERROR : Exception on collecting Currency details '.$e->getMessage());
 
1019
  }
1020
 
1021
  $this->printLog('**********************************************************','',$debug);
1026
  Get all categories
1027
  */
1028
  public function getCategories($finalUrl,$debug){
1029
+
1030
+ $this->printLog('Pull-Feed : getCategories : Started all_categories','',$debug);
 
1031
 
1032
  try{
1033
+
1034
+ $finalurl = $finalUrl.'all_categories';
1035
 
1036
  $category = Mage::getModel('catalog/category');
1037
  $tree = $category->getTreeModel();
1038
  $tree->load();
1039
  $ids = $tree->getCollection()->getAllIds();
1040
 
1041
+ $this->printLog('Pull-Feed : getCategories : Collecting tree of category id ','',$debug);
1042
 
1043
  if ($ids){
1044
 
1045
+ $this->printLog('Pull-Feed : getCategories : If the ids are not null, then iterate','',$debug);
1046
 
1047
  for($i=0;$i<count($ids);$i++){
1048
 
1050
  $cat = Mage::getModel('catalog/category');
1051
  $cat->load($id);
1052
 
1053
+ $this->printLog('Pull-Feed : getCategories : Collecting catagory name and info for id # ',$id,$debug);
1054
 
1055
  $entity_id = $cat->getId();
1056
  $name = $cat->getName();
1073
  $category_path = implode(chr(3), $pathNameArray);
1074
  $catarr['cat_name_path'] = $category_path;
1075
 
1076
+ // $this->logger()->log('result-array '.print_r($catarr,1));
1077
+ $this->printLog('Pull-Feed : getCategories : Send the category info to endpoint as ',$finalurl,$debug);
1078
+
1079
+ // sending request
1080
+ $response = Mage::getModel('expertrec_recommendation/api_request')
1081
+ ->setPrepareRequestStatus(false)
1082
+ ->setUserId('expertrec')
1083
+ ->setUrl($finalurl)
1084
+ ->setMethod(Zend_Http_Client::POST)
1085
+ ->setData($catarr)
1086
+ ->setHeader("Content-Type",'application/json')
1087
+ ->setPrepareRequestStatus(true)
1088
+ ->sendRequest();
1089
+
1090
+ if(!$response) {
1091
+ $this->logger()->log('Pull-Feed : ERROR : Request failed for all_categories with category # '.$id);
1092
+ }
1093
+ else{
1094
+ $this->printLog('Pull-Feed : getCategories : Request with all_categories sent successfully for category # ',$id,$debug);
1095
+ }
1096
  }
1097
+ $this->logger()->log('Pull-Feed : Request with all_categories sent successfully ');
1098
  }
1099
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1100
  }catch (Exception $e) {
1101
+ $this->logger()->log('Pull-Feed : ERROR : Exception on collecting all_categories '.$e->getMessage());
 
1102
  }
1103
 
1104
  $this->printLog('**********************************************************','',$debug);
1108
  /*
1109
  Get popular product query
1110
  */
1111
+ public function getPopularQueries($finalUrl,$debug){
1112
 
1113
+ $this->printLog('Pull-Feed : getPopularQueries : Started popular_queries ','',$debug);
 
1114
 
1115
  try{
1116
 
1117
+ $finalurl = $finalUrl.'popular_queries';
1118
+
1119
  $feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
1120
 
1121
  foreach ($this->_storeId as $storeId) {
1122
+ $array = array();
1123
 
1124
+ $this->printLog('Pull-Feed : getPopularQueries : Collecting popular_queries for store # ',$storeId,$debug);
1125
 
1126
  $collection = Mage::getResourceModel('catalogsearch/query_collection')
1127
  ->addStoreFilter($storeId)
1128
  ->setStoreId($storeId);
1129
  $collection->getSelect()->where('query_text != "__empty__"');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1130
 
1131
+ foreach ($collection as $suggestion) {
1132
+ $value = $suggestion->getData();
1133
+ $array[] = $value;
1134
+ }
1135
 
1136
+ $this->printLog('Pull-Feed : getPopularQueries : Send popular_queries info to endpoint as ',$finalurl,$debug);
1137
+
1138
+ // sending request
1139
+ $response = Mage::getModel('expertrec_recommendation/api_request')
1140
+ ->setPrepareRequestStatus(false)
1141
+ ->setUserId('expertrec')
1142
+ ->setUrl($finalurl)
1143
+ ->setMethod(Zend_Http_Client::POST)
1144
+ ->setData($array)
1145
+ ->setHeader("Content-Type",'application/json')
1146
+ ->setPrepareRequestStatus(true)
1147
+ ->sendRequest();
1148
 
1149
+ if(!$response) {
1150
+ $this->logger()->log('Pull-Feed : ERROR : Request failed for popular_queries for store # '.$storeId);
1151
+ }
1152
+ else{
1153
+ $this->printLog('Pull-Feed : getPopularQueries : Request with popular_queries sent successfully for store # ',$storeId,$debug);
1154
+ }
1155
  }
1156
+ $this->logger()->log('Pull-Feed : Request with popular_queries sent successfully ');
1157
+ }
1158
+ catch (Exception $e) {
1159
+ $this->logger()->log('Pull-Feed : ERROR : Exception on collecting popular_queries '.$e->getMessage());
1160
  }
1161
 
1162
  $this->printLog('**********************************************************','',$debug);
1163
 
1164
  }
 
1165
  /*
1166
  Push feed per product
1167
  */
1168
  public function getFeedData(){
 
 
1169
 
1170
  // update db to 1 once feed pushed
1171
  Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_push','1');
1181
  $mid = $data['merchantid'];
1182
  $secret = $data['secret'];
1183
 
1184
+ // Get debug info
1185
  $debug = $this->getDebugInfo($mid);
1186
 
1187
  if(!isset($debug)){
1188
  $debug = 1; // default in debug mode
1189
  }
1190
 
1191
+ $this->logger()->log('Pull-Feed : Debug status is '.$debug);
1192
 
1193
  // feedUrl as api to userpushfeed
1194
  $feedUrl = "https://feed.expertrec.com/magento/n01eba6261ad7f174cd3a16523e86e65/";
1196
  // finalurl added with merchant id
1197
  $finalUrl = $feedUrl.''.$mid.'/';
1198
 
1199
+ $this->printLog('Pull-Feed : getFeedData : Adding mid to feedendpoint as ',$finalUrl,$debug);
1200
 
1201
+ $this->printLog('Pull-Feed : getFeedData : Calling get product_count ','',$debug);
1202
 
1203
  // calculate number of products and send
1204
  $this->getProductCount($finalUrl,$secret,$debug);
1207
  // check for feed pushed
1208
  $feed_pushed_page_info = Mage::getStoreConfig(self::PUSHED_FEED_PAGES);
1209
 
1210
+ $this->printLog('Pull-Feed : getFeedData : Fetching pushed_feed_pages info from db as ',$feed_pushed_page_info,$debug);
1211
 
1212
  $feed_pushed_page_info_array = explode(',', $feed_pushed_page_info);
1213
  $store_Id_pushed = $feed_pushed_page_info_array[0];
1214
  $pages_pushed = $feed_pushed_page_info_array[1];
1215
 
1216
+ $this->printLog('Pull-Feed : getFeedData : Checking for pushed_store_ids as ',$store_Id_pushed,$debug);
1217
 
1218
  if($store_Id_pushed == 0){
1219
 
1220
+ $this->printLog('Pull-Feed : getFeedData : Calling get currency ','',$debug);
1221
 
1222
  // collect currencies
1223
  $this->getCurrency($finalUrl,$debug);
 
1224
 
1225
  }
1226
 
1235
  if (isset($storedHeaders)){
1236
  $header = explode(',', $storedHeaders);
1237
 
1238
+ $this->printLog('Pull-Feed : getFeedData : Collect headers ','',$debug);
1239
  }
1240
  else{
1241
  $header = array();
1243
 
1244
  $finalurl = $finalUrl.'product';
1245
 
1246
+ $this->printLog('Pull-Feed : getFeedData : Added product to endpoint as ',$finalurl,$debug);
1247
 
1248
  if(!empty($header)){
1249
 
1250
  $stores = count($this->_storeId);
1251
 
1252
+ $this->printLog('Pull-Feed : getFeedData : Headers are not empty & get no.of stores as ',$stores,$debug);
1253
+
1254
+ $this->logger()->log('Pull-Feed : Started pushing product data');
1255
 
1256
  foreach ($this->_storeId as $storeId) {
1257
 
1258
+ $this->printLog('Pull-Feed : getFeedData : Collecting store info of store_id # ',$storeId,$debug);
1259
 
1260
  if($storeId < $store_Id_pushed){
1261
 
1262
+ $this->printLog('Pull-Feed : getFeedData : In order to resume from last pull, skip store_id as it pulled # ',$storeId,$debug);
1263
 
1264
  continue;
1265
  }
1268
  $websiteId = $oStore->getWebsiteId();
1269
  $website = Mage::app()->getWebsite($websiteId);
1270
 
1271
+ $this->printLog('Pull-Feed : getFeedData : Get store and website info for store # ',$storeId,$debug);
1272
 
1273
  $collection=$filter->addBasicFilter($website,$oStore)
1274
  ->setPageSize($feedConfig->pageSize);
1275
 
1276
+ $this->printLog('Pull-Feed : getFeedData : Get product collection ','',$debug);
1277
 
1278
  $pageEnd = $feedConfig->pageEnd;
1279
  $lastPageNumber = $collection->getLastPageNumber();
1284
  $pages = $lastPageNumber;
1285
  }
1286
 
1287
+ $this->logger()->log('Pull-Feed : Total no.of pages are '.$pages.' for store # '.$storeId);
1288
 
 
1289
  for($currentPage = $feedConfig->pageStart; $currentPage <= $pages; $currentPage++) {
1290
  if($storeId <= $store_Id_pushed && $currentPage < $pages_pushed){
1291
 
1292
+ $this->printLog('Pull-Feed : getFeedData : In order to resume from last pull, skip page as it pulled ',$currentPage,$debug);
1293
 
1294
  continue;
1295
  }
1296
  else{
1297
 
1298
+ $this->printLog('Pull-Feed : getFeedData : Collecting products for page ',$currentPage,$debug);
1299
 
1300
+ $this->logger()->log('Pull-Feed : Collecting feed for page: # '.$currentPage);
1301
  $collection->setCurPage($currentPage);
1302
  // get all products
1303
  foreach ($collection as $product) {
1304
  try{
1305
 
1306
+ $this->printLog('Pull-Feed : getFeedData : Collecting info of product_id # ',$product->getId(),$debug);
1307
 
1308
  $resultArray = $formatter->prepareRow($header,$product);
1309
  $resultArray['storeId'] = $storeId;
1310
  $resultArray['websiteId'] = $websiteId;
1311
+ // $this->logger()->log('res '.print_r($resultArray,1));
1312
 
1313
+ $this->printLog('Pull-Feed : getFeedData : Send request to endpoint as ',$finalurl,$debug);
1314
 
1315
  // sending request
1316
  $response = Mage::getModel('expertrec_recommendation/api_request')
1322
  ->setHeader("Content-Type",'application/json')
1323
  ->setPrepareRequestStatus(true)
1324
  ->sendRequest();
1325
+
1326
  if(!$response) {
1327
 
1328
+ $this->logger()->log('Pull-Feed : ERROR : Request failed for product with Id # '.$product->getId());
 
1329
  }
1330
  $page = $storeId.','.$currentPage;
1331
 
1332
+ $this->printLog('Pull-Feed : getFeedData : Updating, sent pages and store info in db as ',$page,$debug);
1333
 
1334
  Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1335
  }
1336
  catch (Exception $e) {
1337
 
1338
+ $this->logger()->log('Pull-Feed : ERROR : Exception on collecting Product info '.$e->getMessage());
 
1339
  }
1340
  } // if page is not pushed
1341
  } // foreach collection
1344
  } // if store is not pushed
1345
  $stores--;
1346
 
1347
+ $this->printLog('Pull-Feed : getFeedData : Reduce store count to keep track of no.of stores pushed as ',$stores,$debug);
1348
  } // for each store
1349
  $page = '0,0';
1350
 
1351
+ $this->printLog('Pull-Feed : getFeedData : Once all stores with pages pushed, update pushed_feed in db as ',$page,$debug);
1352
 
1353
  Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1354
  } // if not empty headers
1355
  // check for feed completion
1356
  if($stores == 0){
1357
 
1358
+ $this->printLog('Pull-Feed : getFeedData : After completing product push, stores remainig are ',$stores,$debug);
1359
 
1360
  $array = array('completed' => 1, );
1361
 
1362
+ $this->printLog('Pull-Feed : getFeedData : Send completed request to endpoint ','',$debug);
1363
 
1364
  $response = Mage::getModel('expertrec_recommendation/api_request')
1365
  ->setPrepareRequestStatus(false)
1370
  ->setHeader("Content-Type",'application/json')
1371
  ->setPrepareRequestStatus(true)
1372
  ->sendRequest();
1373
+
1374
  if(!$response) {
1375
+ $this->logger()->log('Pull-Feed : ERROR : Request failed for completed info ');
1376
+ }else{
1377
+ $this->logger()->log('Pull-Feed : Completed request sent successfully ');
1378
  }
1379
  }
1380
  }catch (Exception $e) {
1381
+ $this->logger()->log('Pull-Feed : ERROR : Exception on sending completed info '.$e->getMessage());
 
1382
  }
1383
 
1384
+ $this->printLog('Pull-Feed : getFeedData : Calling get all_categories ','',$debug);
1385
 
1386
  // collect all catagories
1387
  $this->getCategories($finalUrl,$debug);
1388
 
1389
+ $this->printLog('Pull-Feed : getFeedData : Calling get popular_queries ','',$debug);
1390
 
1391
+ // collect popular queries
1392
+ $this->getPopularQueries($finalUrl,$debug);
1393
 
1394
+ $this->logger()->logMemoryUsage();
1395
 
1396
  }
1397
 
1400
  */
1401
  public function bgProcess(){
1402
 
1403
+ $this->logger()->log('Pull-Feed : Background process for pull-feed started ');
 
1404
 
1405
  ob_end_clean();
1406
  //avoid apache to kill the php running
1407
  ignore_user_abort(true);
1408
  ob_start();//start buffer output
1409
 
1410
+ echo "Pull-Feed started in Background";
1411
  //close session file on server side to avoid blocking other requests
1412
  session_write_close();
1413
 
1418
  ob_end_flush();
1419
  flush();
1420
 
1421
+ // Collect feed
1422
  $this->getFeedData();
1423
 
1424
  }
1431
  Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
1432
  Mage::app()->getResponse()->sendResponse();
1433
 
1434
+ $this->logger()->log('******** Feed pushing started in background as Pull-Feed *******');
1435
+ // background process
1436
  $this->bgProcess();
1437
+
1438
  }
1439
 
1440
  /*
1442
  */
1443
  public function pullFeedAction(){
1444
 
 
 
1445
  try{
1446
 
1447
+ $this->logger()->log('Pull-Feed : Pull Feed started in background ');
1448
  // background process
1449
  $this->bgProcess();
1450
 
1451
  }catch (Exception $e) {
1452
 
1453
+ $this->logger()->log('Pull-Feed : ERROR : Not able to pull the feed : '.$e->getMessage());
1454
+ $this->logger()->log('Pull-Feed : ERROR : Backtrace in pull feed : '.mageDebugBacktrace(true, true, true));
1455
+
1456
  }
1457
+
1458
  }
1459
 
1460
  }
app/code/community/Expertrec/Recommendation/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Expertrec_Recommendation>
5
- <version>1.2.15</version>
6
  </Expertrec_Recommendation>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Expertrec_Recommendation>
5
+ <version>1.2.16</version>
6
  </Expertrec_Recommendation>
7
  </modules>
8
  <global>
app/code/community/Expertrec/Recommendation/sql/expertrec_setup/{mysql4-install-1.2.15.php → mysql4-install-1.2.16.php} RENAMED
@@ -11,7 +11,7 @@
11
 
12
  $mage_ver = Mage::getVersion();
13
  $php_ver = phpversion();
14
- $expertrec_version = "1.2.15";
15
 
16
  $installer->startSetup();
17
 
11
 
12
  $mage_ver = Mage::getVersion();
13
  $php_ver = phpversion();
14
+ $expertrec_version = "1.2.16";
15
 
16
  $installer->startSetup();
17
 
app/code/community/Expertrec/Recommendation/sql/expertrec_setup/{mysql4-upgrade-1.2.14-1.2.15.php → mysql4-upgrade-1.2.15-1.2.16.php} RENAMED
@@ -11,7 +11,7 @@
11
 
12
  $mage_ver = Mage::getVersion();
13
  $php_ver = phpversion();
14
- $expertrec_version = "1.2.15";
15
 
16
  $installer->startSetup();
17
 
11
 
12
  $mage_ver = Mage::getVersion();
13
  $php_ver = phpversion();
14
+ $expertrec_version = "1.2.16";
15
 
16
  $installer->startSetup();
17
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Expertrec_Recommendation</name>
4
- <version>1.2.15</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
@@ -10,9 +10,9 @@
10
  <description>Expertrec search extension helps you have complete control over your site search results. You will be able to add instant autocomplete, spell corrections that learn from the user behaviour on your site, and show product recommendations within the search user interface. It also adds search results pages with facets, sorting by different attributes.</description>
11
  <notes>Expertrec Recommendation plugin for magento sites.</notes>
12
  <authors><author><name>melchi</name><user>melchi</user><email>magento@cloudinfra.in</email></author><author><name>magento</name><user>magento</user><email>magento-team@cloudinfra.in</email></author></authors>
13
- <date>2017-05-11</date>
14
- <time>06:35:08</time>
15
- <contents><target name="magecommunity"><dir name="Expertrec"><dir name="Recommendation"><dir name="Block"><file name="Api.php" hash="e7997269c80ea4c7bc24ad67f843ca00"/></dir><dir name="Helper"><file name="Autocompletehelper.php" hash="2a4f4202f7414158764a8e05cbefd596"/><file name="Data.php" hash="7e3728b4efa9ee373f73878a6a665528"/><file name="Filehelper.php" hash="f0deaedcbef965a14b905aea7946d533"/><dir name="Search"><file name="Layout.php" hash="6b0681539b719913caa5107a16ba8549"/></dir><file name="Suggestionhelper.php" hash="9316b6a6412961fbcd05d5a33dc23bcd"/></dir><dir name="Model"><dir name="Api"><file name="Request.php" hash="cd9a43c25e5251df1af848d6a8d371fb"/></dir><dir name="Feed"><file name="Feedconfig.php" hash="77a806249b1a64a5e0e83d010f835130"/><file name="Feedcreator.php" hash="e32cb528c8fb5085adfa06aaae9a92a7"/><file name="Feedfilter.php" hash="1413a1b24f7352a4a592fa5eb9ea395a"/><file name="Formatter.php" hash="a5a92069c5985fc678dd19ebca13e2ce"/></dir><file name="Feed.php" hash="3ddfbd9ba5d9845d1d546581a9f71701"/><file name="Log.php" hash="a96f0a142abc0a2c49e8134599d1eb93"/><file name="Observer.php" hash="e82501d27e78f2b3853236f98651768b"/><dir name="Translator"><file name="Category.php" hash="a1d8248562da426aab2ca319cebbb3c9"/></dir><file name="Validate.php" hash="c4be906568d7e10e51e6a4a42541bf5c"/><dir name="Writer"><file name="Abstract.php" hash="cafb19a4f943e200b775caec92bebd93"/><file name="Csv.php" hash="27d3188526f885de87b882d196a16c6d"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="4aec75bacab301a25c34bc2eecb57bcf"/></dir><file name="ApiController.php" hash="c6504722ffe737cc113d34e8ff1fc9b6"/><dir name="CatalogSearch"><file name="ResultController.php" hash="e740f44c0cef4aa83545f2278626e7de"/></dir><file name="ConfigController.php" hash="07af2da00256ce6ab54a98b2980ea348"/><file name="IndexController.php" hash="842d75f0f36821bf930c46230ff85f6c"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4d5ac7be55302f8555d5b3191e8cb70d"/><file name="config.xml" hash="65771a19e17697ca12ffbeace928d06b"/></dir><dir name="sql"><dir name="expertrec_setup"><file name="mysql4-install-1.2.15.php" hash="c4c713b9f88e5af2aaa7faaa050b77b1"/><file name="mysql4-upgrade-1.2.14-1.2.15.php" hash="bd3332f0db9049ae700461160a3a4210"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Expertrec_Recommendation.xml" hash="c314465f907c89dfe912035be8d48e71"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="expertrec"><file name="recommendation.xml" hash="42f5f223bf42b357cb43829ac3d74fe1"/></dir></dir><dir name="template"><dir name="expertrec"><dir name="feed"><file name="info.phtml" hash="a41d86f3cc01eb09a7dab6da3b203612"/></dir><dir name="recommendation"><file name="tracker.phtml" hash="e903c52c49f3e8c6b5c3ba939e652dfd"/><dir name="tracking"><file name="product.phtml" hash="3dda590a1cdfb25461fbdecd0b548860"/></dir></dir><dir name="search"><file name="custom.phtml" hash="b1bccc7ed9a04472add4192e05dcca24"/><file name="list.phtml" hash="9ff42c7a725ecab6274b1ab768fed95b"/><file name="view.phtml" hash="f86df8e975bf5bfb7733b85655f1911c"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="expertrec"><file name="recommendation.xml" hash="640762ea93c7657975314b8282f53498"/></dir></dir><dir name="template"><dir name="expertrec"><dir name="recommendation"><file name="notifications.phtml" hash="f264dfe05d0fd53c754a071a28cd415c"/></dir></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Expertrec_Recommendation</name>
4
+ <version>1.2.16</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
10
  <description>Expertrec search extension helps you have complete control over your site search results. You will be able to add instant autocomplete, spell corrections that learn from the user behaviour on your site, and show product recommendations within the search user interface. It also adds search results pages with facets, sorting by different attributes.</description>
11
  <notes>Expertrec Recommendation plugin for magento sites.</notes>
12
  <authors><author><name>melchi</name><user>melchi</user><email>magento@cloudinfra.in</email></author><author><name>magento</name><user>magento</user><email>magento-team@cloudinfra.in</email></author></authors>
13
+ <date>2017-05-12</date>
14
+ <time>06:54:16</time>
15
+ <contents><target name="magecommunity"><dir name="Expertrec"><dir name="Recommendation"><dir name="Block"><file name="Api.php" hash="e7997269c80ea4c7bc24ad67f843ca00"/></dir><dir name="Helper"><file name="Autocompletehelper.php" hash="2a4f4202f7414158764a8e05cbefd596"/><file name="Data.php" hash="7e3728b4efa9ee373f73878a6a665528"/><file name="Filehelper.php" hash="f0deaedcbef965a14b905aea7946d533"/><dir name="Search"><file name="Layout.php" hash="6b0681539b719913caa5107a16ba8549"/></dir><file name="Suggestionhelper.php" hash="9316b6a6412961fbcd05d5a33dc23bcd"/></dir><dir name="Model"><dir name="Api"><file name="Request.php" hash="cd9a43c25e5251df1af848d6a8d371fb"/></dir><dir name="Feed"><file name="Feedconfig.php" hash="77a806249b1a64a5e0e83d010f835130"/><file name="Feedcreator.php" hash="e32cb528c8fb5085adfa06aaae9a92a7"/><file name="Feedfilter.php" hash="1413a1b24f7352a4a592fa5eb9ea395a"/><file name="Formatter.php" hash="a5a92069c5985fc678dd19ebca13e2ce"/></dir><file name="Feed.php" hash="3ddfbd9ba5d9845d1d546581a9f71701"/><file name="Log.php" hash="a96f0a142abc0a2c49e8134599d1eb93"/><file name="Observer.php" hash="e82501d27e78f2b3853236f98651768b"/><dir name="Translator"><file name="Category.php" hash="a1d8248562da426aab2ca319cebbb3c9"/></dir><file name="Validate.php" hash="c4be906568d7e10e51e6a4a42541bf5c"/><dir name="Writer"><file name="Abstract.php" hash="cafb19a4f943e200b775caec92bebd93"/><file name="Csv.php" hash="27d3188526f885de87b882d196a16c6d"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="4aec75bacab301a25c34bc2eecb57bcf"/></dir><file name="ApiController.php" hash="ad6a05dcfb5bbdcc5917db4428f9b745"/><dir name="CatalogSearch"><file name="ResultController.php" hash="e740f44c0cef4aa83545f2278626e7de"/></dir><file name="ConfigController.php" hash="07af2da00256ce6ab54a98b2980ea348"/><file name="IndexController.php" hash="842d75f0f36821bf930c46230ff85f6c"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4d5ac7be55302f8555d5b3191e8cb70d"/><file name="config.xml" hash="76f768772ffebdd4309b6262609096ca"/></dir><dir name="sql"><dir name="expertrec_setup"><file name="mysql4-install-1.2.16.php" hash="ac5a910c1db9a63b1141cb0466ac9aab"/><file name="mysql4-upgrade-1.2.15-1.2.16.php" hash="97094772ee883f1b9bdeb8943c117df3"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Expertrec_Recommendation.xml" hash="c314465f907c89dfe912035be8d48e71"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="expertrec"><file name="recommendation.xml" hash="42f5f223bf42b357cb43829ac3d74fe1"/></dir></dir><dir name="template"><dir name="expertrec"><dir name="feed"><file name="info.phtml" hash="a41d86f3cc01eb09a7dab6da3b203612"/></dir><dir name="recommendation"><file name="tracker.phtml" hash="e903c52c49f3e8c6b5c3ba939e652dfd"/><dir name="tracking"><file name="product.phtml" hash="3dda590a1cdfb25461fbdecd0b548860"/></dir></dir><dir name="search"><file name="custom.phtml" hash="b1bccc7ed9a04472add4192e05dcca24"/><file name="list.phtml" hash="9ff42c7a725ecab6274b1ab768fed95b"/><file name="view.phtml" hash="f86df8e975bf5bfb7733b85655f1911c"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="expertrec"><file name="recommendation.xml" hash="640762ea93c7657975314b8282f53498"/></dir></dir><dir name="template"><dir name="expertrec"><dir name="recommendation"><file name="notifications.phtml" hash="f264dfe05d0fd53c754a071a28cd415c"/></dir></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>