Expertrec_Recommendation - Version 1.2.14

Version Notes

Expertrec Recommendation plugin for magento sites.

Download this release

Release Info

Developer melchi
Extension Expertrec_Recommendation
Version 1.2.14
Comparing to
See all releases


Code changes from version 1.2.13 to 1.2.14

app/code/community/Expertrec/Recommendation/controllers/ApiController.php CHANGED
@@ -17,7 +17,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
17
  const SEARCH_CUSTOM_TEMPLATE = 'search/custom_template';
18
  const FEED_LOG_ENDPOINT = 'expertrec/general/log_endpoint';
19
  const FEED_UPLOAD_ENDPOINT = 'expertrec/general/upload_endpoint';
20
- const IS_UPLOAD_FEED = 'expertrec/general/is_upload';
21
  const IMAGE_WIDTH = 'expertrec/general/expertrec_image_width';
22
  const IMAGE_HEIGHT = 'expertrec/general/expertrec_image_height';
23
  const THUMBNAIL_WIDTH = 'expertrec/general/expertrec_thumbnail_width';
@@ -26,11 +26,9 @@ 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
-
30
- const BUILD_NO = "1493366400";
31
- const EXPERTREC_VERSION = "1.2.13";
32
  private $_password;
33
- private $_websiteId = array();
34
  private $_storeId = array();
35
 
36
  //main function which loads the feed API
@@ -348,7 +346,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
348
  <p><b>Without pagination</b><br />';
349
  $result .= '<p>'.$apiUrlWithCustomConf.'</p>
350
  <input type="hidden" name="secret" value="'.$this->_password.'">
351
- <input type="hidden" name="cmd" value="export">
352
  <input type="hidden" name="wid" value="1">
353
  <input type="hidden" name="sid" value="1">
354
  <button type="submit" name="sug1submit" id="sug1submit">Submit</button></form>';
@@ -357,7 +355,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
357
  <p><b>With pagination without page size(default page size is 500)</b><br />';
358
  $result .= '<p>'.$apiUrlWithCustomConf.'&ps=1&pe=2</p>
359
  <input type="hidden" name="secret" value="'.$this->_password.'">
360
- <input type="hidden" name="cmd" value="export">
361
  <input type="hidden" name="wid" value="1">
362
  <input type="hidden" name="sid" value="1">
363
  <input type="hidden" name="ps" value="1">
@@ -368,7 +366,7 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
368
  <p><b>With pagination & page size</b><br />';
369
  $result .= '<p>'.$apiUrlWithCustomConf.'&ps=1&pe=2&psize=50</p>
370
  <input type="hidden" name="secret" value="'.$this->_password.'">
371
- <input type="hidden" name="cmd" value="export">
372
  <input type="hidden" name="wid" value="1">
373
  <input type="hidden" name="sid" value="1">
374
  <input type="hidden" name="ps" value="1">
@@ -757,6 +755,16 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
757
  return $result;
758
  }
759
 
 
 
 
 
 
 
 
 
 
 
760
  /*
761
  Set & Set mid and secret if not set
762
  */
@@ -765,6 +773,8 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
765
  $logger = Mage::getSingleton('expertrec_recommendation/log');
766
  $feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
767
 
 
 
768
  $mid = Mage::getStoreConfig(self::MERCHANT_ID);
769
  $secret = Mage::getStoreConfig(self::CONFIG_SECRET);
770
 
@@ -802,21 +812,24 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
802
  ->setMethod(Zend_Http_Client::GET)
803
  ->setParameterGet($siteArray)
804
  ->setConfig(array('timeout' => 1));
 
805
  //response with mid and secret
806
  $response = $request->request();
807
  $data = json_decode($response->getBody(),true);
808
  $mid = $data['merchantid'];
809
  $secret = $data['secret'];
810
  //$logger->log("data ".print_r($data,1));
 
811
  // update mid and secret
812
  Mage::helper("expertrec_recommendation")
813
  ->saveConfig('secret',$data['secret'])
814
  ->saveConfig('mid',$data['merchantid'])
815
  ->clearCache();
816
 
817
- $logger->log("Generated new mid and secret");
818
- }catch (Zend_Http_Client_Exception $e) {
819
- $logger->log(sprintf($apiUrl ." failed to create mid&secret because HTTP error: %s", $e->getMessage()),Zend_Log::ERR);
 
820
  }
821
  }
822
  else{
@@ -828,165 +841,345 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
828
  $storedMid = $mid;
829
  $feedConfig->setMerchantId($storedMid);
830
 
 
 
831
  return $data;
832
 
833
  }
834
 
835
  /*
836
- Initial hit to backend with product count and secret
837
  */
838
- public function getProductCount($finalUrl,$secret){
 
839
  $logger = Mage::getSingleton('expertrec_recommendation/log');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
840
  $filter = Mage::getSingleton('expertrec_recommendation/feed_feedfilter');
841
- $array_count = array();
842
- $websiteCollection = Mage::getModel('core/website')->getCollection()->load();
843
- // $websitecount = count($websiteCollection);
844
- $websitecount = $websiteCollection->getSize();
845
- foreach ($websiteCollection as $website){
846
- $websiteId=$website->getWebsiteId();
847
-
848
- $this->_websiteId[] = $websiteId;
849
- foreach ($website->getGroups() as $group) {
850
- // all stores
851
- $stores = $group->getStores();
852
- $storeCount = count($stores);
853
- foreach ($stores as $oStore) {
854
-
855
- $storeId=$oStore->getId();
856
 
857
- $this->_storeId[] = $storeId;
858
- // get all products
859
- $collection = $filter->addBasicFilter($website,$oStore);
860
- $count = $collection->getSize();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
861
 
862
- $array[$storeCount] = array('wid' => $websiteId, 'sid' => $storeId, 'total_products' => $count);
863
- $storeCount--;
864
- }
865
- $collection->clear();
866
  }
867
- }
868
 
869
- $array_count = array('site_host' => $_SERVER['HTTP_HOST'], 'secrete' => $secret, 'product_count' => $array );
870
- $finalurl = $finalUrl.'product_count';
871
 
872
- // sending request
873
- $response = Mage::getModel('expertrec_recommendation/api_request')
874
- ->setPrepareRequestStatus(false)
875
- ->setUserId('expertrec')
876
- ->setUrl($finalurl)
877
- ->setMethod(Zend_Http_Client::GET)
878
- ->setData($array_count)
879
- ->setHeader("Content-Type",'application/json')
880
- ->setPrepareRequestStatus(true)
881
- ->sendRequest();
882
 
883
- $logger->log('UserFeedPush_Track: request with product count sent');
884
- if(!$response) {
885
- $logger->log('UserFeedPush_Track: request failed for total_count');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886
  }
 
 
 
887
  }
888
 
889
  /*
890
  Send currency details
891
  */
892
- public function getCurrency($finalUrl){
893
- $logger = Mage::getSingleton('expertrec_recommendation/log');
894
 
895
- $baseCurrency = Mage::app()->getStore()->getBaseCurrencyCode();
896
- $currCurrency = Mage::app()->getStore()->getCurrentCurrencyCode();
897
 
898
- $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
899
- $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
900
- $allCurrencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
901
 
902
- $array_currency = array(
903
- 'baseCurrency' => $baseCurrency,
904
- 'currCurrency' => $currCurrency,
905
- 'currencyRates' => $allCurrencyRates);
906
 
907
- // $logger->log("currency ".print_r($array_currency,1));
908
- $finalurl = $finalUrl.'currency';
909
 
910
- // sending request
911
- $response = Mage::getModel('expertrec_recommendation/api_request')
912
- ->setPrepareRequestStatus(false)
913
- ->setUserId('expertrec')
914
- ->setUrl($finalurl)
915
- ->setMethod(Zend_Http_Client::GET)
916
- ->setData($array_currency)
917
- ->setHeader("Content-Type",'application/json')
918
- ->setPrepareRequestStatus(true)
919
- ->sendRequest();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
920
 
921
- $logger->log('UserFeedPush_Track: request with currency details sent');
922
- if(!$response) {
923
- $logger->log('UserFeedPush_Track: request failed for total_count');
 
924
  }
 
 
 
925
  }
926
 
927
  /*
928
  Get all categories
929
  */
930
- public function getCategories($finalUrl){
931
- $logger = Mage::getSingleton('expertrec_recommendation/log');
932
 
933
- $category = Mage::getModel('catalog/category');
934
- $tree = $category->getTreeModel();
935
- $tree->load();
936
- $ids = $tree->getCollection()->getAllIds();
937
- if ($ids){
938
- for($i=0;$i<count($ids);$i++){
939
- $id = $ids[$i];
940
- $cat = Mage::getModel('catalog/category');
941
- $cat->load($id);
942
-
943
- $entity_id = $cat->getId();
944
- $name = $cat->getName();
945
- $url_key = $cat->getUrlKey();
946
- $url_path = $cat->getUrlPath();
947
- $catarr['cat_id'] = $entity_id;
948
- $catarr['cat_name'] = $name;
949
-
950
- $pathIdArray = explode('/', $cat->getPath());
951
- $pathNameArray = array();
952
- for($j=0;$j<count($pathIdArray);$j++){
953
- $categoryy=Mage::getModel('catalog/category')->load($pathIdArray[$j]);
954
- $pathNameArray[$j] = $categoryy->getName();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
955
  }
956
- $category_id_path = implode(chr(3), $pathIdArray);
957
- $catarr['cat_id_path'] = $category_id_path;
958
- $category_path = implode(chr(3), $pathNameArray);
959
- $catarr['cat_name_path'] = $category_path;
960
-
961
- $categoryArray[$i]=$catarr;
962
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963
  }
964
- // $logger->log("categories : ".print_r($categoryArray,1));
965
- $finalurl = $finalUrl.'all-category';
966
 
967
- // sending request
968
- $response = Mage::getModel('expertrec_recommendation/api_request')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969
  ->setPrepareRequestStatus(false)
970
  ->setUserId('expertrec')
971
  ->setUrl($finalurl)
972
- ->setMethod(Zend_Http_Client::GET)
973
- ->setData($categoryArray)
974
  ->setHeader("Content-Type",'application/json')
975
  ->setPrepareRequestStatus(true)
976
  ->sendRequest();
977
 
978
- $logger->log('UserFeedPush_Track: request with category details sent');
979
- if(!$response) {
980
- $logger->log('UserFeedPush_Track: request failed for total_count');
 
 
 
 
 
981
  }
 
 
 
982
  }
983
 
984
  /*
985
  Push feed per product
986
  */
987
- public function pushFeedAction(){
988
- $logger = Mage::getSingleton('expertrec_recommendation/log');
989
 
 
 
990
  // update db to 1 once feed pushed
991
  Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_push','1');
992
 
@@ -997,187 +1190,278 @@ class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_
997
 
998
  // set&get mid and secret if mid is new_user
999
  $data = $this->getMidSecret();
 
1000
  $mid = $data['merchantid'];
1001
  $secret = $data['secret'];
1002
 
 
 
 
 
 
 
 
 
1003
  // feedUrl as api to userpushfeed
1004
  $feedUrl = "https://feed.expertrec.com/magento/n01eba6261ad7f174cd3a16523e86e65/";
 
1005
  // finalurl added with merchant id
1006
  $finalUrl = $feedUrl.''.$mid.'/';
1007
 
1008
- // check for feed pushed
1009
- $feed_pushed_page_info = Mage::getStoreConfig(self::PUSHED_FEED_PAGES);
1010
- $feed_pushed_page_info_array = explode(',', $feed_pushed_page_info);
1011
- $website_Id_pushed = $feed_pushed_page_info_array[0];
1012
- $store_Id_pushed = $feed_pushed_page_info_array[1];
1013
- $pages_pushed = $feed_pushed_page_info_array[2];
1014
 
1015
  // calculate number of products and send
1016
- $this->getProductCount($finalUrl,$secret);
1017
 
1018
- if($website_Id_pushed == 0){
1019
- // collect currencies
1020
- $this->getCurrency($finalUrl);
1021
- $this->getCategories($finalUrl);
1022
- }
1023
 
1024
- $filter = Mage::getSingleton('expertrec_recommendation/feed_feedfilter');
1025
- $formatter = Mage::getSingleton('expertrec_recommendation/feed_formatter')
1026
- ->init();
1027
- $feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
1028
- // get headers
1029
- $storedHeaders = Mage::getStoreConfig(self::CONFIG_HEADERS);
1030
- $finalurl = $finalUrl.'product';
1031
 
1032
- if (isset($storedHeaders)){
1033
- $header = explode(',', $storedHeaders);
1034
- }
1035
- else{
1036
- $header = array();
1037
- }
1038
- if(!empty($header)){
1039
 
1040
- foreach ($this->_websiteId as $websiteId){
1041
 
1042
- if($websiteId < $website_Id_pushed){
1043
- continue;
1044
- }
1045
- else{
1046
- foreach ($this->_storeId as $storeId) {
1047
- if($websiteId <= $website_Id_pushed && $storeId < $store_Id_pushed){
1048
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1049
  }
1050
  else{
1051
- $website = Mage::getModel('core/website')->load($websiteId);
1052
- $oStore = Mage::app()->getStore($StoreId);
1053
- $collection=$filter->addBasicFilter($website,$oStore)
1054
- ->setPageSize($feedConfig->pageSize);
1055
-
1056
- $pageEnd = $feedConfig->pageEnd;
1057
- $lastPageNumber = $collection->getLastPageNumber();
1058
- if($pageEnd != 0 && $pageEnd < $lastPageNumber){
1059
- $pages = $pageEnd;
 
 
 
1060
  }
1061
  else{
1062
- $pages = $lastPageNumber;
1063
- }
1064
- $logger->log("Total no. of pages for which we are collecting feed in this reqeust: #".$pages." for store #".$storeId);
1065
- for($currentPage = $feedConfig->pageStart; $currentPage <= $pages; $currentPage++) {
1066
- if($websiteId <= $website_Id_pushed && $storeId <= $store_Id_pushed && $currentPage < $pages_pushed){
1067
- continue;
1068
- }
1069
- else{
1070
- $logger->log("Collecting feed for page: #".$currentPage);
1071
- $collection->setCurPage($currentPage);
1072
- // get all products
1073
- foreach ($collection as $product) {
1074
- try{
1075
- $resultArray = $formatter->prepareRow($header,$product);
1076
- $resultArray['storeId'] = $storeId;
1077
- $resultArray['websiteId'] = $websiteId;
1078
- // sending request
1079
- $response = Mage::getModel('expertrec_recommendation/api_request')
1080
- ->setPrepareRequestStatus(false)
1081
- ->setUserId('expertrec')
1082
- ->setUrl($finalurl)
1083
- ->setMethod(Zend_Http_Client::POST)
1084
- ->setData($resultArray)
1085
- ->setHeader("Content-Type",'application/json')
1086
- ->setPrepareRequestStatus(true)
1087
- ->sendRequest();
1088
- // $logger->log('UserFeedPush_Track: request succeded for product with Id #'.$product->getId().' of store '.$storeId);
1089
- if(!$response) {
1090
- $logger->log('UserFeedPush_Track: request failed for product with Id #'.$product->getId());
1091
- }
1092
- $page = $websiteId.','.$storeId.','.$currentPage;
1093
- Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1094
- }
1095
- catch (Exception $e) {
1096
- $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1097
  }
1098
- } // if page is not pushed
1099
- } // foreach collection
1100
- $collection->clear();
1101
- } // for current page
1102
- } // if store is not pushed
1103
- } // for each store
1104
- } // if website is not pushed
1105
- } // for each websites
1106
- $websitecount--;
1107
- $page = '0,0,0';
1108
- Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1109
- } // if not empty headers
1110
- // check for feed completion
1111
- if($websitecount == 0){
1112
- $array = array('completed' => 1, );
1113
- $response = Mage::getModel('expertrec_recommendation/api_request')
1114
- ->setPrepareRequestStatus(false)
1115
- ->setUserId('expertrec')
1116
- ->setUrl($finalUrl)
1117
- ->setMethod(Zend_Http_Client::GET)
1118
- ->setData($array)
1119
- ->setHeader("Content-Type",'application/json')
1120
- ->setPrepareRequestStatus(true)
1121
- ->sendRequest();
1122
- $logger->log('UserFeedPush_Track: request completed');
1123
- if(!$response) {
1124
- $logger->log('UserFeedPush_Track: Request not complete');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1125
  }
 
 
 
1126
  }
 
 
 
 
 
1127
  $logger->logMemoryUsage();
 
1128
  }
1129
 
1130
  /*
1131
- upload feed by user
1132
  */
1133
- public function feedAction(){
1134
-
1135
- Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
1136
- Mage::app()->getResponse()->sendResponse();
1137
 
1138
  ob_end_clean();
1139
  //avoid apache to kill the php running
1140
  ignore_user_abort(true);
1141
  ob_start();//start buffer output
 
 
1142
  //close session file on server side to avoid blocking other requests
1143
  session_write_close();
 
1144
  //send header to avoid the browser side to take content as gzip format
1145
  header("Content-Encoding: none");
1146
  header("Content-Length: ".ob_get_length());
1147
  header("Connection: close");
1148
  ob_end_flush();
1149
  flush();
1150
- $this->pushFeedAction();
 
 
 
 
 
 
 
 
 
 
 
 
 
1151
  }
1152
 
1153
  /*
1154
  pull feed from info page
1155
  */
1156
  public function pullFeedAction(){
 
1157
  $logger = Mage::getSingleton('expertrec_recommendation/log');
 
1158
  try{
1159
 
1160
- ob_end_clean();
1161
- //avoid apache to kill the php running
1162
- ignore_user_abort(true);
1163
- ob_start();//start buffer output
1164
- $logger->log("Pull Feed started in background.");
1165
- echo "Pull Feed started in background.";
1166
- //close session file on server side to avoid blocking other requests
1167
- session_write_close();
1168
- //send header to avoid the browser side to take content as gzip format
1169
- header("Content-Encoding: none");
1170
- header("Content-Length: ".ob_get_length());
1171
- header("Connection: close");
1172
- ob_end_flush();
1173
- flush();
1174
-
1175
- $this->pushFeedAction();
1176
- die("Feed pulled successfully.");
1177
 
1178
  }catch (Exception $e) {
1179
- $logger->log( "Not able to pull the feed: ".$e->getMessage());
1180
- $logger->log('callstack on error in pull feed : '.mageDebugBacktrace(true, true, true));
 
1181
  }
1182
  }
1183
 
17
  const SEARCH_CUSTOM_TEMPLATE = 'search/custom_template';
18
  const FEED_LOG_ENDPOINT = 'expertrec/general/log_endpoint';
19
  const FEED_UPLOAD_ENDPOINT = 'expertrec/general/upload_endpoint';
20
+ const IS_UPLOAD_FEED = 'is_upload';
21
  const IMAGE_WIDTH = 'expertrec/general/expertrec_image_width';
22
  const IMAGE_HEIGHT = 'expertrec/general/expertrec_image_height';
23
  const THUMBNAIL_WIDTH = 'expertrec/general/expertrec_thumbnail_width';
26
  const CONFIG_SECRET = 'expertrec/general/secret';
27
  const PUSHED_FEED_PAGES = 'expertrec/general/expertrec_feed_pushed_pages';
28
 
29
+ const BUILD_NO = "1494410700";
30
+ const EXPERTREC_VERSION = "1.2.14";
 
31
  private $_password;
 
32
  private $_storeId = array();
33
 
34
  //main function which loads the feed API
346
  <p><b>Without pagination</b><br />';
347
  $result .= '<p>'.$apiUrlWithCustomConf.'</p>
348
  <input type="hidden" name="secret" value="'.$this->_password.'">
349
+ <input type="hidden" name="cmd" value="getpp">
350
  <input type="hidden" name="wid" value="1">
351
  <input type="hidden" name="sid" value="1">
352
  <button type="submit" name="sug1submit" id="sug1submit">Submit</button></form>';
355
  <p><b>With pagination without page size(default page size is 500)</b><br />';
356
  $result .= '<p>'.$apiUrlWithCustomConf.'&ps=1&pe=2</p>
357
  <input type="hidden" name="secret" value="'.$this->_password.'">
358
+ <input type="hidden" name="cmd" value="getpp">
359
  <input type="hidden" name="wid" value="1">
360
  <input type="hidden" name="sid" value="1">
361
  <input type="hidden" name="ps" value="1">
366
  <p><b>With pagination & page size</b><br />';
367
  $result .= '<p>'.$apiUrlWithCustomConf.'&ps=1&pe=2&psize=50</p>
368
  <input type="hidden" name="secret" value="'.$this->_password.'">
369
+ <input type="hidden" name="cmd" value="getpp">
370
  <input type="hidden" name="wid" value="1">
371
  <input type="hidden" name="sid" value="1">
372
  <input type="hidden" name="ps" value="1">
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
+
768
  /*
769
  Set & Set mid and secret if not set
770
  */
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);
780
 
812
  ->setMethod(Zend_Http_Client::GET)
813
  ->setParameterGet($siteArray)
814
  ->setConfig(array('timeout' => 1));
815
+
816
  //response with mid and secret
817
  $response = $request->request();
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
  $storedMid = $mid;
842
  $feedConfig->setMerchantId($storedMid);
843
 
844
+ $logger->log(" Fetched mid ans secret ");
845
+
846
  return $data;
847
 
848
  }
849
 
850
  /*
851
+ Get debug info
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
+
861
+ try{
862
+ // send request
863
+ $request = new Zend_Http_Client();
864
+ $request->setUri($finalUrl)
865
+ ->setHeaders("Content-Type",'application/json')
866
+ ->setMethod(Zend_Http_Client::GET)
867
+ ->setConfig(array('timeout' => 1));
868
+
869
+ //response with mid and secret
870
+ $response = $request->request();
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);
888
+
889
+ return $debug;
890
+
891
+ }
892
+
893
+ /*
894
+ Initial hit to backend with product count and secret
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
+
907
+ $allStores = Mage::app()->getStores();
908
+ foreach ($allStores as $store){
909
+
910
+ $storeId = $store->getId();
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
+
918
+ // get all products
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);
962
+
963
  }
964
 
965
  /*
966
  Send currency details
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);
1020
+
1021
  }
1022
 
1023
  /*
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
+
1046
+ $id = $ids[$i];
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();
1054
+ $url_key = $cat->getUrlKey();
1055
+ $url_path = $cat->getUrlPath();
1056
+ $catarr['cat_id'] = $entity_id;
1057
+ $catarr['cat_name'] = $name;
1058
+
1059
+ $pathIdArray = explode('/', $cat->getPath());
1060
+ $pathNameArray = array();
1061
+
1062
+ for($j=0;$j<count($pathIdArray);$j++){
1063
+
1064
+ $categoryy=Mage::getModel('catalog/category')->load($pathIdArray[$j]);
1065
+ $pathNameArray[$j] = $categoryy->getName();
1066
+ }
1067
+
1068
+ $category_id_path = implode(chr(3), $pathIdArray);
1069
+ $catarr['cat_id_path'] = $category_id_path;
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::GET)
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);
1105
+
1106
+ }
1107
+
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');
1185
 
1190
 
1191
  // set&get mid and secret if mid is new_user
1192
  $data = $this->getMidSecret();
1193
+
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/";
1207
+
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);
1217
 
1218
+ try{
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
+ $this->printLog('getFeedData : Calling get all-categories ','',$debug);
1238
+
1239
+ // collect all catagories
1240
+ $this->getCategories($finalUrl,$debug);
1241
+ }
1242
+
1243
+ $filter = Mage::getSingleton('expertrec_recommendation/feed_feedfilter');
1244
+ $formatter = Mage::getSingleton('expertrec_recommendation/feed_formatter')
1245
+ ->init();
1246
+ $feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
1247
+
1248
+ // get headers
1249
+ $storedHeaders = Mage::getStoreConfig(self::CONFIG_HEADERS);
1250
+
1251
+ if (isset($storedHeaders)){
1252
+ $header = explode(',', $storedHeaders);
1253
+
1254
+ $this->printLog('getFeedData : Collect headers ','',$debug);
1255
+ }
1256
+ else{
1257
+ $header = array();
1258
+ }
1259
+
1260
+ $finalurl = $finalUrl.'product';
1261
+
1262
+ $this->printLog('getFeedData : Added product to endpoint as ',$finalurl,$debug);
1263
+
1264
+ if(!empty($header)){
1265
+
1266
+ $stores = count($this->_storeId);
1267
+
1268
+ $this->printLog('getFeedData : Headers are not empty & get no.of stores as ',$stores,$debug);
1269
+
1270
+ foreach ($this->_storeId as $storeId) {
1271
+
1272
+ $this->printLog('getFeedData : Collecting store info of store_id # ',$storeId,$debug);
1273
+
1274
+ if($storeId < $store_Id_pushed){
1275
+
1276
+ $this->printLog('getFeedData : In order to resume from last pull, skip store_id as it pulled # ',$storeId,$debug);
1277
+
1278
+ continue;
1279
+ }
1280
+ else{
1281
+ $oStore = Mage::app()->getStore($storeId);
1282
+ $websiteId = $oStore->getWebsiteId();
1283
+ $website = Mage::app()->getWebsite($websiteId);
1284
+
1285
+ $this->printLog('getFeedData : Get store and website info for store # ',$storeId,$debug);
1286
+
1287
+ $collection=$filter->addBasicFilter($website,$oStore)
1288
+ ->setPageSize($feedConfig->pageSize);
1289
+
1290
+ $this->printLog('getFeedData : Get product collection ','',$debug);
1291
+
1292
+ $pageEnd = $feedConfig->pageEnd;
1293
+ $lastPageNumber = $collection->getLastPageNumber();
1294
+ if($pageEnd != 0 && $pageEnd < $lastPageNumber){
1295
+ $pages = $pageEnd;
1296
  }
1297
  else{
1298
+ $pages = $lastPageNumber;
1299
+ }
1300
+
1301
+ $this->printLog('getFeedData : Total no. of pages with products in this store is ',$pages,$debug);
1302
+
1303
+ // $logger->log("Total no. of pages for which we are collecting feed in this reqeust: #".$pages." for store #".$storeId);
1304
+ for($currentPage = $feedConfig->pageStart; $currentPage <= $pages; $currentPage++) {
1305
+ if($storeId <= $store_Id_pushed && $currentPage < $pages_pushed){
1306
+
1307
+ $this->printLog('getFeedData : In order to resume from last pull, skip page as it pulled ',$currentPage,$debug);
1308
+
1309
+ continue;
1310
  }
1311
  else{
1312
+
1313
+ $this->printLog('getFeedData : Collecting products for page ',$currentPage,$debug);
1314
+
1315
+ // $logger->log("Collecting feed for page: #".$currentPage);
1316
+ $collection->setCurPage($currentPage);
1317
+ // get all products
1318
+ foreach ($collection as $product) {
1319
+ try{
1320
+
1321
+ $this->printLog('getFeedData : Collecting info of product_id # ',$product->getId(),$debug);
1322
+
1323
+ $resultArray = $formatter->prepareRow($header,$product);
1324
+ $resultArray['storeId'] = $storeId;
1325
+ $resultArray['websiteId'] = $websiteId;
1326
+ // $logger->log("res ".print_r($resultArray,1));
1327
+
1328
+ $this->printLog('getFeedData : Send request to endpoint as',$finalurl,$debug);
1329
+
1330
+ // sending request
1331
+ $response = Mage::getModel('expertrec_recommendation/api_request')
1332
+ ->setPrepareRequestStatus(false)
1333
+ ->setUserId('expertrec')
1334
+ ->setUrl($finalurl)
1335
+ ->setMethod(Zend_Http_Client::POST)
1336
+ ->setData($resultArray)
1337
+ ->setHeader("Content-Type",'application/json')
1338
+ ->setPrepareRequestStatus(true)
1339
+ ->sendRequest();
1340
+ // $logger->log('UserFeedPush_Track: request succeded for product with Id #'.$product->getId().' of store '.$storeId);
1341
+ if(!$response) {
1342
+
1343
+ // $logger->log('UserFeedPush_Track: request failed for product with Id #'.$product->getId());
1344
+ $this->printLog('getFeedData : Request failed for product with Id #',$product->getId(),$debug);
 
 
1345
  }
1346
+ $page = $storeId.','.$currentPage;
1347
+
1348
+ $this->printLog('getFeedData : Updating, sent pages and store info in db as ',$page,$debug);
1349
+
1350
+ Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1351
+ }
1352
+ catch (Exception $e) {
1353
+
1354
+ // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1355
+ $this->printLog('getFeedData : Exception on collecting Product info ',$e->getMessage(),$debug);
1356
+ }
1357
+ } // if page is not pushed
1358
+ } // foreach collection
1359
+ $collection->clear();
1360
+ } // for current page
1361
+ } // if store is not pushed
1362
+ $stores--;
1363
+
1364
+ $this->printLog('getFeedData : Reduce store count to keep track of no.of stores pushed as ',$stores,$debug);
1365
+ } // for each store
1366
+ $page = '0,0';
1367
+
1368
+ $this->printLog('getFeedData : Once all stores with pages pushed, update pushed_feed in db as',$page,$debug);
1369
+
1370
+ Mage::helper("expertrec_recommendation")->saveConfig('expertrec_feed_pushed_pages',$page);
1371
+ } // if not empty headers
1372
+ // check for feed completion
1373
+ if($stores == 0){
1374
+
1375
+ $this->printLog('getFeedData : After completing product push, stores remainig are ',$stores,$debug);
1376
+
1377
+ $array = array('completed' => 1, );
1378
+
1379
+ $this->printLog('getFeedData : Send completed request to endpoint ','',$debug);
1380
+
1381
+ $response = Mage::getModel('expertrec_recommendation/api_request')
1382
+ ->setPrepareRequestStatus(false)
1383
+ ->setUserId('expertrec')
1384
+ ->setUrl($finalUrl)
1385
+ ->setMethod(Zend_Http_Client::GET)
1386
+ ->setData($array)
1387
+ ->setHeader("Content-Type",'application/json')
1388
+ ->setPrepareRequestStatus(true)
1389
+ ->sendRequest();
1390
+ // $logger->log('UserFeedPush_Track: request completed');
1391
+ if(!$response) {
1392
+ // $logger->log('UserFeedPush_Track: Request not complete');
1393
+ $this->printLog('getFeedData : Request failed for completed info ','',$debug);
1394
+ }
1395
  }
1396
+ }catch (Exception $e) {
1397
+ // $logger->log("UserFeedPush_Track error: ".$e->getMessage());
1398
+ $this->printLog('getFeedData : Exception on sending completed info ',$e->getMessage(),$debug);
1399
  }
1400
+
1401
+ $this->printLog('getFeedData : Calling getPopularQuerries','',$debug);
1402
+
1403
+ $this->getPopularQuerries($finalUrl,$debug);
1404
+
1405
  $logger->logMemoryUsage();
1406
+
1407
  }
1408
 
1409
  /*
1410
+ Background process
1411
  */
1412
+ public function bgProcess(){
1413
+
1414
+ $logger = Mage::getSingleton('expertrec_recommendation/log');
1415
+ $logger->log(" Background process for pull-feed started ");
1416
 
1417
  ob_end_clean();
1418
  //avoid apache to kill the php running
1419
  ignore_user_abort(true);
1420
  ob_start();//start buffer output
1421
+
1422
+ echo "pull feed started in background";
1423
  //close session file on server side to avoid blocking other requests
1424
  session_write_close();
1425
+
1426
  //send header to avoid the browser side to take content as gzip format
1427
  header("Content-Encoding: none");
1428
  header("Content-Length: ".ob_get_length());
1429
  header("Connection: close");
1430
  ob_end_flush();
1431
  flush();
1432
+
1433
+ $this->getFeedData();
1434
+
1435
+ }
1436
+
1437
+ /*
1438
+ upload feed by user
1439
+ */
1440
+ public function feedAction(){
1441
+
1442
+ Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
1443
+ Mage::app()->getResponse()->sendResponse();
1444
+
1445
+ $this->bgProcess();
1446
  }
1447
 
1448
  /*
1449
  pull feed from info page
1450
  */
1451
  public function pullFeedAction(){
1452
+
1453
  $logger = Mage::getSingleton('expertrec_recommendation/log');
1454
+
1455
  try{
1456
 
1457
+ $logger->log(" Pull Feed started in background ");
1458
+ // background process
1459
+ $this->bgProcess();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1460
 
1461
  }catch (Exception $e) {
1462
+
1463
+ $logger->log(" Not able to pull the feed : ".$e->getMessage());
1464
+ $logger->log(' Backtrace in pull feed : '.mageDebugBacktrace(true, true, true));
1465
  }
1466
  }
1467
 
app/code/community/Expertrec/Recommendation/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Expertrec_Recommendation>
5
- <version>1.2.13</version>
6
  </Expertrec_Recommendation>
7
  </modules>
8
  <global>
@@ -106,11 +106,11 @@
106
  </sales_order_payment_place_end>
107
  <cataloginventory_stock_item_save_after>
108
  <observers>
109
- <expertrec_recommendation_save_category>
110
  <type>singleton</type>
111
  <class>expertrec_recommendation/observer</class>
112
  <method>outOfStockReport</method>
113
- </expertrec_recommendation_save_category>
114
  </observers>
115
  </cataloginventory_stock_item_save_after>
116
  </events>
2
  <config>
3
  <modules>
4
  <Expertrec_Recommendation>
5
+ <version>1.2.14</version>
6
  </Expertrec_Recommendation>
7
  </modules>
8
  <global>
106
  </sales_order_payment_place_end>
107
  <cataloginventory_stock_item_save_after>
108
  <observers>
109
+ <expertrec_recommendation_save_stock>
110
  <type>singleton</type>
111
  <class>expertrec_recommendation/observer</class>
112
  <method>outOfStockReport</method>
113
+ </expertrec_recommendation_save_stock>
114
  </observers>
115
  </cataloginventory_stock_item_save_after>
116
  </events>
app/code/community/Expertrec/Recommendation/sql/expertrec_setup/{mysql4-install-1.2.13.php → mysql4-install-1.2.14.php} RENAMED
@@ -8,11 +8,13 @@
8
  */
9
 
10
  $installer = $this;
 
11
  $mage_ver = Mage::getVersion();
12
  $php_ver = phpversion();
13
- $expertrec_version = "1.2.13";
14
 
15
  $installer->startSetup();
 
16
  $result =array();
17
 
18
  $result['status'] = "Installed";
@@ -41,12 +43,15 @@
41
  $result['admin_email'] = $admin_data[0]['email'];
42
 
43
  $postData = '';
 
44
  foreach($result as $key => $value) {
45
  $postData .= $key . '='.$value.'&';
46
  }
 
47
  $postData = rtrim($postData, '&');
48
 
49
  $url = "https://feed.expertrec.com/magento-install/77c3b75abd2842e93b8c52c4aiu8y";
 
50
  $curl = curl_init();
51
  curl_setopt($curl, CURLOPT_URL, $url);
52
  curl_setopt($curl, CURLOPT_POST, 1);
@@ -67,9 +72,11 @@
67
  ('default',0,'expertrec/general/expertrec_thumbnail_width',80),
68
  ('default',0,'expertrec/general/expertrec_thumbnail_height',80),
69
  ('default',0,'expertrec/general/expertrec_feed_push',0),
70
- ('default',0,'expertrec/general/expertrec_feed_pushed_pages','0,0,0'),
 
71
  ('default',0,'expertrec/general/filters','filter_by_stock,filter_by_status')
72
  ON DUPLICATE KEY UPDATE `value`=`value`;
73
  ");
 
74
  $installer->endSetup();
75
  ?>
8
  */
9
 
10
  $installer = $this;
11
+
12
  $mage_ver = Mage::getVersion();
13
  $php_ver = phpversion();
14
+ $expertrec_version = "1.2.14";
15
 
16
  $installer->startSetup();
17
+
18
  $result =array();
19
 
20
  $result['status'] = "Installed";
43
  $result['admin_email'] = $admin_data[0]['email'];
44
 
45
  $postData = '';
46
+
47
  foreach($result as $key => $value) {
48
  $postData .= $key . '='.$value.'&';
49
  }
50
+
51
  $postData = rtrim($postData, '&');
52
 
53
  $url = "https://feed.expertrec.com/magento-install/77c3b75abd2842e93b8c52c4aiu8y";
54
+
55
  $curl = curl_init();
56
  curl_setopt($curl, CURLOPT_URL, $url);
57
  curl_setopt($curl, CURLOPT_POST, 1);
72
  ('default',0,'expertrec/general/expertrec_thumbnail_width',80),
73
  ('default',0,'expertrec/general/expertrec_thumbnail_height',80),
74
  ('default',0,'expertrec/general/expertrec_feed_push',0),
75
+ ('default',0,'expertrec/general/expertrec_feed_pushed_pages','0,0'),
76
+ ('default',0,'expertrec/general/debug','1'),
77
  ('default',0,'expertrec/general/filters','filter_by_stock,filter_by_status')
78
  ON DUPLICATE KEY UPDATE `value`=`value`;
79
  ");
80
+
81
  $installer->endSetup();
82
  ?>
app/code/community/Expertrec/Recommendation/sql/expertrec_setup/{mysql4-upgrade-1.2.12-1.2.13.php → mysql4-upgrade-1.2.13-1.2.14.php} RENAMED
@@ -8,11 +8,13 @@
8
  */
9
 
10
  $installer = $this;
 
11
  $mage_ver = Mage::getVersion();
12
  $php_ver = phpversion();
13
- $expertrec_version = "1.2.13";
14
 
15
  $installer->startSetup();
 
16
  $result =array();
17
 
18
  $result['status'] = "Upgraded";
@@ -41,12 +43,15 @@
41
  $result['admin_email'] = $admin_data[0]['email'];
42
 
43
  $postData = '';
 
44
  foreach($result as $key => $value) {
45
  $postData .= $key . '='.$value.'&';
46
  }
 
47
  $postData = rtrim($postData, '&');
48
 
49
  $url = "https://feed.expertrec.com/magento-install/77c3b75abd2842e93b8c52c4aiu8y";
 
50
  $curl = curl_init();
51
  curl_setopt($curl, CURLOPT_URL, $url);
52
  curl_setopt($curl, CURLOPT_POST, 1);
@@ -57,8 +62,25 @@
57
  curl_close($curl);
58
 
59
  $installer->run("
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  UPDATE {$this->getTable('core_config_data')} SET `value`=0 WHERE `path`='expertrec/general/expertrec_feed_push';
61
  UPDATE {$this->getTable('core_config_data')} SET `value`='qty,is_in_stock,expert_image,expert_thumbnail,expert_category,expert_category_ids,final_price,entity_id,rating_summary,expert_url,created_at,image,msrp,name,price,short_description,sku,small_image,special_price,category_ids,minimal_price,status,visibility' WHERE `path`='expertrec/general/headers';
 
62
  ");
 
63
  $installer->endSetup();
64
  ?>
8
  */
9
 
10
  $installer = $this;
11
+
12
  $mage_ver = Mage::getVersion();
13
  $php_ver = phpversion();
14
+ $expertrec_version = "1.2.14";
15
 
16
  $installer->startSetup();
17
+
18
  $result =array();
19
 
20
  $result['status'] = "Upgraded";
43
  $result['admin_email'] = $admin_data[0]['email'];
44
 
45
  $postData = '';
46
+
47
  foreach($result as $key => $value) {
48
  $postData .= $key . '='.$value.'&';
49
  }
50
+
51
  $postData = rtrim($postData, '&');
52
 
53
  $url = "https://feed.expertrec.com/magento-install/77c3b75abd2842e93b8c52c4aiu8y";
54
+
55
  $curl = curl_init();
56
  curl_setopt($curl, CURLOPT_URL, $url);
57
  curl_setopt($curl, CURLOPT_POST, 1);
62
  curl_close($curl);
63
 
64
  $installer->run("
65
+ INSERT INTO {$this->getTable('core_config_data')} (`scope`, `scope_id`, `path`, `value`)
66
+ VALUES ('default',0,'expertrec/general/mid','new_user'),
67
+ ('default',0,'expertrec/general/secret','NTE5NTQ1Zjk4OGExYzYxOWFkOTkyN2Y3MDQ5MTQ3NTM='),
68
+ ('default',0,'expertrec/general/log_endpoint','https://feed.expertrec.com/magento/9418bba77c3b75abd2842e93b8c52c4a'),
69
+ ('default',0,'expertrec/general/headers','qty,is_in_stock,expert_image,expert_thumbnail,expert_category,expert_category_ids,final_price,entity_id,rating_summary,expert_url,created_at,image,msrp,name,price,short_description,sku,small_image,special_price,category_ids,minimal_price,status,visibility'),
70
+ ('default',0,'expertrec/general/expertrec_image_width',250),
71
+ ('default',0,'expertrec/general/expertrec_image_height',250),
72
+ ('default',0,'expertrec/general/expertrec_thumbnail_width',80),
73
+ ('default',0,'expertrec/general/expertrec_thumbnail_height',80),
74
+ ('default',0,'expertrec/general/expertrec_feed_push',0),
75
+ ('default',0,'expertrec/general/expertrec_feed_pushed_pages','0,0'),
76
+ ('default',0,'expertrec/general/debug','1'),
77
+ ('default',0,'expertrec/general/filters','filter_by_stock,filter_by_status')
78
+ ON DUPLICATE KEY UPDATE `value`=`value`;
79
+
80
  UPDATE {$this->getTable('core_config_data')} SET `value`=0 WHERE `path`='expertrec/general/expertrec_feed_push';
81
  UPDATE {$this->getTable('core_config_data')} SET `value`='qty,is_in_stock,expert_image,expert_thumbnail,expert_category,expert_category_ids,final_price,entity_id,rating_summary,expert_url,created_at,image,msrp,name,price,short_description,sku,small_image,special_price,category_ids,minimal_price,status,visibility' WHERE `path`='expertrec/general/headers';
82
+ UPDATE {$this->getTable('core_config_data')} SET `value`='0,0' WHERE `path`='expertrec/general/expertrec_feed_pushed_pages';
83
  ");
84
+
85
  $installer->endSetup();
86
  ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Expertrec_Recommendation</name>
4
- <version>1.2.13</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-04-28</date>
14
- <time>08:00:53</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="7e6ab2205528a4073273d80b9c413995"/><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="886c36c2de0c4e07e0c4db8ae69685ed"/></dir><dir name="sql"><dir name="expertrec_setup"><file name="mysql4-install-1.2.13.php" hash="25a4df0c750d2ef2f4c0c362085b9773"/><file name="mysql4-upgrade-1.2.12-1.2.13.php" hash="c8dd5c598a8bb4e7a9d40c433fd3deee"/></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.14</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-10</date>
14
+ <time>10:29:39</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="bf3e7e084373e4c52783b4685449eb95"/><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="37c5c53bdacb25a4baf30937b224cc75"/></dir><dir name="sql"><dir name="expertrec_setup"><file name="mysql4-install-1.2.14.php" hash="c85870dff378fe198d1867061ebcd05d"/><file name="mysql4-upgrade-1.2.13-1.2.14.php" hash="339fe01edc4459f28a6b55945a0a77a9"/></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>