Brainsins_Recommender - Version 1.5.6

Version Notes

Now recommendations can be retrieved using an ajax call

Download this release

Release Info

Developer Magento Core Team
Extension Brainsins_Recommender
Version 1.5.6
Comparing to
See all releases


Code changes from version 1.5.5 to 1.5.6

Files changed (28) hide show
  1. app/code/community/Brainsins/.DS_Store +0 -0
  2. app/code/community/Brainsins/Recsins/.DS_Store +0 -0
  3. app/code/community/Brainsins/Recsins/Block/.DS_Store +0 -0
  4. app/code/community/Brainsins/Recsins/Block/Adminhtml/.DS_Store +0 -0
  5. app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/.DS_Store +0 -0
  6. app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/Edit/.DS_Store +0 -0
  7. app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/Edit/Form.php +17 -0
  8. app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/Edit/Tab/.DS_Store +0 -0
  9. app/code/community/Brainsins/Recsins/Block/Recsins.php +178 -40
  10. app/code/community/Brainsins/Recsins/Entity/.DS_Store +0 -0
  11. app/code/community/Brainsins/Recsins/Helper/.DS_Store +0 -0
  12. app/code/community/Brainsins/Recsins/Model/.DS_Store +0 -0
  13. app/code/community/Brainsins/Recsins/Model/Api/.DS_Store +0 -0
  14. app/code/community/Brainsins/Recsins/Model/Api/Api.php +42 -26
  15. app/code/community/Brainsins/Recsins/Model/Api/ficheros/.DS_Store +0 -0
  16. app/code/community/Brainsins/Recsins/Model/Mysql4/.DS_Store +0 -0
  17. app/code/community/Brainsins/Recsins/Model/Recsins.php +601 -562
  18. app/code/community/Brainsins/Recsins/Model/Recsins_1.php +0 -569
  19. app/code/community/Brainsins/Recsins/controllers/.DS_Store +0 -0
  20. app/code/community/Brainsins/Recsins/controllers/Adminhtml/.DS_Store +0 -0
  21. app/code/community/Brainsins/Recsins/controllers/Adminhtml/RecsinsController.php +11 -1
  22. app/code/community/Brainsins/Recsins/controllers/IndexController.php +76 -0
  23. app/code/community/Brainsins/Recsins/etc/.DS_Store +0 -0
  24. app/code/community/Brainsins/Recsins/etc/config.xml +1 -1
  25. app/code/community/Brainsins/Recsins/sql/.DS_Store +0 -0
  26. app/code/community/Brainsins/Recsins/sql/recsins_setup/.DS_Store +0 -0
  27. app/code/community/Brainsins/Recsins/sql/recsins_setup/mysql4-upgrade-1.5.5-1.5.6.php +47 -0
  28. package.xml +5 -5
app/code/community/Brainsins/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Block/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Block/Adminhtml/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/Edit/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/Edit/Form.php CHANGED
@@ -555,6 +555,21 @@ class Brainsins_Recsins_Block_Adminhtml_Recsins_Edit_Form extends Mage_Adminhtml
555
  }
556
  $useHighDetailLabel = new Varien_Data_Form_Element_Label(array('value' => $helper->__("Use high detail in recommendation requests"), 'bold' => 'true'));
557
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
 
559
  //$advancedFieldSet->addElement($advancedRadios);
560
  $advancedFieldSet->addElement($includeOutOfStockLabel);
@@ -573,6 +588,8 @@ class Brainsins_Recsins_Block_Adminhtml_Recsins_Edit_Form extends Mage_Adminhtml
573
  $advancedFieldSet->addElement($importScriptHttps);
574
  $advancedFieldSet->addElement($useHighDetailLabel);
575
  $advancedFieldSet->addElement($useHighDetail);
 
 
576
 
577
  //$advancedFieldSet->addElement($imagesExplainLabel1);
578
  //$advancedFieldSet->addElement($imagesExplainLabel2);
555
  }
556
  $useHighDetailLabel = new Varien_Data_Form_Element_Label(array('value' => $helper->__("Use high detail in recommendation requests"), 'bold' => 'true'));
557
 
558
+ $useAjaxRequests = new Varien_Data_Form_Element_Checkbox(array('name' => 'use_ajax_requests'));
559
+ $useAjaxRequests->setId('use_ajax_requests');
560
+ $useAjaxRequests->setValue("checked");
561
+ $useAjaxRequestsOption = Mage::getStoreConfig('brainsins/BS_USE_AJAX_REQUESTS');
562
+ if (isset($useAjaxRequestsOption) && $useAjaxRequestsOption != null) {
563
+ if ($useAjaxRequestsOption == "1") {
564
+ $useAjaxRequests->setIsChecked(true);
565
+ } else {
566
+ $useAjaxRequests->setIsChecked(false);
567
+ }
568
+ } else {
569
+ $useAjaxRequests->setIsChecked(false);
570
+ }
571
+ $useAjaxRequestsLabel = new Varien_Data_Form_Element_Label(array('value' => $helper->__("Use ajax for recommendation requests"), 'bold' => 'true'));
572
+
573
 
574
  //$advancedFieldSet->addElement($advancedRadios);
575
  $advancedFieldSet->addElement($includeOutOfStockLabel);
588
  $advancedFieldSet->addElement($importScriptHttps);
589
  $advancedFieldSet->addElement($useHighDetailLabel);
590
  $advancedFieldSet->addElement($useHighDetail);
591
+ $advancedFieldSet->addElement($useAjaxRequestsLabel);
592
+ $advancedFieldSet->addElement($useAjaxRequests);
593
 
594
  //$advancedFieldSet->addElement($imagesExplainLabel1);
595
  //$advancedFieldSet->addElement($imagesExplainLabel2);
app/code/community/Brainsins/Recsins/Block/Adminhtml/Recsins/Edit/Tab/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Block/Recsins.php CHANGED
@@ -2,28 +2,28 @@
2
 
3
  /*
4
  * BrainSINS' Magento Extension allows to integrate the BrainSINS
5
- * personalized product recommendations into a Magento Store.
6
- * Copyright (c) 2011 Social Gaming Platform S.R.L.
7
- *
8
- * This file is part of BrainSINS' Magento Extension.
9
- *
10
- * BrainSINS' Magento Extension is free software: you can redistribute it
11
- * and/or modify it under the terms of the GNU General Public License
12
- * as published by the Free Software Foundation, either version 3 of the
13
- * License, or (at your option) any later version.
14
- *
15
- * BrainSINS' Magento Extension is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with BrainSINS' Magento Extension. If not, see
22
- * <http://www.gnu.org/licenses/>.
23
- *
24
- * Please do not hesitate to contact us at info@brainsins.com
25
- *
26
- */
27
 
28
  /*
29
  * This block is attached to the footer of all front-end pages
@@ -153,20 +153,20 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
153
  $script .= "</script>";
154
  $html .= $script;
155
  }
156
-
157
  //custom js file from config
158
-
159
  $scriptUrl = "";
160
-
161
  if (Mage::app()->getStore()->isCurrentlySecure()) {
162
  $scriptUrl = Mage::getStoreConfig('brainsins/BS_SCRIPT_THTTPS_URL');
163
  } else {
164
  $scriptUrl = Mage::getStoreConfig('brainsins/BS_SCRIPT_URL');
165
  }
166
-
167
  if (isset($scriptUrl) && $scriptUrl != "") {
168
  $html .= "<script type='text/javascript' src='" . $scriptUrl . "'></script>";
169
- }
170
 
171
  $html .= '<script type="text/javascript">';
172
  $html .= 'var bsHost = (("https:" == document.location.protocol) ? "https://" : "http://");' . PHP_EOL;
@@ -191,7 +191,7 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
191
  $checkoutSuccessFlag = $session->getData("recsins_checkout_success");
192
 
193
  $isValidUl = array_key_exists('ul', $_COOKIE) && isset($_COOKIE['ul']) && $_COOKIE['ul'];
194
-
195
  if ($this->getCustomerId() && (!$isValidUl || ($loginFlag && $loginFlag == '1'))) {
196
  $customer = Mage::getSingleton('customer/session')->getCustomer();
197
  $isNewUser = Mage::getModel("recsins/recsins")->checkNewUser($customer, $this->getCustomerEmail());
@@ -251,7 +251,7 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
251
  //track page url
252
  $product = Mage::registry('current_product');
253
  if (isset($product) && $product) {
254
-
255
 
256
  $pid = $product->getId();
257
  $name = $product->getName();
@@ -331,7 +331,7 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
331
  }
332
  }
333
  }
334
- }
335
  }
336
  }
337
  }
@@ -384,8 +384,133 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
384
  return $html;
385
  }
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  public function getJSRecommendations($placeKey, $divId, $userId, $productId) {
388
 
 
 
 
 
 
 
389
  $key = Mage::getStoreConfig('brainsins/BSKEY');
390
 
391
  $recommenderId = Mage::getStoreConfig($placeKey);
@@ -408,29 +533,29 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
408
  if (isset($key) && $key != null && isset($recommenderId)) {
409
 
410
  $paintCallback = "null";
411
-
412
  $currencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
413
  $currencyJs = "";
414
  $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
415
  $langCode = Mage::app()->getStore()->getCode() . $currencyCode;
416
-
417
  if ($currencySymbol == "$") {
418
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbol( BrainSINS.RecommenderConstants.dollar );" . PHP_EOL;
419
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
420
  $currencyJs .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
421
- } else if ($currencySymbol == "�") {
422
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbol( BrainSINS.RecommenderConstants.pound );" . PHP_EOL;
423
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
424
  $currencyJs .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
425
- } else if ($currencySymbol == "�") {
426
  //default behaviour
427
  } else {
428
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbol('$currencySymbol');" . PHP_EOL;
429
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
430
  $currencyJs .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
431
  }
432
-
433
-
434
  if ($placeKey == 'brainsins/BS_HOME_RECOMMENDER') {
435
  $paintCallback = "typeof bsPaintHomeRecommendations == 'undefined' ? null : bsPaintHomeRecommendations";
436
  } elseif ($placeKey == 'brainsins/BS_PRODUCT_RECOMMENDER') {
@@ -452,14 +577,14 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
452
  $script .= 'var bsHost = (("https:" == document.location.protocol) ? "https://" : "http://");' . PHP_EOL;
453
  $script .= 'document.write(unescape("%3Cscript src=\'" + bsHost + "' . $recUrl . '/bsrecwidget.js\' type=\'text/javascript\'%3E%3C/script%3E"));' . PHP_EOL;
454
  $script .= "</script>" . PHP_EOL;
455
-
456
  $useHighDetailScript = "";
457
-
458
  $useHighDetail = Mage::getStoreConfig('brainsins/BS_USE_HIGH_DETAIL');
459
  if (isset($useHighDetail) && $useHighDetail == "1") {
460
- $useHighDetailScript = 'BrainSINSRecommender.setDetailsLevel("high");' . PHP_EOL;
461
  }
462
-
463
  $script .= '
464
  <script type="text/javascript">
465
  try{
@@ -473,6 +598,19 @@ class Brainsins_Recsins_Block_Recsins extends Mage_Core_Block_Abstract {
473
  </script>
474
  ';
475
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
476
  return $script;
477
  }
478
  }
2
 
3
  /*
4
  * BrainSINS' Magento Extension allows to integrate the BrainSINS
5
+ * personalized product recommendations into a Magento Store.
6
+ * Copyright (c) 2011 Social Gaming Platform S.R.L.
7
+ *
8
+ * This file is part of BrainSINS' Magento Extension.
9
+ *
10
+ * BrainSINS' Magento Extension is free software: you can redistribute it
11
+ * and/or modify it under the terms of the GNU General Public License
12
+ * as published by the Free Software Foundation, either version 3 of the
13
+ * License, or (at your option) any later version.
14
+ *
15
+ * BrainSINS' Magento Extension is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with BrainSINS' Magento Extension. If not, see
22
+ * <http://www.gnu.org/licenses/>.
23
+ *
24
+ * Please do not hesitate to contact us at info@brainsins.com
25
+ *
26
+ */
27
 
28
  /*
29
  * This block is attached to the footer of all front-end pages
153
  $script .= "</script>";
154
  $html .= $script;
155
  }
156
+
157
  //custom js file from config
158
+
159
  $scriptUrl = "";
160
+
161
  if (Mage::app()->getStore()->isCurrentlySecure()) {
162
  $scriptUrl = Mage::getStoreConfig('brainsins/BS_SCRIPT_THTTPS_URL');
163
  } else {
164
  $scriptUrl = Mage::getStoreConfig('brainsins/BS_SCRIPT_URL');
165
  }
166
+
167
  if (isset($scriptUrl) && $scriptUrl != "") {
168
  $html .= "<script type='text/javascript' src='" . $scriptUrl . "'></script>";
169
+ }
170
 
171
  $html .= '<script type="text/javascript">';
172
  $html .= 'var bsHost = (("https:" == document.location.protocol) ? "https://" : "http://");' . PHP_EOL;
191
  $checkoutSuccessFlag = $session->getData("recsins_checkout_success");
192
 
193
  $isValidUl = array_key_exists('ul', $_COOKIE) && isset($_COOKIE['ul']) && $_COOKIE['ul'];
194
+
195
  if ($this->getCustomerId() && (!$isValidUl || ($loginFlag && $loginFlag == '1'))) {
196
  $customer = Mage::getSingleton('customer/session')->getCustomer();
197
  $isNewUser = Mage::getModel("recsins/recsins")->checkNewUser($customer, $this->getCustomerEmail());
251
  //track page url
252
  $product = Mage::registry('current_product');
253
  if (isset($product) && $product) {
254
+
255
 
256
  $pid = $product->getId();
257
  $name = $product->getName();
331
  }
332
  }
333
  }
334
+ }
335
  }
336
  }
337
  }
384
  return $html;
385
  }
386
 
387
+ public function getAjaxRequestRecommendations($placeKey, $divId, $userId, $productId) {
388
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
389
+
390
+ $recommenderId = Mage::getStoreConfig($placeKey);
391
+
392
+ if (!isset($recommenderId) || !$recommenderId) {
393
+ return "";
394
+ }
395
+
396
+ if (!isset($productId)) {
397
+ $productId = 0;
398
+ }
399
+
400
+ //$prodId = $productId ? "'" . $productId . "'" : 'null';
401
+
402
+ $recUrl = $this->getRecommenderUrl();
403
+
404
+ $script = "";
405
+ $filter = '';
406
+
407
+ if (isset($key) && $key != null && isset($recommenderId)) {
408
+
409
+ $paintCallback = "null";
410
+ if ($placeKey == 'brainsins/BS_HOME_RECOMMENDER') {
411
+ $paintCallback = "bsPaintHomeRecommendations";
412
+ } elseif ($placeKey == 'brainsins/BS_PRODUCT_RECOMMENDER') {
413
+ $paintCallback = "bsPaintProductRecommendations";
414
+ } elseif ($placeKey == 'brainsins/BS_CART_RECOMMENDER') {
415
+ $paintCallback = "bsPaintCartRecommendations";
416
+ } elseif ($placeKey == 'brainsins/BS_CHECKOUT_RECOMMENDER') {
417
+ $paintCallback = "bsPaintCheckoutRecommendations";
418
+ } elseif ($placeKey == 'brainsins/BS_CATEGORY_RECOMMENDER') {
419
+ $paintCallback = "bsPaintCategoryRecommendations";
420
+ }
421
+
422
+ $script .= '<script type="text/javascript">' . PHP_EOL;
423
+ $script .= 'var bsHost = (("https:" == document.location.protocol) ? "https://" : "http://");' . PHP_EOL;
424
+ $script .= 'document.write(unescape("%3Cscript src=\'" + bsHost + "' . $recUrl . '/bsrecwidget.js\' type=\'text/javascript\'%3E%3C/script%3E"));' . PHP_EOL;
425
+ $script .= "</script>" . PHP_EOL;
426
+
427
+ $script .= '<script type="text/javascript">' . PHP_EOL;
428
+ $script .= 'var BrainSINSRecommender = BrainSINS.getRecommender(BrainSINSTracker);' . PHP_EOL;
429
+ $script .= 'BrainSINSRecommender.loadCSS(' . $recommenderId . ");" . PHP_EOL;
430
+
431
+ $useHighDetail = Mage::getStoreConfig('brainsins/BS_USE_HIGH_DETAIL');
432
+ if (isset($useHighDetail) && $useHighDetail == "1") {
433
+ $script .= 'BrainSINSRecommender.setDetailsLevel("high");' . PHP_EOL;
434
+ }
435
+
436
+ $currencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
437
+ $currencyJs = "";
438
+ $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
439
+ $langCode = Mage::app()->getStore()->getCode() . $currencyCode;
440
+
441
+ if ($currencySymbol == "$") {
442
+ $script .= "BrainSINSRecommender.setCurrencySymbol( BrainSINS.RecommenderConstants.dollar );" . PHP_EOL;
443
+ $script .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
444
+ $script .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
445
+ } else if ($currencySymbol == "£") {
446
+ $script .= "BrainSINSRecommender.setCurrencySymbol( BrainSINS.RecommenderConstants.pound );" . PHP_EOL;
447
+ $script .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
448
+ $script .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
449
+ } else if ($currencySymbol == "€") {
450
+ //default behaviour
451
+ } else {
452
+ $script .= "BrainSINSRecommender.setCurrencySymbol('$currencySymbol');" . PHP_EOL;
453
+ $script .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
454
+ $script .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
455
+ }
456
+
457
+ $script .= "</script>" . PHP_EOL;
458
+
459
+ $script .= '<script type="text/javascript">' . PHP_EOL;
460
+
461
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
462
+ $pos = strpos($baseUrl, "/", 8);
463
+ $callUrl = "";
464
+ if ($pos !== false) {
465
+ $callUrl = substr($baseUrl, $pos);
466
+ $callUrl .= "recsins/index/getRecommendations";
467
+ } else {
468
+ $callUrl .= "/recsins/index/getRecommendations";
469
+ }
470
+
471
+
472
+ $script .= 'new Ajax.Request("' . $callUrl;
473
+
474
+ $script .= '/recId/' . $recommenderId;
475
+ $script .= '/userId/' . $userId;
476
+
477
+ if ($placeKey == 'brainsins/BS_CATEGORY_RECOMMENDER') {
478
+ $script .= '/categories/' . $productId;
479
+ $script .= '/filter/all';
480
+ } elseif ($placeKey == 'brainsins/BS_PRODUCT_RECOMMENDER') {
481
+ $script .= '/prodId/' . $productId;
482
+ }
483
+
484
+ $script .= '/lang/' . $langCode;
485
+ $script .= '/divName/' . $divId;
486
+
487
+ $script .= '",{';
488
+ $script .= 'method : "get",' . PHP_EOL;
489
+ $script .= 'onSuccess : function(transport) {' . PHP_EOL;
490
+ $script .= 'if (typeof ' . $paintCallback . ' == "function") {';
491
+ $script .= 'console.log(transport.responseJSON);';
492
+ $script .= $paintCallback . "(transport.responseJSON);";
493
+ $script .= "} else {";
494
+ $script .= "BrainSINSRecommender.paintRecommendations(transport.responseJSON);";
495
+ $script .="}";
496
+
497
+ $script .= '}' . PHP_EOL;
498
+ $script .= '});' . PHP_EOL;
499
+
500
+ $script .= "</script>" . PHP_EOL;
501
+ }
502
+
503
+ return $script;
504
+ }
505
+
506
  public function getJSRecommendations($placeKey, $divId, $userId, $productId) {
507
 
508
+ $useAjax = Mage::getStoreConfig('brainsins/BS_USE_AJAX_REQUESTS');
509
+
510
+ if (isset($useAjax) && $useAjax == "1") {
511
+ return $this->getAjaxRequestRecommendations($placeKey, $divId, $userId, $productId);
512
+ }
513
+
514
  $key = Mage::getStoreConfig('brainsins/BSKEY');
515
 
516
  $recommenderId = Mage::getStoreConfig($placeKey);
533
  if (isset($key) && $key != null && isset($recommenderId)) {
534
 
535
  $paintCallback = "null";
536
+
537
  $currencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
538
  $currencyJs = "";
539
  $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
540
  $langCode = Mage::app()->getStore()->getCode() . $currencyCode;
541
+
542
  if ($currencySymbol == "$") {
543
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbol( BrainSINS.RecommenderConstants.dollar );" . PHP_EOL;
544
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
545
  $currencyJs .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
546
+ } else if ($currencySymbol == "�") {
547
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbol( BrainSINS.RecommenderConstants.pound );" . PHP_EOL;
548
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
549
  $currencyJs .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
550
+ } else if ($currencySymbol == "�") {
551
  //default behaviour
552
  } else {
553
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbol('$currencySymbol');" . PHP_EOL;
554
  $currencyJs .= "BrainSINSRecommender.setCurrencySymbolPosition( BrainSINS.RecommenderConstants.leftPosition );" . PHP_EOL;
555
  $currencyJs .= "BrainSINSRecommender.setCurrencyDelimiter( '.' );" . PHP_EOL;
556
  }
557
+
558
+
559
  if ($placeKey == 'brainsins/BS_HOME_RECOMMENDER') {
560
  $paintCallback = "typeof bsPaintHomeRecommendations == 'undefined' ? null : bsPaintHomeRecommendations";
561
  } elseif ($placeKey == 'brainsins/BS_PRODUCT_RECOMMENDER') {
577
  $script .= 'var bsHost = (("https:" == document.location.protocol) ? "https://" : "http://");' . PHP_EOL;
578
  $script .= 'document.write(unescape("%3Cscript src=\'" + bsHost + "' . $recUrl . '/bsrecwidget.js\' type=\'text/javascript\'%3E%3C/script%3E"));' . PHP_EOL;
579
  $script .= "</script>" . PHP_EOL;
580
+
581
  $useHighDetailScript = "";
582
+
583
  $useHighDetail = Mage::getStoreConfig('brainsins/BS_USE_HIGH_DETAIL');
584
  if (isset($useHighDetail) && $useHighDetail == "1") {
585
+ $useHighDetailScript = 'BrainSINSRecommender.setDetailsLevel("high");' . PHP_EOL;
586
  }
587
+
588
  $script .= '
589
  <script type="text/javascript">
590
  try{
598
  </script>
599
  ';
600
  }
601
+
602
+ /*$script .= "<script type='text/javascript'>";
603
+ $script .= "var BrainSINSRecommender = BrainSINS.getRecommender( BrainSINSTracker );";
604
+ $script .= "BrainSINSRecommender.loadCSS(2);";
605
+ $script .= 'new Ajax.Request("/mage170/recsins/index/getRecommendations", {';
606
+ $script .= 'method : "get",';
607
+ $script .= 'onSuccess : function(transport) {';
608
+ $script .= 'document.getElementById("home_recommendations").innerHTML = transport.responseText';
609
+ $script .= '}';
610
+ $script .= '})';
611
+
612
+ $script .="</script>";*/
613
+
614
  return $script;
615
  }
616
  }
app/code/community/Brainsins/Recsins/Entity/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Helper/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Model/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Model/Api/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Model/Api/Api.php CHANGED
@@ -38,7 +38,7 @@ class Brainsins_Recsins_Model_Api_Api extends Mage_Api_Model_Resource_Abstract {
38
  }
39
  return $result;
40
  }
41
-
42
  public function currencyList() {
43
  $currencies = Mage::app()->getStore()->getAvailableCurrencyCodes(true);
44
  return $currencies;
@@ -51,32 +51,48 @@ class Brainsins_Recsins_Model_Api_Api extends Mage_Api_Model_Resource_Abstract {
51
  return ($productsApi->bsInfo($productId, $store));
52
  }
53
 
54
- public function productCount() {
55
- return array(Mage::getModel("catalog/product")->getCollection()
56
- ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
57
- ->count());
 
 
 
 
 
 
58
  }
59
 
60
  public function productPage($numPage, $size, $visibility = 2, $options = array(), $filter = array()) {
61
-
62
  $visibility = 2;
63
  $visibilityComparator = "ge";
64
-
65
  if (array_key_exists("visibility", $options)) {
66
  $visibility = $options["visibility"];
67
  }
68
-
69
  if (array_key_exists("visibilityComparator", $options)) {
70
  $visibilityComparator = $options["visibilityComparator"];
71
  }
72
-
73
-
74
- $products = Mage::getModel('catalog/product')->getCollection()
75
- ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
76
- ->addAttributeToSelect('id')->
77
- addAttributeToSelect('visibility')->
78
- addAttributeToSelect('store_ids')->
79
- setPage($numPage, $size);
 
 
 
 
 
 
 
 
 
 
80
 
81
  $result = array();
82
  $productsApi = new Brainsins_Recsins_Model_Api_ProductsApi();
@@ -86,12 +102,12 @@ class Brainsins_Recsins_Model_Api_Api extends Mage_Api_Model_Resource_Abstract {
86
  $prodVisibility = $product->getVisibility();
87
 
88
  if (
89
- $visibilityComparator == "eq" && $prodVisibility == $visibility ||
90
- $visibilityComparator == "ne" && $prodVisibility != $visibility ||
91
- $visibilityComparator == "gt" && $prodVisibility > $visibility ||
92
- $visibilityComparator == "ge" && $prodVisibility >= $visibility ||
93
- $visibilityComparator == "lt" && $prodVisibility < $visibility ||
94
- $visibilityComparator == "le" && $prodVisibility <= $visibility
95
  ) {
96
  $stores = $product->getStoreIds();
97
 
@@ -128,8 +144,8 @@ class Brainsins_Recsins_Model_Api_Api extends Mage_Api_Model_Resource_Abstract {
128
  $subscribed = "0";
129
  if ($subscriber->isSubscribed()) {
130
  $subscribed = "1";
131
- }
132
-
133
  $customerInfo['email'] = $email;
134
  $customerInfo['bs_lang_code'] = Mage::app()->getStore($customer->getStoreId())->getCode();
135
  $customerInfo['bs_is_subscribed'] = $subscribed;
@@ -248,9 +264,9 @@ class Brainsins_Recsins_Model_Api_Api extends Mage_Api_Model_Resource_Abstract {
248
  } else {
249
  $result['use_special_price'] = "0";
250
  }
251
-
252
  $taxPriceSelectedOption = Mage::getStoreConfig('brainsins/BS_TAX_PRICE');
253
-
254
  if (isset($taxPriceSelectedOption)) {
255
  $result['tax_price'] = $taxPriceSelectedOption;
256
  } else {
38
  }
39
  return $result;
40
  }
41
+
42
  public function currencyList() {
43
  $currencies = Mage::app()->getStore()->getAvailableCurrencyCodes(true);
44
  return $currencies;
51
  return ($productsApi->bsInfo($productId, $store));
52
  }
53
 
54
+ public function productCount($options = array()) {
55
+
56
+ if (array_key_exists("skipStatusFilter", $options) && $options['skipStatusFilter'] == "1") {
57
+ return array(Mage::getModel("catalog/product")->getCollection()
58
+ ->count());
59
+ } else {
60
+ return array(Mage::getModel("catalog/product")->getCollection()
61
+ ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
62
+ ->count());
63
+ }
64
  }
65
 
66
  public function productPage($numPage, $size, $visibility = 2, $options = array(), $filter = array()) {
67
+
68
  $visibility = 2;
69
  $visibilityComparator = "ge";
70
+
71
  if (array_key_exists("visibility", $options)) {
72
  $visibility = $options["visibility"];
73
  }
74
+
75
  if (array_key_exists("visibilityComparator", $options)) {
76
  $visibilityComparator = $options["visibilityComparator"];
77
  }
78
+
79
+ $products = array();
80
+ if (array_key_exists("skipStatusFilter", $options) && $options['skipStatusFilter'] == "1") {
81
+ $products = Mage::getModel('catalog/product')->getCollection()
82
+ ->addAttributeToSelect('id')->
83
+ addAttributeToSelect('visibility')->
84
+ addAttributeToSelect('store_ids')->
85
+ setPage($numPage, $size);
86
+ } else {
87
+ $products = Mage::getModel('catalog/product')->getCollection()
88
+ ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
89
+ ->addAttributeToSelect('id')->
90
+ addAttributeToSelect('visibility')->
91
+ addAttributeToSelect('store_ids')->
92
+ setPage($numPage, $size);
93
+ }
94
+
95
+
96
 
97
  $result = array();
98
  $productsApi = new Brainsins_Recsins_Model_Api_ProductsApi();
102
  $prodVisibility = $product->getVisibility();
103
 
104
  if (
105
+ $visibilityComparator == "eq" && $prodVisibility == $visibility ||
106
+ $visibilityComparator == "ne" && $prodVisibility != $visibility ||
107
+ $visibilityComparator == "gt" && $prodVisibility > $visibility ||
108
+ $visibilityComparator == "ge" && $prodVisibility >= $visibility ||
109
+ $visibilityComparator == "lt" && $prodVisibility < $visibility ||
110
+ $visibilityComparator == "le" && $prodVisibility <= $visibility
111
  ) {
112
  $stores = $product->getStoreIds();
113
 
144
  $subscribed = "0";
145
  if ($subscriber->isSubscribed()) {
146
  $subscribed = "1";
147
+ }
148
+
149
  $customerInfo['email'] = $email;
150
  $customerInfo['bs_lang_code'] = Mage::app()->getStore($customer->getStoreId())->getCode();
151
  $customerInfo['bs_is_subscribed'] = $subscribed;
264
  } else {
265
  $result['use_special_price'] = "0";
266
  }
267
+
268
  $taxPriceSelectedOption = Mage::getStoreConfig('brainsins/BS_TAX_PRICE');
269
+
270
  if (isset($taxPriceSelectedOption)) {
271
  $result['tax_price'] = $taxPriceSelectedOption;
272
  } else {
app/code/community/Brainsins/Recsins/Model/Api/ficheros/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Model/Mysql4/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/Model/Recsins.php CHANGED
@@ -2,650 +2,689 @@
2
 
3
  /*
4
  * BrainSINS' Magento Extension allows to integrate the BrainSINS
5
- * personalized product recommendations into a Magento Store.
6
- * Copyright (c) 2011 Social Gaming Platform S.R.L.
7
- *
8
- * This file is part of BrainSINS' Magento Extension.
9
- *
10
- * BrainSINS' Magento Extension is free software: you can redistribute it
11
- * and/or modify it under the terms of the GNU General Public License
12
- * as published by the Free Software Foundation, either version 3 of the
13
- * License, or (at your option) any later version.
14
- *
15
- * Foobar is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22
- *
23
- * Please do not hesitate to contact us at info@brainsins.com
24
- *
25
- */
26
 
27
  class Brainsins_Recsins_Model_Recsins extends Mage_Core_Model_Abstract {
28
 
29
- private $bsClient;
30
- //private $dev = true;
31
- private $dev = false;
32
- private $server;
33
 
34
- protected function _construct() {
35
- parent::_construct();
36
- $this->_init('recsins/recsins');
37
 
38
- $key = Mage::getStoreConfig('brainsins/BSKEY');
39
 
40
 
41
- if ($this->dev) {
42
- $this->server = "dev-api.brainsins.com";
43
- } else {
44
- $this->server = "api.brainsins.com";
45
- }
46
 
47
- $this->bsClient = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
48
- }
49
 
50
- public function importRecommenders() {
51
- $key = Mage::getStoreConfig('brainsins/BSKEY');
52
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
53
 
54
- $recommenders = simplexml_load_string($client->getAllRecommenders());
55
- $result = false;
56
- if (isset($recommenders) && isset($recommenders->recommenders)) {
57
- //delete previous recommenders
58
 
59
- $recModel = Mage::getModel('recsins/recommender');
60
- $dbRecommenders = array();
61
 
62
- foreach ($recommenders->recommenders->recommender as $recommender) {
63
 
64
- $dbRecommender = array();
65
- $dbRecommender['id'] = $recommender->id_recommender;
66
- $dbRecommender['name'] = $recommender->name;
67
- $dbRecommender['page'] = $recommender->page;
68
 
69
- $dbRecommenders[] = $dbRecommender;
70
- }
71
 
72
- $result = $recModel->setAllRecommenders($dbRecommenders);
73
- }
74
- return $result;
75
- }
76
 
77
- public function uploadCatalogUsers($pageSize, $lastPage, $firstTransaction = false) {
78
 
79
- $lastCustomerId = 0;
80
 
81
- $key = Mage::getStoreConfig('brainsins/BSKEY');
82
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
83
 
84
- $customers = Mage::getModel("customer/customer")->getCollection()->addAttributeToSelect('*')->setPage($lastPage + 1, $pageSize);
85
 
86
- $result = true;
87
 
88
- $firstUploadChanged = false;
89
 
90
- foreach ($customers as $customer) {
91
 
92
- if ($firstTransaction && !$firstUploadChanged) {
93
- $firstUploadChanged = true;
94
- Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_FIRST_TRANSACTION', '0');
95
- }
96
 
97
- $user = Mage::getModel('recsins/user', array('user_id' => $customer->getId(), 'email' => $customer->getEmail()));
98
- $client->addUser($user);
99
- if ($customer->getId() > $lastCustomerId) {
100
- $lastCustomerId = $customer->getId();
101
- }
102
- }
103
 
104
- $result = $client->sendUsers($firstTransaction);
105
 
106
- $lastUploadedId = Mage::getStoreConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED');
107
 
108
- if (!isset($lastUploadedId) || $lastUploadedId < $lastCustomerId) {
109
- Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED', $lastCustomerId);
110
- }
111
 
112
- Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_LAST_PAGE_SENT', $lastPage + 1);
113
- //Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_BS_LAST_CUSTOMER_ID_UPLOADED', $lastCustomerId);
114
 
115
- return $result;
116
- }
117
 
118
- public function uploadCatalogProducts($pageSize, $lastPage, $firstTransaction = false, $uploadOutOfStock = false) {
119
- $stores = Mage::app()->getStore()->getCollection();
120
 
121
- $key = Mage::getStoreConfig('brainsins/BSKEY');
122
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
123
 
124
- $transactionCounter = 0;
125
 
126
- $result = true;
127
 
128
- //get first store id
129
- $firstStoreId = $stores->getFirstItem();
130
 
131
- if ($firstStoreId) {
132
- $firstStoreId = $firstStoreId->getId();
133
- } else {
134
- return;
135
- }
136
 
137
- if (!isset($firstStoreId)) {
138
- return;
139
- }
140
 
141
- $client->resetAll();
142
- $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->setPage($lastPage + 1, $pageSize)->addPriceData(null, $firstStoreId);
143
 
144
- $firstUploadChanged = false;
145
 
146
 
147
- foreach ($products as $product) {
148
- $id = $product->getId();
149
 
150
- $visibility = $product->getVisibility();
151
- $configurable_product_model = Mage::getModel('catalog/product_type_configurable');
152
- $parentIdArray = $configurable_product_model->getParentIdsByChild($product->getId());
153
 
154
- if (!$uploadOutOfStock && (!Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIs_in_stock() || Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty() <= 0)) {
155
- continue;
156
- }
157
 
158
- if ($firstTransaction && !$firstUploadChanged) {
159
- $firstUploadChanged = true;
160
- Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_FIRST_TRANSACTION', '0');
161
- }
162
 
163
- if (count($parentIdArray) == 0 && $visibility > 1 && $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
164
 
165
- $bsProduct = Mage::getModel('recsins/product');
166
 
167
 
168
- $bsProduct->setIsMultilanguage(true);
169
 
170
- $names = array();
171
- $descriptions = array();
172
- $urls = array();
173
- $prices = array();
174
- $imageUrls = array();
175
 
176
- $bsProduct->setProduct_id($product->getId());
177
 
178
- $categoryList = array();
179
- $categoryIds = $product->getCategoryIds();
180
 
181
 
182
- if (isset($categoryIds) && is_array($categoryIds)) {
183
- foreach ($categoryIds as $catId) {
184
- $category = Mage::getModel('catalog/category')->load($catId);
185
- $parents = $category->getParentIds();
186
 
187
- if (!in_array($catId, $categoryList)) {
188
- $categoryList[] = $catId;
189
- }
190
 
191
- if (isset($parents) && is_array($parents)) {
192
- foreach ($parents as $parent) {
193
- if (!in_array($parent, $categoryList)) {
194
- $categoryList[] = $parent;
195
- }
196
- }
197
- }
198
- }
199
- }
200
- $bsProduct->setCategories($categoryList);
201
 
202
- foreach ($stores as $store) {
203
 
204
- $storeCode = $store->getCode();
205
- $storeId = $store->getId();
206
 
207
- $product->setStoreId($storeId);
208
- $product->load($id);
209
 
210
- $price = $product->getPrice();
211
 
212
- if ($price == 0.0 && $product->getTypeId() == "bundle") {
213
- list($minPrice, $maxPrice) = $product->getPriceModel()->getPrices($product);
214
- $price = $minPrice;
215
- }
216
 
217
- $prices[$storeCode] = $price;
218
- $useSpecialPrice = Mage::getStoreConfig('brainsins/BS_USE_SPECIAL_PRICE');
219
- if (isset($useSpecialPrice) && $useSpecialPrice == '1') {
220
-
221
- $specialPrice = $product->getSpecialPrice();
222
- if (isset($specialPrice) && $specialPrice) {
223
-
224
- $specialFrom = $product->getSpecialFromDate();
225
- $specialTo = $product->getSpecialToDate();
226
- $specialFromTS;
227
- $specialToTS;
228
-
229
- $nowTS = time();
230
-
231
- $specialValidRange = true;
232
-
233
- if (isset($specialFrom)) {
234
- $specialFromTS = strtotime($specialFrom);
235
- if ($specialFromTS > $nowTS) {
236
- $specialValidRange = false;
237
- }
238
- }
239
-
240
- if (isset($specialTo)) {
241
- $specialToTS = strtotime($specialTo);
242
- if ($specialToTS < $nowTS) {
243
- $specialValidRange = false;
244
- }
245
- }
246
-
247
- if ($specialValidRange && $product->getTypeId() != "bundle") {
248
- $prices[$storeCode] = $specialPrice;
249
- }
250
- }
251
- }
252
-
253
-
254
- $resize = false;
255
- $width = 0;
256
- $heigth = 0;
257
-
258
- $imageSelectedOption = Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_BS_IMAGE_RESIZE');
259
- if (isset($imageSelectedOption) && $imageSelectedOption == 'image_resize') {
260
- $resize = true;
261
- }
262
-
263
- $imageSelectedWidth = Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_BS_IMAGE_RESIZE_WIDTH');
264
- $imageSelectedHeigth = Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_BS_IMAGE_RESIZE_HEIGTH');
265
-
266
- if (isset($imageSelectedWidth) && is_numeric($imageSelectedWidth) && $imageSelectedWidth > 0) {
267
- $width = $imageSelectedWidth;
268
- }
269
-
270
- if (isset($imageSelectedHeigth) && is_numeric($imageSelectedHeigth) && $imageSelectedHeigth > 0) {
271
- $heigth = $imageSelectedHeigth;
272
- }
273
-
274
- if ($resize && $width > 0) {
275
- $prodImage = $product->getSmallImage();
276
- if (isset($prodImage) && $prodImage != null && $prodImage != "no_selection") {
277
- if ($heigth > 0) {
278
- $imageUrls[$storeCode] = ((string) Mage::helper('catalog/image')->init($product, "small_image")->resize($width, $heigth));
279
- } else {
280
- $imageUrls[$storeCode] = ((string) Mage::helper('catalog/image')->init($product, "small_image")->resize($width));
281
- }
282
- }
283
- } else {
284
- $prodImage = $product->getSmallImage();
285
- if (isset($prodImage) && $prodImage != null && $prodImage != "no_selection") {
286
-
287
- $img = Mage::getModel("catalog/product_image");
288
- $img->setDestinationSubdir("small_image");
289
- $img->setBaseFile($prodImage);
290
-
291
- $baseDir = Mage::getBaseDir('media');
292
- $path = str_replace($baseDir . DS, "", $img->getBaseFile());
293
- $url = $store->getBaseUrl('media') . str_replace(DS, '/', $path);
294
- $imageUrls[$storeCode] = $url;
295
- }
296
- }
297
-
298
- //if resize is selected, override image url with controller call. Previous code will leave a copy of the image ready in the cache
299
- if ($resize) {
300
- $imageUrls[$storeCode] = $store->getBaseUrl() . "recsins/index/getRecProdImg?id=" . $id;
301
- }
302
- $names[$storeCode] = utf8_decode($product->getName());
303
- $descriptions[$storeCode] = utf8_decode($product->getShortDescription());
304
- $urls[$storeCode] = $product->getProductUrl();
305
- }
306
-
307
- $bsProduct->setNames($names);
308
- $bsProduct->setDescriptions($descriptions);
309
- $bsProduct->setUrls($urls);
310
- $bsProduct->setPrices($prices);
311
- $bsProduct->setImageUrls($imageUrls);
312
-
313
- $client->addProduct($bsProduct);
314
- } else {
315
- //this product is a configuration of a more general product(id)
316
- // or a non visible product
317
- }
318
- }
319
- Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_LAST_PAGE_SENT', $lastPage + 1);
320
- $result = $client->sendProducts($firstTransaction);
321
- return $result;
322
- }
323
-
324
- private function getNextFakeId($lastFakeId) {
325
- if (!isset($lastFakeId) || $lastFakeId == 0) {
326
- return 999999999999;
327
- } else {
328
- return $lastFakeId - 1;
329
- }
330
- }
331
-
332
- public function uploadCatalogQuotes($pageSize, $lastPage, $lastFakeId = 0, $firstTransaction = false) {
333
-
334
- $key = Mage::getStoreConfig('brainsins/BSKEY');
335
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
336
-
337
- $quotes = Mage::getModel('sales/quote')->getCollection()->setPageSize($pageSize)->setCurPage($lastPage + 1); //($lastPage + 1, 1);
338
- foreach ($quotes as $quote) {
339
-
340
- $quote->load($quote->getId());
341
- $items = $quote->getAllItems();
342
- $idCustomer = $quote->getCustomerId();
343
-
344
- if (!isset($idCustomer)) {
345
- $lastFakeId = $this->getNextFakeId($lastFakeId);
346
- $idCustomer = $lastFakeId;
347
- }
348
- $bsCart = Mage::getModel('recsins/cart');
349
- $bsCart->setIdCart($quote->getId());
350
- $bsCart->setIdUser($idCustomer);
351
- $bsCart->setStartDate($quote->getCreated_at());
352
- $bsCart->setFinishDate($quote->getUpdated_at());
353
-
354
- $cartItems = array();
355
- foreach ($items as $item) {
356
-
357
- if ($item->getParentItemId()) {
358
- continue;
359
- }
360
-
361
- //TODO ? $product = $item->getProduct();
362
- $qty = $item->getQty();
363
- $price = $item->getPrice();
364
- $idProduct = $item->getProduct_id();
365
-
366
- if (array_key_exists($idProduct, $cartItems)) {
367
- $newQty = $cartItems[$idProduct]['qty'] + $qty;
368
- $newPrice = ($cartItems[$idProduct]['price'] * $cartItems[$idProduct]['qty'] + $price * $qty) / $newQty;
369
- $cartItems[$idProduct]['qty'] = $newQty;
370
- $cartItems[$idProduct]['price'] = $newPrice;
371
- } else {
372
- $cartItems[$idProduct] = array();
373
- $cartItems[$idProduct]['qty'] = $qty;
374
- $cartItems[$idProduct]['price'] = $price;
375
- }
376
- }
377
-
378
- $bsCart->setProducts($cartItems);
379
- $client->addCart($bsCart);
380
- }
381
-
382
- Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_LAST_PAGE_SENT', $lastPage + 1);
383
- Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_BS_LAST_FAKE_ID', $lastFakeId);
384
- return $client->sendCatalogCarts($firstTransaction);
385
- }
386
-
387
- public function uploadCatalogOrders($pageSize, $lastPage, $lastFakeId, $firstTransaction = false) {
388
-
389
- $key = Mage::getStoreConfig('brainsins/BSKEY');
390
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
391
-
392
- $orders = Mage::getModel('sales/order')->getCollection()->setPageSize($pageSize)->setCurPage($lastPage + 1);
393
-
394
- foreach ($orders as $order) {
395
-
396
- $order->load($order->getId());
397
- $idCustomer = $order->getCustomer_id();
398
- $quoteId = $order->getQuote_id();
399
-
400
- if (!isset($idCustomer)) {
401
- $idCustomer = $this->getNextFakeId($lastFakeId);
402
- }
403
-
404
- $bsOrder = Mage::getModel('recsins/order');
405
- $bsOrder->setIdPurchase($order->getIncrementId());
406
- $bsOrder->setIdCart($quoteId);
407
- $bsOrder->setIdUser($idCustomer);
408
- $bsOrder->setDate($order->getCreated_at());
409
- $bsOrder->setAmount($order->getSubtotal());
410
-
411
- $bsCart = Mage::getModel('recsins/cart');
412
- $bsCart->setIdCart($quoteId);
413
- $bsCart->setIdUser($idCustomer);
414
- $bsCart->setStartDate($order->getCreated_at());
415
- $bsCart->setFinishDate($order->getCreated_at());
416
-
417
- $orderItems = array();
418
- $cartItems = array();
419
 
420
- $items = $order->getAllItems();
421
- foreach ($items as $item) {
422
 
423
- if ($item->getParentItemId()) {
424
- continue;
425
- }
426
 
427
- $idProduct = $item->getProduct_id();
428
- $price = $item->getPrice();
429
- $qty = (int) $item->getQty_ordered();
430
 
431
- if (array_key_exists($idProduct, $orderItems)) {
432
- $newQty = $orderItems[$idProduct]['qty'] + $qty;
433
- $newPrice = ($orderItems[$idProduct]['price'] * $orderItems[$idProduct]['qty'] + $price * $qty) / $newQty;
434
- $orderItems[$idProduct]['qty'] = $newQty;
435
- $orderItems[$idProduct]['price'] = $newPrice;
436
- $cartItems[$idProduct]['qty'] = $newQty;
437
- $cartItems[$idProduct]['price'] = $newPrice;
438
- } else {
439
- $orderItems[$idProduct] = array();
440
- $cartItems[$idProduct] = array();
441
- $orderItems[$idProduct]['qty'] = $qty;
442
- $orderItems[$idProduct]['price'] = $price;
443
- $cartItems[$idProduct]['qty'] = $qty;
444
- $cartItems[$idProduct]['price'] = $price;
445
- }
446
- }
447
-
448
- $bsCart->setProducts($cartItems);
449
- $bsOrder->setProducts($orderItems);
450
 
451
- $client->addCart($bsCart);
452
- $client->addOrder($bsOrder);
453
- }
454
 
455
- $result = $client->sendCatalogCarts();
456
- $result = $result && $client->sendCatalogPurchases($firstTransaction);
457
 
458
- Mage::getModel('core/config')->saveConfig('brainsins/LAST_PAGE_SENT', $lastPage + 1);
459
- Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_FAKE_ID', $lastFakeId);
460
- return $result;
461
- }
462
 
463
- public function uploadQuotes($quotes, $userId = null) {
464
 
465
- $key = Mage::getStoreConfig('brainsins/BSKEY');
466
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
467
 
468
- foreach ($quotes as $quote) {
469
 
470
- $orderId = $quote->getOrig_order_id();
471
- if ($orderId == 0) {
472
- $orderId = $quote->getReserved_order_id();
473
- }
474
 
475
- if ($orderId == 0) {
476
- $items = $quote->getAllItems();
477
 
478
- if (count($items) > 0) {
479
- $idCustomer = $userId ? $userId : $quote->getCustomer()->getId();
480
- if ($idCustomer) {
481
 
482
- $cartCustomerId = $userId ? $userId : $quote->getCustomer()->getId();
483
 
484
- $bsCart = Mage::getModel('recsins/cart');
485
- $bsCart->setIdCart($quote->getId());
486
- $bsCart->setUserId($cartCustomerId);
487
 
488
- $bsCart->setStart_date($quote->getCreated_at());
489
- $bsCart->setFinish_date($quote->getUpdated_at());
490
- $cartItems = array();
491
 
492
 
493
- foreach ($items as $item) {
494
- if ($item->getParentItemId()) {
495
- continue;
496
- }
497
-
498
- $qty = $item->getQty();
499
- $price = $item->getBasePriceInclTax();
500
-
501
-
502
- $product = $item->getProduct();
503
-
504
- $productId = $product->getId();
505
- $configurable_product_model = Mage::getModel('catalog/product_type_configurable');
506
- $parentIdArray = $configurable_product_model->getParentIdsByChild($productId);
507
-
508
- $found = false;
509
-
510
- foreach ($cartItems as $storedItem) {
511
-
512
- if ($productId == $storedItem->getProduct_id()) {
513
-
514
- $storedQty = $storedItem->getQuantity();
515
- $storedPrice = $storedItem->getPrice();
516
-
517
- $newQty = $storedQty + $qty;
518
- $newPrice = ($storedPrice * $storedQty + $price * $qty) / $newQty;
519
-
520
- $storedItem->setQuantity($newQty);
521
- $storedItem->setPrice($newPrice);
522
-
523
- $found = true;
524
- break;
525
- }
526
- }
527
-
528
- if (!$found) {
529
- $cartItem = Mage::getModel('recsins/cartProduct');
530
-
531
- $cartItem->setProduct_id($productId);
532
- $cartItem->setQuantity($qty);
533
- $cartItem->setPrice($price);
534
-
535
- $cartItems[] = $cartItem;
536
- }
537
- }
538
-
539
- $bsCart->setProducts($cartItems);
540
- $client->addCart($bsCart);
541
- }
542
- } else {
543
- //empty cart -> nothing to upload
544
- }
545
- }
546
- }
547
- $result = $client->sendFullCarts();
548
- return $result;
549
- }
550
-
551
- public function trackCheckoutBegin($userId) {
552
- $key = Mage::getStoreConfig('brainsins/BSKEY');
553
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
554
 
555
- $result = $client->beginCheckout($userId);
556
- }
 
 
 
 
 
 
 
 
 
557
 
558
- public function trackCheckoutSuccess($order, $user) {
559
- $key = Mage::getStoreConfig('brainsins/BSKEY');
560
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
561
 
562
- $idOrder;
 
563
 
564
- $total = 0;
 
 
565
 
566
- $idsMultipleArray = Mage::getSingleton('core/session')->getOrderIds(true);
567
- $firstElement = true;
568
-
569
- if ($idsMultipleArray && is_array($idsMultipleArray)) {
570
- foreach ($idsMultipleArray as $id) {
571
- if ($firstElement) {
572
- $idOrder = $id;
573
- $firstElement = false;
574
- }
575
- $order = Mage::getModel('sales/order')->loadByIncrementId($id);
576
- $total += $order->getBaseSubtotalInclTax();
577
- }
578
- } else {
579
- $idOrder = $order->getIncrementId();
580
- $total = $order->getBaseSubtotalInclTax();
581
- //$total = $order->getBase_grand_total();
582
- }
583
-
584
- $result = $client->endCheckout($idOrder, $user, $total);
585
-
586
- return $result;
587
- }
588
-
589
- public function sendUpdatedUser($idUser, $email) {
590
- $key = Mage::getStoreConfig('brainsins/BSKEY');
591
- $client = Mage::getModel("recsins/client", array("server" => $this->server, "storeKey" => $key));
592
- $user = Mage::getModel('recsins/user', array('user_id' => $idUser, 'email' => $email));
593
- $res = $client->sendUser($idUser, $email);
594
- return $res;
595
- }
596
-
597
- public function checkNewUser($customer) {
598
-
599
- if (!isset($customer) || !$customer) {
600
- return;
601
- }
602
-
603
- $lastId = Mage::getStoreConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED');
604
- $idUser = $customer->getId();
605
- $email = "";
606
-
607
- if (!isset($lastId) || !$lastId || $idUser > $lastId) {
608
- Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED', $idUser);
609
- $key = Mage::getStoreConfig('brainsins/BSKEY');
610
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
611
-
612
- $subscriber = Mage::getModel("newsletter/subscriber");
613
- $subscriber->loadByCustomer($customer);
614
-
615
- if ($subscriber->isSubscribed()) {
616
- $email = $subscriber->getEmail();
617
- }
618
-
619
- $user = Mage::getModel('recsins/user', array('user_id' => $idUser, 'email' => $email));
620
-
621
- $client->addUser($user);
622
- $client->sendUsers();
623
- $res = $client->sendUserLogin($idUser, $_COOKIE['coId']);
624
-
625
- setcookie("ul", 1);
626
- setcookie("uId", $idUser);
627
-
628
- return true;
629
- } else {
630
- return false;
631
- }
632
- }
633
-
634
- public function log($message) {
635
- $pathToBsLogDir = Mage::getBaseDir('base') . "/errors/bsins";
636
-
637
- if (isset($pathToBsLogDir) && !is_dir($pathToBsLogDir)) {
638
- mkdir($pathToBsLogDir);
639
- }
640
-
641
- if (isset($pathToBsLogDir) && is_dir($pathToBsLogDir)) {
642
- $f = fopen($pathToBsLogDir . "/bslog.txt", "a");
643
- if ($f !== false) {
644
- fwrite($f, "[" . date('j-m-y H:m:s') . "] -> ");
645
- fwrite($f, $message);
646
- fwrite($f, PHP_EOL);
647
- }
648
- }
649
- }
650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
  }
2
 
3
  /*
4
  * BrainSINS' Magento Extension allows to integrate the BrainSINS
5
+ * personalized product recommendations into a Magento Store.
6
+ * Copyright (c) 2011 Social Gaming Platform S.R.L.
7
+ *
8
+ * This file is part of BrainSINS' Magento Extension.
9
+ *
10
+ * BrainSINS' Magento Extension is free software: you can redistribute it
11
+ * and/or modify it under the terms of the GNU General Public License
12
+ * as published by the Free Software Foundation, either version 3 of the
13
+ * License, or (at your option) any later version.
14
+ *
15
+ * Foobar is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22
+ *
23
+ * Please do not hesitate to contact us at info@brainsins.com
24
+ *
25
+ */
26
 
27
  class Brainsins_Recsins_Model_Recsins extends Mage_Core_Model_Abstract {
28
 
29
+ private $bsClient;
30
+ //private $dev = true;
31
+ private $dev = false;
32
+ private $server;
33
 
34
+ protected function _construct() {
35
+ parent::_construct();
36
+ $this->_init('recsins/recsins');
37
 
38
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
39
 
40
 
41
+ if ($this->dev) {
42
+ $this->server = "dev-api.brainsins.com";
43
+ } else {
44
+ $this->server = "api.brainsins.com";
45
+ }
46
 
47
+ $this->bsClient = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
48
+ }
49
 
50
+ public function importRecommenders() {
51
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
52
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
53
 
54
+ $recommenders = simplexml_load_string($client->getAllRecommenders());
55
+ $result = false;
56
+ if (isset($recommenders) && isset($recommenders->recommenders)) {
57
+ //delete previous recommenders
58
 
59
+ $recModel = Mage::getModel('recsins/recommender');
60
+ $dbRecommenders = array();
61
 
62
+ foreach ($recommenders->recommenders->recommender as $recommender) {
63
 
64
+ $dbRecommender = array();
65
+ $dbRecommender['id'] = $recommender->id_recommender;
66
+ $dbRecommender['name'] = $recommender->name;
67
+ $dbRecommender['page'] = $recommender->page;
68
 
69
+ $dbRecommenders[] = $dbRecommender;
70
+ }
71
 
72
+ $result = $recModel->setAllRecommenders($dbRecommenders);
73
+ }
74
+ return $result;
75
+ }
76
 
77
+ public function uploadCatalogUsers($pageSize, $lastPage, $firstTransaction = false) {
78
 
79
+ $lastCustomerId = 0;
80
 
81
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
82
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
83
 
84
+ $customers = Mage::getModel("customer/customer")->getCollection()->addAttributeToSelect('*')->setPage($lastPage + 1, $pageSize);
85
 
86
+ $result = true;
87
 
88
+ $firstUploadChanged = false;
89
 
90
+ foreach ($customers as $customer) {
91
 
92
+ if ($firstTransaction && !$firstUploadChanged) {
93
+ $firstUploadChanged = true;
94
+ Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_FIRST_TRANSACTION', '0');
95
+ }
96
 
97
+ $user = Mage::getModel('recsins/user', array('user_id' => $customer->getId(), 'email' => $customer->getEmail()));
98
+ $client->addUser($user);
99
+ if ($customer->getId() > $lastCustomerId) {
100
+ $lastCustomerId = $customer->getId();
101
+ }
102
+ }
103
 
104
+ $result = $client->sendUsers($firstTransaction);
105
 
106
+ $lastUploadedId = Mage::getStoreConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED');
107
 
108
+ if (!isset($lastUploadedId) || $lastUploadedId < $lastCustomerId) {
109
+ Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED', $lastCustomerId);
110
+ }
111
 
112
+ Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_LAST_PAGE_SENT', $lastPage + 1);
113
+ //Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_BS_LAST_CUSTOMER_ID_UPLOADED', $lastCustomerId);
114
 
115
+ return $result;
116
+ }
117
 
118
+ public function uploadCatalogProducts($pageSize, $lastPage, $firstTransaction = false, $uploadOutOfStock = false) {
119
+ $stores = Mage::app()->getStore()->getCollection();
120
 
121
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
122
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
123
 
124
+ $transactionCounter = 0;
125
 
126
+ $result = true;
127
 
128
+ //get first store id
129
+ $firstStoreId = $stores->getFirstItem();
130
 
131
+ if ($firstStoreId) {
132
+ $firstStoreId = $firstStoreId->getId();
133
+ } else {
134
+ return;
135
+ }
136
 
137
+ if (!isset($firstStoreId)) {
138
+ return;
139
+ }
140
 
141
+ $client->resetAll();
142
+ $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->setPage($lastPage + 1, $pageSize)->addPriceData(null, $firstStoreId);
143
 
144
+ $firstUploadChanged = false;
145
 
146
 
147
+ foreach ($products as $product) {
148
+ $id = $product->getId();
149
 
150
+ $visibility = $product->getVisibility();
151
+ $configurable_product_model = Mage::getModel('catalog/product_type_configurable');
152
+ $parentIdArray = $configurable_product_model->getParentIdsByChild($product->getId());
153
 
154
+ if (!$uploadOutOfStock && (!Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIs_in_stock() || Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty() <= 0)) {
155
+ continue;
156
+ }
157
 
158
+ if ($firstTransaction && !$firstUploadChanged) {
159
+ $firstUploadChanged = true;
160
+ Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_FIRST_TRANSACTION', '0');
161
+ }
162
 
163
+ if (count($parentIdArray) == 0 && $visibility > 1 && $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
164
 
165
+ $bsProduct = Mage::getModel('recsins/product');
166
 
167
 
168
+ $bsProduct->setIsMultilanguage(true);
169
 
170
+ $names = array();
171
+ $descriptions = array();
172
+ $urls = array();
173
+ $prices = array();
174
+ $imageUrls = array();
175
 
176
+ $bsProduct->setProduct_id($product->getId());
177
 
178
+ $categoryList = array();
179
+ $categoryIds = $product->getCategoryIds();
180
 
181
 
182
+ if (isset($categoryIds) && is_array($categoryIds)) {
183
+ foreach ($categoryIds as $catId) {
184
+ $category = Mage::getModel('catalog/category')->load($catId);
185
+ $parents = $category->getParentIds();
186
 
187
+ if (!in_array($catId, $categoryList)) {
188
+ $categoryList[] = $catId;
189
+ }
190
 
191
+ if (isset($parents) && is_array($parents)) {
192
+ foreach ($parents as $parent) {
193
+ if (!in_array($parent, $categoryList)) {
194
+ $categoryList[] = $parent;
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ $bsProduct->setCategories($categoryList);
201
 
202
+ foreach ($stores as $store) {
203
 
204
+ $storeCode = $store->getCode();
205
+ $storeId = $store->getId();
206
 
207
+ $product->setStoreId($storeId);
208
+ $product->load($id);
209
 
210
+ $price = $product->getPrice();
211
 
212
+ if ($price == 0.0 && $product->getTypeId() == "bundle") {
213
+ list($minPrice, $maxPrice) = $product->getPriceModel()->getPrices($product);
214
+ $price = $minPrice;
215
+ }
216
 
217
+ $prices[$storeCode] = $price;
218
+ $useSpecialPrice = Mage::getStoreConfig('brainsins/BS_USE_SPECIAL_PRICE');
219
+ if (isset($useSpecialPrice) && $useSpecialPrice == '1') {
220
+
221
+ $specialPrice = $product->getSpecialPrice();
222
+ if (isset($specialPrice) && $specialPrice) {
223
+
224
+ $specialFrom = $product->getSpecialFromDate();
225
+ $specialTo = $product->getSpecialToDate();
226
+ $specialFromTS;
227
+ $specialToTS;
228
+
229
+ $nowTS = time();
230
+
231
+ $specialValidRange = true;
232
+
233
+ if (isset($specialFrom)) {
234
+ $specialFromTS = strtotime($specialFrom);
235
+ if ($specialFromTS > $nowTS) {
236
+ $specialValidRange = false;
237
+ }
238
+ }
239
+
240
+ if (isset($specialTo)) {
241
+ $specialToTS = strtotime($specialTo);
242
+ if ($specialToTS < $nowTS) {
243
+ $specialValidRange = false;
244
+ }
245
+ }
246
+
247
+ if ($specialValidRange && $product->getTypeId() != "bundle") {
248
+ $prices[$storeCode] = $specialPrice;
249
+ }
250
+ }
251
+ }
252
+
253
+
254
+ $resize = false;
255
+ $width = 0;
256
+ $heigth = 0;
257
+
258
+ $imageSelectedOption = Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_BS_IMAGE_RESIZE');
259
+ if (isset($imageSelectedOption) && $imageSelectedOption == 'image_resize') {
260
+ $resize = true;
261
+ }
262
+
263
+ $imageSelectedWidth = Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_BS_IMAGE_RESIZE_WIDTH');
264
+ $imageSelectedHeigth = Mage::getSingleton("core/session", array("name" => "adminhtml"))->getData('brainsins_BS_IMAGE_RESIZE_HEIGTH');
265
+
266
+ if (isset($imageSelectedWidth) && is_numeric($imageSelectedWidth) && $imageSelectedWidth > 0) {
267
+ $width = $imageSelectedWidth;
268
+ }
269
+
270
+ if (isset($imageSelectedHeigth) && is_numeric($imageSelectedHeigth) && $imageSelectedHeigth > 0) {
271
+ $heigth = $imageSelectedHeigth;
272
+ }
273
+
274
+ if ($resize && $width > 0) {
275
+ $prodImage = $product->getSmallImage();
276
+ if (isset($prodImage) && $prodImage != null && $prodImage != "no_selection") {
277
+ if ($heigth > 0) {
278
+ $imageUrls[$storeCode] = ((string) Mage::helper('catalog/image')->init($product, "small_image")->resize($width, $heigth));
279
+ } else {
280
+ $imageUrls[$storeCode] = ((string) Mage::helper('catalog/image')->init($product, "small_image")->resize($width));
281
+ }
282
+ }
283
+ } else {
284
+ $prodImage = $product->getSmallImage();
285
+ if (isset($prodImage) && $prodImage != null && $prodImage != "no_selection") {
286
+
287
+ $img = Mage::getModel("catalog/product_image");
288
+ $img->setDestinationSubdir("small_image");
289
+ $img->setBaseFile($prodImage);
290
+
291
+ $baseDir = Mage::getBaseDir('media');
292
+ $path = str_replace($baseDir . DS, "", $img->getBaseFile());
293
+ $url = $store->getBaseUrl('media') . str_replace(DS, '/', $path);
294
+ $imageUrls[$storeCode] = $url;
295
+ }
296
+ }
297
+
298
+ //if resize is selected, override image url with controller call. Previous code will leave a copy of the image ready in the cache
299
+ if ($resize) {
300
+ $imageUrls[$storeCode] = $store->getBaseUrl() . "recsins/index/getRecProdImg?id=" . $id;
301
+ }
302
+ $names[$storeCode] = utf8_decode($product->getName());
303
+ $descriptions[$storeCode] = utf8_decode($product->getShortDescription());
304
+ $urls[$storeCode] = $product->getProductUrl();
305
+ }
306
+
307
+ $bsProduct->setNames($names);
308
+ $bsProduct->setDescriptions($descriptions);
309
+ $bsProduct->setUrls($urls);
310
+ $bsProduct->setPrices($prices);
311
+ $bsProduct->setImageUrls($imageUrls);
312
+
313
+ $client->addProduct($bsProduct);
314
+ } else {
315
+ //this product is a configuration of a more general product(id)
316
+ // or a non visible product
317
+ }
318
+ }
319
+ Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_LAST_PAGE_SENT', $lastPage + 1);
320
+ $result = $client->sendProducts($firstTransaction);
321
+ return $result;
322
+ }
323
+
324
+ private function getNextFakeId($lastFakeId) {
325
+ if (!isset($lastFakeId) || $lastFakeId == 0) {
326
+ return 999999999999;
327
+ } else {
328
+ return $lastFakeId - 1;
329
+ }
330
+ }
331
+
332
+ public function uploadCatalogQuotes($pageSize, $lastPage, $lastFakeId = 0, $firstTransaction = false) {
333
+
334
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
335
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
336
+
337
+ $quotes = Mage::getModel('sales/quote')->getCollection()->setPageSize($pageSize)->setCurPage($lastPage + 1); //($lastPage + 1, 1);
338
+ foreach ($quotes as $quote) {
339
+
340
+ $quote->load($quote->getId());
341
+ $items = $quote->getAllItems();
342
+ $idCustomer = $quote->getCustomerId();
343
+
344
+ if (!isset($idCustomer)) {
345
+ $lastFakeId = $this->getNextFakeId($lastFakeId);
346
+ $idCustomer = $lastFakeId;
347
+ }
348
+ $bsCart = Mage::getModel('recsins/cart');
349
+ $bsCart->setIdCart($quote->getId());
350
+ $bsCart->setIdUser($idCustomer);
351
+ $bsCart->setStartDate($quote->getCreated_at());
352
+ $bsCart->setFinishDate($quote->getUpdated_at());
353
+
354
+ $cartItems = array();
355
+ foreach ($items as $item) {
356
+
357
+ if ($item->getParentItemId()) {
358
+ continue;
359
+ }
360
+
361
+ //TODO ? $product = $item->getProduct();
362
+ $qty = $item->getQty();
363
+ $price = $item->getPrice();
364
+ $idProduct = $item->getProduct_id();
365
+
366
+ if (array_key_exists($idProduct, $cartItems)) {
367
+ $newQty = $cartItems[$idProduct]['qty'] + $qty;
368
+ $newPrice = ($cartItems[$idProduct]['price'] * $cartItems[$idProduct]['qty'] + $price * $qty) / $newQty;
369
+ $cartItems[$idProduct]['qty'] = $newQty;
370
+ $cartItems[$idProduct]['price'] = $newPrice;
371
+ } else {
372
+ $cartItems[$idProduct] = array();
373
+ $cartItems[$idProduct]['qty'] = $qty;
374
+ $cartItems[$idProduct]['price'] = $price;
375
+ }
376
+ }
377
+
378
+ $bsCart->setProducts($cartItems);
379
+ $client->addCart($bsCart);
380
+ }
381
+
382
+ Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_LAST_PAGE_SENT', $lastPage + 1);
383
+ Mage::getSingleton("core/session", array("name" => "adminhtml"))->setData('brainsins_BS_LAST_FAKE_ID', $lastFakeId);
384
+ return $client->sendCatalogCarts($firstTransaction);
385
+ }
386
+
387
+ public function uploadCatalogOrders($pageSize, $lastPage, $lastFakeId, $firstTransaction = false) {
388
+
389
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
390
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
391
+
392
+ $orders = Mage::getModel('sales/order')->getCollection()->setPageSize($pageSize)->setCurPage($lastPage + 1);
393
+
394
+ foreach ($orders as $order) {
395
+
396
+ $order->load($order->getId());
397
+ $idCustomer = $order->getCustomer_id();
398
+ $quoteId = $order->getQuote_id();
399
+
400
+ if (!isset($idCustomer)) {
401
+ $idCustomer = $this->getNextFakeId($lastFakeId);
402
+ }
403
+
404
+ $bsOrder = Mage::getModel('recsins/order');
405
+ $bsOrder->setIdPurchase($order->getIncrementId());
406
+ $bsOrder->setIdCart($quoteId);
407
+ $bsOrder->setIdUser($idCustomer);
408
+ $bsOrder->setDate($order->getCreated_at());
409
+ $bsOrder->setAmount($order->getSubtotal());
410
+
411
+ $bsCart = Mage::getModel('recsins/cart');
412
+ $bsCart->setIdCart($quoteId);
413
+ $bsCart->setIdUser($idCustomer);
414
+ $bsCart->setStartDate($order->getCreated_at());
415
+ $bsCart->setFinishDate($order->getCreated_at());
416
+
417
+ $orderItems = array();
418
+ $cartItems = array();
419
 
420
+ $items = $order->getAllItems();
421
+ foreach ($items as $item) {
422
 
423
+ if ($item->getParentItemId()) {
424
+ continue;
425
+ }
426
 
427
+ $idProduct = $item->getProduct_id();
428
+ $price = $item->getPrice();
429
+ $qty = (int) $item->getQty_ordered();
430
 
431
+ if (array_key_exists($idProduct, $orderItems)) {
432
+ $newQty = $orderItems[$idProduct]['qty'] + $qty;
433
+ $newPrice = ($orderItems[$idProduct]['price'] * $orderItems[$idProduct]['qty'] + $price * $qty) / $newQty;
434
+ $orderItems[$idProduct]['qty'] = $newQty;
435
+ $orderItems[$idProduct]['price'] = $newPrice;
436
+ $cartItems[$idProduct]['qty'] = $newQty;
437
+ $cartItems[$idProduct]['price'] = $newPrice;
438
+ } else {
439
+ $orderItems[$idProduct] = array();
440
+ $cartItems[$idProduct] = array();
441
+ $orderItems[$idProduct]['qty'] = $qty;
442
+ $orderItems[$idProduct]['price'] = $price;
443
+ $cartItems[$idProduct]['qty'] = $qty;
444
+ $cartItems[$idProduct]['price'] = $price;
445
+ }
446
+ }
447
+
448
+ $bsCart->setProducts($cartItems);
449
+ $bsOrder->setProducts($orderItems);
450
 
451
+ $client->addCart($bsCart);
452
+ $client->addOrder($bsOrder);
453
+ }
454
 
455
+ $result = $client->sendCatalogCarts();
456
+ $result = $result && $client->sendCatalogPurchases($firstTransaction);
457
 
458
+ Mage::getModel('core/config')->saveConfig('brainsins/LAST_PAGE_SENT', $lastPage + 1);
459
+ Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_FAKE_ID', $lastFakeId);
460
+ return $result;
461
+ }
462
 
463
+ public function uploadQuotes($quotes, $userId = null) {
464
 
465
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
466
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
467
 
468
+ foreach ($quotes as $quote) {
469
 
470
+ $orderId = $quote->getOrig_order_id();
471
+ if ($orderId == 0) {
472
+ $orderId = $quote->getReserved_order_id();
473
+ }
474
 
475
+ if ($orderId == 0) {
476
+ $items = $quote->getAllItems();
477
 
478
+ if (count($items) > 0) {
479
+ $idCustomer = $userId ? $userId : $quote->getCustomer()->getId();
480
+ if ($idCustomer) {
481
 
482
+ $cartCustomerId = $userId ? $userId : $quote->getCustomer()->getId();
483
 
484
+ $bsCart = Mage::getModel('recsins/cart');
485
+ $bsCart->setIdCart($quote->getId());
486
+ $bsCart->setUserId($cartCustomerId);
487
 
488
+ $bsCart->setStart_date($quote->getCreated_at());
489
+ $bsCart->setFinish_date($quote->getUpdated_at());
490
+ $cartItems = array();
491
 
492
 
493
+ foreach ($items as $item) {
494
+ if ($item->getParentItemId()) {
495
+ continue;
496
+ }
497
+
498
+ $qty = $item->getQty();
499
+ $price = $item->getBasePriceInclTax();
500
+
501
+
502
+ $product = $item->getProduct();
503
+
504
+ $productId = $product->getId();
505
+ $configurable_product_model = Mage::getModel('catalog/product_type_configurable');
506
+ $parentIdArray = $configurable_product_model->getParentIdsByChild($productId);
507
+
508
+ $found = false;
509
+
510
+ foreach ($cartItems as $storedItem) {
511
+
512
+ if ($productId == $storedItem->getProduct_id()) {
513
+
514
+ $storedQty = $storedItem->getQuantity();
515
+ $storedPrice = $storedItem->getPrice();
516
+
517
+ $newQty = $storedQty + $qty;
518
+ $newPrice = ($storedPrice * $storedQty + $price * $qty) / $newQty;
519
+
520
+ $storedItem->setQuantity($newQty);
521
+ $storedItem->setPrice($newPrice);
522
+
523
+ $found = true;
524
+ break;
525
+ }
526
+ }
527
+
528
+ if (!$found) {
529
+ $cartItem = Mage::getModel('recsins/cartProduct');
530
+
531
+ $cartItem->setProduct_id($productId);
532
+ $cartItem->setQuantity($qty);
533
+ $cartItem->setPrice($price);
534
+
535
+ $cartItems[] = $cartItem;
536
+ }
537
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
538
 
539
+ $bsCart->setProducts($cartItems);
540
+ $client->addCart($bsCart);
541
+ }
542
+ } else {
543
+ //empty cart -> nothing to upload
544
+ }
545
+ }
546
+ }
547
+ $result = $client->sendFullCarts();
548
+ return $result;
549
+ }
550
 
551
+ public function trackCheckoutBegin($userId) {
552
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
553
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
554
 
555
+ $result = $client->beginCheckout($userId);
556
+ }
557
 
558
+ public function trackCheckoutSuccess($order, $user) {
559
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
560
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
561
 
562
+ $idOrder;
563
+
564
+ $total = 0;
565
+
566
+ $idsMultipleArray = Mage::getSingleton('core/session')->getOrderIds(true);
567
+ $firstElement = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
 
569
+ if ($idsMultipleArray && is_array($idsMultipleArray)) {
570
+ foreach ($idsMultipleArray as $id) {
571
+ if ($firstElement) {
572
+ $idOrder = $id;
573
+ $firstElement = false;
574
+ }
575
+ $order = Mage::getModel('sales/order')->loadByIncrementId($id);
576
+ $total += $order->getBaseSubtotalInclTax();
577
+ }
578
+ } else {
579
+ $idOrder = $order->getIncrementId();
580
+ $total = $order->getBaseSubtotalInclTax();
581
+ //$total = $order->getBase_grand_total();
582
+ }
583
+
584
+ $result = $client->endCheckout($idOrder, $user, $total);
585
+
586
+ return $result;
587
+ }
588
+
589
+ public function sendUpdatedUser($idUser, $email) {
590
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
591
+ $client = Mage::getModel("recsins/client", array("server" => $this->server, "storeKey" => $key));
592
+ $user = Mage::getModel('recsins/user', array('user_id' => $idUser, 'email' => $email));
593
+ $res = $client->sendUser($idUser, $email);
594
+ return $res;
595
+ }
596
+
597
+ public function checkNewUser($customer) {
598
+
599
+ if (!isset($customer) || !$customer) {
600
+ return;
601
+ }
602
+
603
+ $lastId = Mage::getStoreConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED');
604
+ $idUser = $customer->getId();
605
+ $email = "";
606
+
607
+ if (!isset($lastId) || !$lastId || $idUser > $lastId) {
608
+ Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED', $idUser);
609
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
610
+ $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
611
+
612
+ $subscriber = Mage::getModel("newsletter/subscriber");
613
+ $subscriber->loadByCustomer($customer);
614
+
615
+ if ($subscriber->isSubscribed()) {
616
+ $email = $subscriber->getEmail();
617
+ }
618
+
619
+ $user = Mage::getModel('recsins/user', array('user_id' => $idUser, 'email' => $email));
620
+
621
+ $client->addUser($user);
622
+ $client->sendUsers();
623
+ $res = $client->sendUserLogin($idUser, $_COOKIE['coId']);
624
+
625
+ setcookie("ul", 1);
626
+ setcookie("uId", $idUser);
627
+
628
+ return true;
629
+ } else {
630
+ return false;
631
+ }
632
+ }
633
+
634
+ public function requestRecommendations($recommenderId, $productId, $clientId, $lang, $divName, $categories, $filter) {
635
+
636
+ $key = Mage::getStoreConfig('brainsins/BSKEY');
637
+
638
+ $url = "http://recommender.brainsins.com/recommender.php";
639
+
640
+ $url .= "?token=" . $key;
641
+ $url .= "&userId=" . $clientId;
642
+
643
+ $url .= "&recId=" . $recommenderId;
644
+
645
+ if (isset($productId) && $productId != "") {
646
+ $url .= "&prodId=" . $productId;
647
+ }
648
+
649
+ if (isset($lang) && $lang != "") {
650
+ $url .= "&lang=" . $lang;
651
+ }
652
+
653
+ $url .= "&dN=" . $divName;
654
+
655
+ if (isset($categories) && $categories != "") {
656
+ $url .= "&cat=" . $categories;
657
+ }
658
+
659
+ if (isset($filter) && $filter != "") {
660
+ $url .= "&filter=" . $filter;
661
+ }
662
+ $curl = curl_init();
663
+ curl_setopt($curl, CURLOPT_URL, $url);
664
+ $timeout = 2;
665
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
666
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
667
+ curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/plain", "Accept: text/plain"));
668
+ $result = curl_exec($curl);
669
+ curl_close($curl);
670
+ return($result);
671
+
672
+ }
673
+
674
+ public function log($message) {
675
+ $pathToBsLogDir = Mage::getBaseDir('base') . "/errors/bsins";
676
+
677
+ if (isset($pathToBsLogDir) && !is_dir($pathToBsLogDir)) {
678
+ mkdir($pathToBsLogDir);
679
+ }
680
+
681
+ if (isset($pathToBsLogDir) && is_dir($pathToBsLogDir)) {
682
+ $f = fopen($pathToBsLogDir . "/bslog.txt", "a");
683
+ if ($f !== false) {
684
+ fwrite($f, "[" . date('j-m-y H:m:s') . "] -> ");
685
+ fwrite($f, $message);
686
+ fwrite($f, PHP_EOL);
687
+ }
688
+ }
689
+ }
690
  }
app/code/community/Brainsins/Recsins/Model/Recsins_1.php DELETED
@@ -1,569 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * BrainSINS' Magento Extension allows to integrate the BrainSINS
5
- * personalized product recommendations into a Magento Store.
6
- * Copyright (c) 2011 Social Gaming Platform S.R.L.
7
- *
8
- * This file is part of BrainSINS' Magento Extension.
9
- *
10
- * BrainSINS' Magento Extension is free software: you can redistribute it
11
- * and/or modify it under the terms of the GNU General Public License
12
- * as published by the Free Software Foundation, either version 3 of the
13
- * License, or (at your option) any later version.
14
- *
15
- * Foobar is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22
- *
23
- * Please do not hesitate to contact us at info@brainsins.com
24
- *
25
- */
26
-
27
- class Brainsins_Recsins_Model_Recsins extends Mage_Core_Model_Abstract {
28
-
29
- private $bsClient;
30
- //private $dev = true;
31
- private $dev = false;
32
- private $server;
33
-
34
- protected function _construct() {
35
- parent::_construct();
36
- $this->_init('recsins/recsins');
37
-
38
- $key = Mage::getStoreConfig('brainsins/BSKEY');
39
-
40
-
41
- if ($this->dev) {
42
- $this->server = "dev-api.brainsins.com";
43
- } else {
44
- $this->server = "api.brainsins.com";
45
- }
46
-
47
- $this->bsClient = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
48
- }
49
-
50
- public function importRecommenders() {
51
- $key = Mage::getStoreConfig('brainsins/BSKEY');
52
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
53
-
54
- $recommenders = simplexml_load_string($client->getAllRecommenders());
55
- $result = false;
56
- if (isset($recommenders) && isset($recommenders->recommenders)) {
57
- //delete previous recommenders
58
-
59
- $collection = Mage::getModel('recsins/recommender')->getCollection();
60
-
61
- foreach ($collection as $recModel) {
62
- $recModel->delete();
63
- }
64
-
65
- foreach ($recommenders->recommenders->recommender as $recommender) {
66
-
67
- $recModel = Mage::getModel('recsins/recommender');
68
- $recModel->setRecommender_id($recommender->id_recommender);
69
- $recModel->setRecommender_name($recommender->name);
70
- $recModel->setRecommender_page($recommender->page);
71
-
72
- $recModel->save();
73
- }
74
-
75
- $result = true;
76
- }
77
- return $result;
78
- }
79
-
80
- public function uploadCatalogUsers($pageSize, $lastPage, $firstTransaction = false) {
81
-
82
- $lastCustomerId = 0;
83
-
84
- $key = Mage::getStoreConfig('brainsins/BSKEY');
85
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
86
-
87
- $customers = Mage::getModel("customer/customer")->getCollection()->addAttributeToSelect('*')->setPage($lastPage + 1, $pageSize);
88
-
89
- $result = true;
90
-
91
- $firstUploadChanged = false;
92
-
93
- foreach ($customers as $customer) {
94
-
95
- if ($firstTransaction && !$firstUploadChanged) {
96
- $firstUploadChanged = true;
97
- Mage::getModel('core/config')->saveConfig('brainsins/FIRST_TRANSACTION', '0');
98
- }
99
-
100
- $user = Mage::getModel('recsins/user', array('user_id' => $customer->getId(), 'email' => $customer->getEmail()));
101
- $client->addUser($user);
102
- }
103
-
104
- $result = $client->sendUsers($firstTransaction);
105
- Mage::getModel('core/config')->saveConfig('brainsins/LAST_PAGE_SENT', $lastPage + 1);
106
- Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED', $lastCustomerId);
107
-
108
- return $result;
109
- }
110
-
111
- public function uploadCatalogProducts($pageSize, $lastPage, $firstTransaction = false, $uploadOutOfStock = false) {
112
- $stores = Mage::app()->getStore()->getCollection();
113
-
114
- $key = Mage::getStoreConfig('brainsins/BSKEY');
115
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
116
-
117
- $transactionCounter = 0;
118
-
119
- $result = true;
120
-
121
- //get first store id
122
- $firstStoreId = $stores->getFirstItem();
123
-
124
- if ($firstStoreId) {
125
- $firstStoreId = $firstStoreId->getId();
126
- } else {
127
- return;
128
- }
129
-
130
- if (!isset($firstStoreId)) {
131
- return;
132
- }
133
-
134
- $client->resetAll();
135
- $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->setPage($lastPage + 1, $pageSize)->addPriceData(null, $firstStoreId);
136
-
137
- $firstUploadChanged = false;
138
-
139
-
140
- foreach ($products as $product) {
141
- $id = $product->getId();
142
-
143
- $visibility = $product->getVisibility();
144
- $configurable_product_model = Mage::getModel('catalog/product_type_configurable');
145
- $parentIdArray = $configurable_product_model->getParentIdsByChild($product->getId());
146
-
147
- if (!$uploadOutOfStock && (!Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIs_in_stock() || Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty() <= 0)) {
148
- continue;
149
- }
150
-
151
- if ($firstTransaction && !$firstUploadChanged) {
152
- $firstUploadChanged = true;
153
- Mage::getModel('core/config')->saveConfig('brainsins/FIRST_TRANSACTION', '0');
154
- }
155
-
156
-
157
- if (count($parentIdArray) == 0 && $visibility > 1 && $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
158
-
159
- $bsProduct = Mage::getModel('recsins/product');
160
-
161
-
162
- $bsProduct->setIsMultilanguage(true);
163
-
164
- $names = array();
165
- $descriptions = array();
166
- $urls = array();
167
-
168
- $bsProduct->setProduct_id($product->getId());
169
- $bsProduct->setPrice($product->getPrice());
170
-
171
- if ($product->getPrice() == 0.0 && $product->getTypeId() == "bundle") {
172
- list($minPrice, $maxPrice) = $product->getPriceModel()->getPrices($product);
173
- $bsProduct->setPrice($minPrice);
174
- }
175
-
176
- $categoryList = array();
177
- $categoryIds = $product->getCategoryIds();
178
-
179
-
180
- if (isset($categoryIds) && is_array($categoryIds)) {
181
- foreach ($categoryIds as $catId) {
182
- $category = Mage::getModel('catalog/category')->load($catId);
183
- $parents = $category->getParentIds();
184
-
185
- if (!in_array($catId, $categoryList)) {
186
- $categoryList[] = $catId;
187
- }
188
-
189
- if (isset($parents) && is_array($parents)) {
190
- foreach ($parents as $parent) {
191
- if (!in_array($parent, $categoryList)) {
192
- $categoryList[] = $parent;
193
- }
194
- }
195
- }
196
- //$categoryList = array_unique(array_merge($categoryList, $parents));
197
- }
198
- }
199
- $bsProduct->setCategories($categoryList);
200
-
201
- //TODO depends on a parameter!!!
202
- $resize = false;
203
- $width = 0;
204
- $heigth = 0;
205
-
206
- $imageSelectedOption = Mage::getStoreConfig('brainsins/BS_IMAGE_RESIZE');
207
- if (isset($imageSelectedOption) && $imageSelectedOption == 'image_resize') {
208
- $resize = true;
209
- }
210
-
211
- $imageSelectedWidth = Mage::getStoreConfig('brainsins/BS_IMAGE_RESIZE_WIDTH');
212
- $imageSelectedHeigth = Mage::getStoreConfig('brainsins/BS_IMAGE_RESIZE_HEIGTH');
213
-
214
- if (isset($imageSelectedWidth) && is_numeric($imageSelectedWidth) && $imageSelectedWidth > 0) {
215
- $width = $imageSelectedWidth;
216
- }
217
-
218
- if (isset($imageSelectedHeigth) && is_numeric($imageSelectedHeigth) && $imageSelectedHeigth > 0) {
219
- $heigth = $imageSelectedHeigth;
220
- }
221
-
222
- if ($resize && $width > 0) {
223
- $prodImage = $product->getSmallImage();
224
- if (isset($prodImage) && $prodImage != null && $prodImage != "no_selection") {
225
- if ($heigth > 0) {
226
- $bsProduct->setImage_url((string)Mage::helper('catalog/image')->init($product, "image")->resize($width, $heigth));
227
- } else {
228
- $bsProduct->setImage_url((string)Mage::helper('catalog/image')->init($product, "image")->resize($width));
229
- }
230
- }
231
- } else {
232
- $prodImage = $product->getSmallImage();
233
- if (isset($prodImage) && $prodImage != null && $prodImage != "no_selection") {
234
- $bsProduct->setImage_url((string)Mage::helper('catalog/image')->init($product, "image"));
235
- }
236
- }
237
-
238
- foreach ($stores as $store) {
239
- $storeCode = $store->getCode();
240
- $storeId = $store->getId();
241
-
242
- $product->setStoreId($storeId);
243
- $product->load($id);
244
-
245
- $names[$storeCode] = utf8_decode($product->getName());
246
- $descriptions[$storeCode] = utf8_decode($product->getShortDescription());
247
- $urls[$storeCode] = $product->getProductUrl();
248
- }
249
-
250
- $bsProduct->setNames($names);
251
- $bsProduct->setDescriptions($descriptions);
252
- $bsProduct->setUrls($urls);
253
-
254
- $client->addProduct($bsProduct);
255
- } else {
256
- //this product is a configuration of a more general product(id)
257
- // or a non visible product
258
- }
259
- }
260
- Mage::getModel('core/config')->saveConfig('brainsins/LAST_PAGE_SENT', $lastPage + 1);
261
- $result = $client->sendProducts($firstTransaction);
262
- return $result;
263
- }
264
-
265
- private function getNextFakeId($lastFakeId) {
266
- if (!isset($lastFakeId) || $lastFakeId == 0) {
267
- return 999999999999;
268
- } else {
269
- return $lastFakeId - 1;
270
- }
271
- }
272
-
273
- public function uploadCatalogQuotes($pageSize, $lastPage, $lastFakeId = 0, $firstTransaction = false) {
274
-
275
- $key = Mage::getStoreConfig('brainsins/BSKEY');
276
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
277
-
278
- $quotes = Mage::getModel('sales/quote')->getCollection()->setPageSize($pageSize)->setCurPage($lastPage + 1); //($lastPage + 1, 1);
279
- foreach ($quotes as $quote) {
280
-
281
- $quote->load($quote->getId());
282
- $items = $quote->getAllItems();
283
- $idCustomer = $quote->getCustomerId();
284
-
285
- if (!isset($idCustomer)) {
286
- $lastFakeId = $this->getNextFakeId($lastFakeId);
287
- $idCustomer = $lastFakeId;
288
- }
289
- $bsCart = Mage::getModel('recsins/cart');
290
- $bsCart->setIdCart($quote->getId());
291
- $bsCart->setIdUser($idCustomer);
292
- $bsCart->setStartDate($quote->getCreated_at());
293
- $bsCart->setFinishDate($quote->getUpdated_at());
294
-
295
- $cartItems = array();
296
- foreach ($items as $item) {
297
-
298
- if ($item->getParentItemId()) {
299
- continue;
300
- }
301
-
302
- //TODO ? $product = $item->getProduct();
303
- $qty = $item->getQty();
304
- $price = $item->getPrice();
305
- $idProduct = $item->getProduct_id();
306
-
307
- if (array_key_exists($idProduct, $cartItems)) {
308
- $newQty = $cartItems[$idProduct]['qty'] + $qty;
309
- $newPrice = ($cartItems[$idProduct]['price'] * $cartItems[$idProduct]['qty'] + $price * $qty) / $newQty;
310
- $cartItems[$idProduct]['qty'] = $newQty;
311
- $cartItems[$idProduct]['price'] = $newPrice;
312
- } else {
313
- $cartItems[$idProduct] = array();
314
- $cartItems[$idProduct]['qty'] = $qty;
315
- $cartItems[$idProduct]['price'] = $price;
316
- }
317
- }
318
-
319
- $bsCart->setProducts($cartItems);
320
- $client->addCart($bsCart);
321
- }
322
-
323
- Mage::getModel('core/config')->saveConfig('brainsins/LAST_PAGE_SENT', $lastPage + 1);
324
- Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_FAKE_ID', $lastFakeId);
325
- return $client->sendCatalogCarts($firstTransaction);
326
- }
327
-
328
- public function uploadCatalogOrders($pageSize, $lastPage, $lastFakeId, $firstTransaction = false) {
329
-
330
- $key = Mage::getStoreConfig('brainsins/BSKEY');
331
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
332
-
333
- $orders = Mage::getModel('sales/order')->getCollection()->setPageSize($pageSize)->setCurPage($lastPage + 1);
334
-
335
- foreach ($orders as $order) {
336
-
337
- $order->load($order->getId());
338
- $idCustomer = $order->getCustomer_id();
339
- $quoteId = $order->getQuote_id();
340
-
341
- if (!isset($idCustomer)) {
342
- $idCustomer = $this->getNextFakeId($lastFakeId);
343
- }
344
-
345
- $bsOrder = Mage::getModel('recsins/order');
346
- $bsOrder->setIdPurchase($order->getIncrementId());
347
- $bsOrder->setIdCart($quoteId);
348
- $bsOrder->setIdUser($idCustomer);
349
- $bsOrder->setDate($order->getCreated_at());
350
- $bsOrder->setAmount($order->getSubtotal());
351
-
352
- $bsCart = Mage::getModel('recsins/cart');
353
- $bsCart->setIdCart($quoteId);
354
- $bsCart->setIdUser($idCustomer);
355
- $bsCart->setStartDate($order->getCreated_at());
356
- $bsCart->setFinishDate($order->getCreated_at());
357
-
358
- $orderItems = array();
359
- $cartItems = array();
360
-
361
- $items = $order->getAllItems();
362
- foreach ($items as $item) {
363
-
364
- if ($item->getParentItemId()) {
365
- continue;
366
- }
367
-
368
- $idProduct = $item->getProduct_id();
369
- $price = $item->getPrice();
370
- $qty = (int) $item->getQty_ordered();
371
-
372
- if (array_key_exists($idProduct, $orderItems)) {
373
- $newQty = $orderItems[$idProduct]['qty'] + $qty;
374
- $newPrice = ($orderItems[$idProduct]['price'] * $orderItems[$idProduct]['qty'] + $price * $qty) / $newQty;
375
- $orderItems[$idProduct]['qty'] = $newQty;
376
- $orderItems[$idProduct]['price'] = $newPrice;
377
- $cartItems[$idProduct]['qty'] = $newQty;
378
- $cartItems[$idProduct]['price'] = $newPrice;
379
- } else {
380
- $orderItems[$idProduct] = array();
381
- $cartItems[$idProduct] = array();
382
- $orderItems[$idProduct]['qty'] = $qty;
383
- $orderItems[$idProduct]['price'] = $price;
384
- $cartItems[$idProduct]['qty'] = $qty;
385
- $cartItems[$idProduct]['price'] = $price;
386
- }
387
- }
388
-
389
- $bsCart->setProducts($cartItems);
390
- $bsOrder->setProducts($orderItems);
391
-
392
- $client->addCart($bsCart);
393
- $client->addOrder($bsOrder);
394
- }
395
-
396
- $result = $client->sendCatalogCarts();
397
- $result = $result && $client->sendCatalogPurchases($firstTransaction);
398
-
399
- Mage::getModel('core/config')->saveConfig('brainsins/LAST_PAGE_SENT', $lastPage + 1);
400
- Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_FAKE_ID', $lastFakeId);
401
- return $result;
402
- }
403
-
404
- public function uploadQuotes($quotes, $userId = null) {
405
-
406
- $key = Mage::getStoreConfig('brainsins/BSKEY');
407
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
408
-
409
- foreach ($quotes as $quote) {
410
-
411
- $orderId = $quote->getOrig_order_id();
412
- if ($orderId == 0) {
413
- $orderId = $quote->getReserved_order_id();
414
- }
415
-
416
- if ($orderId == 0) {
417
- $items = $quote->getAllItems();
418
-
419
- if (count($items) > 0) {
420
- $idCustomer = $userId ? $userId : $quote->getCustomer()->getId();
421
- if ($idCustomer) {
422
-
423
- $cartCustomerId = $userId ? $userId : $quote->getCustomer()->getId();
424
-
425
- $bsCart = Mage::getModel('recsins/cart');
426
- $bsCart->setIdCart($quote->getId());
427
- $bsCart->setUserId($cartCustomerId);
428
-
429
- $bsCart->setStart_date($quote->getCreated_at());
430
- $bsCart->setFinish_date($quote->getUpdated_at());
431
- $cartItems = array();
432
-
433
-
434
- foreach ($items as $item) {
435
- if ($item->getParentItemId()) {
436
- continue;
437
- }
438
-
439
- $qty = $item->getQty();
440
- $price = $item->getPrice();
441
-
442
-
443
- $product = $item->getProduct();
444
-
445
- $productId = $product->getId();
446
- $configurable_product_model = Mage::getModel('catalog/product_type_configurable');
447
- $parentIdArray = $configurable_product_model->getParentIdsByChild($productId);
448
-
449
- $found = false;
450
-
451
- foreach ($cartItems as $storedItem) {
452
-
453
- if ($productId == $storedItem->getProduct_id()) {
454
-
455
- $storedQty = $storedItem->getQuantity();
456
- $storedPrice = $storedItem->getPrice();
457
-
458
- $newQty = $storedQty + $qty;
459
- $newPrice = ($storedPrice * $storedQty + $price * $qty) / $newQty;
460
-
461
- $storedItem->setQuantity($newQty);
462
- $storedItem->setPrice($newPrice);
463
-
464
- $found = true;
465
- break;
466
- }
467
- }
468
-
469
- if (!$found) {
470
- $cartItem = Mage::getModel('recsins/cartProduct');
471
-
472
- $cartItem->setProduct_id($productId);
473
- $cartItem->setQuantity($qty);
474
- $cartItem->setPrice($price);
475
-
476
- $cartItems[] = $cartItem;
477
- }
478
- }
479
-
480
- $bsCart->setProducts($cartItems);
481
- $client->addCart($bsCart);
482
- }
483
- } else {
484
- //empty cart -> nothing to upload
485
- }
486
- }
487
- }
488
- $result = $client->sendFullCarts();
489
- return $result;
490
- }
491
-
492
- public function trackCheckoutBegin($userId) {
493
- $key = Mage::getStoreConfig('brainsins/BSKEY');
494
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
495
-
496
- $result = $client->beginCheckout($userId);
497
- }
498
-
499
- public function trackCheckoutSuccess($order, $user) {
500
- $key = Mage::getStoreConfig('brainsins/BSKEY');
501
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
502
-
503
- $idOrder;
504
-
505
- $total = 0;
506
-
507
- $idsMultipleArray = Mage::getSingleton('core/session')->getOrderIds(true);
508
- $firstElement = true;
509
-
510
- if ($idsMultipleArray && is_array($idsMultipleArray)) {
511
- foreach ($idsMultipleArray as $id) {
512
- if ($firstElement) {
513
- $idOrder = $id;
514
- $firstElement = false;
515
- }
516
- $order = Mage::getModel('sales/order')->loadByIncrementId($id);
517
- $total += $order->getSubtotal();
518
- }
519
- } else {
520
- $idOrder = $order->getIncrementId();
521
- $total = $order->getSubtotal();
522
- //$total = $order->getBase_grand_total();
523
- }
524
-
525
- $result = $client->endCheckout($idOrder, $user, $total);
526
-
527
- return $result;
528
- }
529
-
530
- public function checkNewUser($idUser, $email) {
531
- $lastId = Mage::getStoreConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED');
532
-
533
- if (!$lastId || $idUser > $lastId) {
534
- Mage::getModel('core/config')->saveConfig('brainsins/BS_LAST_CUSTOMER_ID_UPLOADED', $idUser);
535
- $key = Mage::getStoreConfig('brainsins/BSKEY');
536
- $client = Mage::getSingleton("recsins/client", array("server" => $this->server, "storeKey" => $key));
537
- $user = Mage::getModel('recsins/user', array('user_id' => $idUser, 'email' => $email));
538
-
539
- $client->addUser($user);
540
- $client->sendUsers();
541
- $res = $client->sendUserLogin($idUser, $_COOKIE['coId']);
542
-
543
- setcookie("ul", 1);
544
- setcookie("uId", $idUser);
545
-
546
- return true;
547
- } else {
548
- return false;
549
- }
550
- }
551
-
552
- public function log($message) {
553
- $pathToBsLogDir = Mage::getBaseDir('base') . "/errors/bsins";
554
-
555
- if (isset($pathToBsLogDir) && !is_dir($pathToBsLogDir)) {
556
- mkdir($pathToBsLogDir);
557
- }
558
-
559
- if (isset($pathToBsLogDir) && is_dir($pathToBsLogDir)) {
560
- $f = fopen($pathToBsLogDir . "/bslog.txt", "a");
561
- if ($f !== false) {
562
- fwrite($f, "[" . date('j-m-y H:m:s') . "] -> ");
563
- fwrite($f, $message);
564
- fwrite($f, PHP_EOL);
565
- }
566
- }
567
- }
568
-
569
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Brainsins/Recsins/controllers/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/controllers/Adminhtml/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/controllers/Adminhtml/RecsinsController.php CHANGED
@@ -283,9 +283,19 @@ class Brainsins_Recsins_Adminhtml_RecsinsController extends Mage_Adminhtml_Contr
283
  Mage::getModel('core/config')->saveConfig('brainsins/BS_USE_HIGH_DETAIL', "0");
284
  }
285
  } else {
286
-
287
  Mage::getModel('core/config')->saveConfig('brainsins/BS_USE_HIGH_DETAIL', "0");
288
  }
 
 
 
 
 
 
 
 
 
 
 
289
 
290
  $importConfig = $data['import_config'];
291
  if (isset($importConfig) && $importConfig == '1') {
283
  Mage::getModel('core/config')->saveConfig('brainsins/BS_USE_HIGH_DETAIL', "0");
284
  }
285
  } else {
 
286
  Mage::getModel('core/config')->saveConfig('brainsins/BS_USE_HIGH_DETAIL', "0");
287
  }
288
+
289
+ if (array_key_exists("use_ajax_requests", $data)) {
290
+ $useAjaxRequestsValue = $data['use_ajax_requests'];
291
+ if (isset($useAjaxRequestsValue) && $useAjaxRequestsValue == "checked") {
292
+ Mage::getModel('core/config')->saveConfig('brainsins/BS_USE_AJAX_REQUESTS', "1");
293
+ } else {
294
+ Mage::getModel('core/config')->saveConfig('brainsins/BS_USE_AJAX_REQUESTS', "0");
295
+ }
296
+ } else {
297
+ Mage::getModel('core/config')->saveConfig('brainsins/BS_USE_AJAX_REQUESTS', "0");
298
+ }
299
 
300
  $importConfig = $data['import_config'];
301
  if (isset($importConfig) && $importConfig == '1') {
app/code/community/Brainsins/Recsins/controllers/IndexController.php CHANGED
@@ -42,4 +42,80 @@ class Brainsins_Recsins_IndexController extends Mage_Core_Controller_Front_Actio
42
  $this->_redirectUrl($url);
43
  }
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
42
  $this->_redirectUrl($url);
43
  }
44
  }
45
+
46
+ public function getRecProdImgUrlAction() {
47
+
48
+ $id = $this->getRequest()->getParam("id");
49
+ $helper = Mage::helper("recsins/recsins");
50
+ $url = $helper->getImageUrl($id);
51
+
52
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
53
+ $url = "https://www.gemln.com/media/catalog/product/cache/7/small_image/149x155/9df78eab33525d08d6e5fb8d27136e95/T/r/Tresara-DiamondRing-GBRIN0060085-227.jpg";
54
+ $pos = strpos($url, "/", 8);
55
+ if ($pos !== false) {
56
+ $relativeUrl = substr($url, $pos);
57
+ return $relativeUrl;
58
+ } else {
59
+ return $url;
60
+ }
61
+ }
62
+
63
+ public function getRecProdImgRelativeUrl($id) {
64
+
65
+ $helper = Mage::helper("recsins/recsins");
66
+ $url = $helper->getImageUrl($id);
67
+
68
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
69
+ $pos = strpos($url, "/", 8);
70
+ if ($pos !== false) {
71
+ $relativeUrl = substr($url, $pos);
72
+ return $relativeUrl;
73
+ } else {
74
+ return $url;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * @return JSON Object
80
+ */
81
+ public function getRecommendationsAction() {
82
+
83
+
84
+ $recommenderId = $this->getRequest()->getParam("recId");
85
+ $userId = $this->getRequest()->getParam("userId");
86
+ $productId = $this->getRequest()->getParam("prodId");
87
+ $lang = $this->getRequest()->getParam("lang");
88
+ $divName = $this->getRequest()->getParam("divName");
89
+ $numRecs = $this->getRequest()->getParam("numRecs");
90
+ $categories = $this->getRequest()->getParam("categories");
91
+ $filter = $this->getRequest()->getParam("filter");
92
+ $detail = $this->getRequest()->getParam("detail");
93
+ $currSymbol = $this->getRequest()->getParam("currSymbol");
94
+ $currPosition = $this->getRequest()->getParam("currPosition");
95
+ $currDelimiter = $this->getRequest()->getParam("currDelimiter");
96
+ $callback = $this->getRequest()->getParam("callback");
97
+
98
+ $model = Mage::getSingleton("recsins/recsins");
99
+ $model = new Brainsins_Recsins_Model_Recsins();
100
+ $result = $model->requestRecommendations($recommenderId, $productId, $userId, $lang, $divName, $categories, $filter);
101
+
102
+ $json = json_decode($result, true);
103
+
104
+ foreach($json["data"]["list"] as &$item) {
105
+ $item['imageUrl'] = $this->getRecProdImgRelativeUrl($item["id"]);
106
+ }
107
+
108
+ $updatedJson = json_encode($json);
109
+
110
+ $script = "";
111
+
112
+ if (!isset($callback) || $calback == "") {
113
+ $callback = "BrainSINSRecommender.paintRecommendations";
114
+ }
115
+
116
+ $this->getResponse()->setHeader('Content-type', 'application/json');
117
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($json));
118
+
119
+ return;
120
+ }
121
  }
app/code/community/Brainsins/Recsins/etc/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/etc/config.xml CHANGED
@@ -26,7 +26,7 @@
26
  <config>
27
  <modules>
28
  <Brainsins_Recsins>
29
- <version>1.5.5</version>
30
  </Brainsins_Recsins>
31
  </modules>
32
  <frontend>
26
  <config>
27
  <modules>
28
  <Brainsins_Recsins>
29
+ <version>1.5.6</version>
30
  </Brainsins_Recsins>
31
  </modules>
32
  <frontend>
app/code/community/Brainsins/Recsins/sql/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/sql/recsins_setup/.DS_Store DELETED
Binary file
app/code/community/Brainsins/Recsins/sql/recsins_setup/mysql4-upgrade-1.5.5-1.5.6.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * BrainSINS' Magento Extension allows to integrate the BrainSINS
5
+ * personalized product recommendations into a Magento Store.
6
+ * Copyright (c) 2011 Social Gaming Platform S.R.L.
7
+ *
8
+ * This file is part of BrainSINS' Magento Extension.
9
+ *
10
+ * BrainSINS' Magento Extension is free software: you can redistribute it
11
+ * and/or modify it under the terms of the GNU General Public License
12
+ * as published by the Free Software Foundation, either version 3 of the
13
+ * License, or (at your option) any later version.
14
+ *
15
+ * Foobar is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22
+ *
23
+ * Please do not hesitate to contact us at info@brainsins.com
24
+ *
25
+ */
26
+ $installer = $this;
27
+
28
+ $table = $installer->getTable('recsins_recommender');
29
+
30
+ $installer->startSetup();
31
+
32
+ if (!$installer->tableExists($table)) {
33
+ $installer->run("
34
+ CREATE TABLE IF NOT EXISTS {$table} (
35
+ `id` int(10) unsigned NOT NULL,
36
+ `name` varchar(255),
37
+ `page` smallint(8),
38
+ PRIMARY KEY (`id`)
39
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Brainsins loaded Recommenders';
40
+ ");
41
+ }
42
+
43
+ Mage::getModel('core/config')->saveConfig('brainsins/BS_VERSION', '1.5.6');
44
+
45
+ $installer->endSetup();
46
+
47
+ Mage::getConfig()->cleanCache();
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Brainsins_Recommender</name>
4
- <version>1.5.5</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.brainsins.es/contrato-de-prestacion-de-servicios-brainsin-para-plugins/">GPL 3.0</license>
7
  <channel>community</channel>
@@ -19,11 +19,11 @@ BrainSINS Recommender is offered as a software as a service. It processes the us
19
  Increase your cross-sell, up-sell and Average Order Value (AOV) rates. Send personalized emails to your clients to increase the return to your store, and measure and control the effect of all the recommendations in your online store.&#xD;
20
  &#xD;
21
  Install the plugin in a few minutes and offer more than 100 personalized recommenders in any web page of your online store in less than 24 hours. Choose the plan that better fits to your store at http://www.brainsins.es/tarifas/ and try it for Free 1 month, experimenting the benefits in your own online store without compromise.</description>
22
- <notes>Added a configuration option to retrieve description in recommendations</notes>
23
  <authors><author><name>BrainSINS</name><user>auto-converted</user><email>alejandro.cuevas@brainsins.com</email></author></authors>
24
- <date>2012-07-26</date>
25
- <time>17:43:25</time>
26
- <contents><target name="magecommunity"><dir name="Brainsins"><dir name="Recsins"><dir name="Block"><dir name="Adminhtml"><dir name="Recsins"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="f50e327073f6db6f0b7aaf2e6018834b"/><file name=".DS_Store" hash="47ab7c6331c785f3abe32e1d49659743"/></dir><file name="Form.php" hash="a5eb38bd631ea495e1a367cdabd43cac"/><file name="Tabs.php" hash="da7477ceefd6cc473fb2fb2a307f0282"/><file name=".DS_Store" hash="dbfd4b859fae44d226584cc0de499414"/></dir><file name="Edit.php" hash="942d16b49fca2566799c7c393ffdd4d2"/><file name="Grid.php" hash="bf34a0c320aeebfe1cc645dc4120b4aa"/><file name=".DS_Store" hash="550ce861437446e70bb1b83296032d36"/></dir><file name="Recsins.php" hash="f0bb580c8238818273726847917789f8"/><file name=".DS_Store" hash="1b0ef8c354534e8683bfa107de6b5724"/></dir><file name="Category.php" hash="fa64d544ad0020dfa651b6c27f95d734"/><file name="Checkout.php" hash="e6e523a465b52ff1d93dea497c15db5e"/><file name="Home.php" hash="26eb9d8e4f796bb0a2ba8ea90691c943"/><file name="Product.php" hash="648d439dc8729a8205449c6887175371"/><file name="Recsins.php" hash="c2bcc5360a349057e9e5ec4c75f6ea02"/><file name=".DS_Store" hash="685d9658140adde8787312ba21575a63"/><file name=".LCKRecsins.php~" hash="ed46e9b84acaa2b3b33539877109417b"/></dir><dir name="Entity"><file name="Setup.php" hash="02af74b02e083c4552762ecc9987a1a7"/><file name=".DS_Store" hash="904a17b2e133ff00bc1c75992115b463"/></dir><dir name="Helper"><file name="Data.php" hash="c117b4e42fef671651a78c8f4e01d0e5"/><file name="Recsins.php" hash="435d1402b9b860d906db3a3beb3c93de"/><file name=".DS_Store" hash="c9075ec8f3a93c790032a41253f0410d"/></dir><dir name="Model"><dir name="Api"><dir name="ficheros"><file name="Api.php" hash="1ee860dbae5f6b13258a0d0645d5adf8"/><file name="ProductsApi.php" hash="935bed7774eabfeda9949810faa116b0"/><file name=".DS_Store" hash="014af3b68e1d3b96ec61219fe428ff22"/></dir><file name="Api.php" hash="0fbdc82b29aaa90ecf3a4c0da9b15e7d"/><file name="ProductsApi.php" hash="0af71e0b0a1f3b1884428a5e43dea402"/><file name="ficheros.zip" hash="aa99d1feccadf91c4e467075feb1a875"/><file name=".DS_Store" hash="ef6c115a2d11276a7d6f63bf02593722"/></dir><dir name="Mysql4"><dir name="Recsins"><file name="Collection.php" hash="8c69337dee2f64516174e59805c6ec83"/></dir><file name="Recsins.php" hash="57256b85a9e1279e0875ea50cf8325d4"/><file name=".DS_Store" hash="738094d269ed6a646832036c60e08599"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><dir name="Recommender"><file name="Collection.php" hash="6c36324bb84cba28f6a5bdb7eb0c2bce"/></dir><file name="Recommender.php" hash="f6857e56874c6480447b5c411aa7a066"/></dir></dir><file name="Setup.php" hash="02af74b02e083c4552762ecc9987a1a7"/></dir><file name="Cart.php" hash="d19925676d18f200f25b1c995f035300"/><file name="CartProduct.php" hash="fffddbe0a759335f89bbdbcec7b4d2eb"/><file name="Client.php" hash="54ab4289c332f4414761ba4256dc205e"/><file name="NewFile.xml" hash="93286b7fccf6f6092628ada8b85c0727"/><file name="Observer.php" hash="6c0ff3f353947cda424057117c5ba530"/><file name="Order.php" hash="b8dcb3adfe676725fe4f09acff84cd97"/><file name="OrderProduct.php" hash="1d33e879db0bb8557704ed3b66fb584d"/><file name="Product.php" hash="222db5151109eb9e6741cc1fe0d1ba7f"/><file name="Recommender.php" hash="12532b4efd6fdec560522a2ecf029ed9"/><file name="Recsins.php" hash="6a324de328fce850a5f3955e33fb3ec0"/><file name="Recsins_1.php" hash="310a9b224478749d35c5b59689ce1a07"/><file name="Status.php" hash="e3f1a39141d7a4aaa99252937f60ca8d"/><file name="User.php" hash="3244421d7331e5167e910f6fc3827361"/><file name=".DS_Store" hash="1f13e526a6f8ed14ac43ebd700cb6f60"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="RecsinsController.php" hash="d26b0053425cca1a56d3111194c64491"/><file name=".DS_Store" hash="eb69d7bfb18ebe8966b63ac54b04d1c0"/></dir><file name="IndexController.php" hash="2c9f228ed4e43c347235ed327365a219"/><file name=".DS_Store" hash="b415ad11c2cfebb78e16adb17ca06bff"/></dir><dir name="etc"><file name="api.xml" hash="c82c8df487ba808a8851ea9f1a8fe197"/><file name="config.xml" hash="f15a7b54816aa5df784863d49789e530"/><file name="widget.xml" hash="c4f1829fa161f1119d817b64878f3b2f"/><file name=".DS_Store" hash="05e296fc2705958a70855fe260ceb9e5"/></dir><dir name="sql"><dir name="recsins_setup"><file name="mysql4-install-1.4.0.php" hash="33ae9091e3066779c13e738beae3650c"/><file name="mysql4-upgrade-1.4.0-1.4.1.php" hash="b636f16be2575bff013c14c012b34625"/><file name="mysql4-upgrade-1.4.1-1.4.2.php" hash="e73c5189c851c1ddb94d8ce8acd6f1a6"/><file name="mysql4-upgrade-1.4.2-1.4.3.php" hash="2297a4e5670b28a24c1fcd3d5d47aca6"/><file name="mysql4-upgrade-1.4.3-1.4.4.php" hash="6c76f6d7ffe9da72ebabd44779d13bde"/><file name="mysql4-upgrade-1.4.4-1.4.5.php" hash="1b932c2afb4543c6e067a7b769d48eb8"/><file name="mysql4-upgrade-1.4.5-1.4.6.php" hash="a851ccc0fa73440b74828c0b2ee993d9"/><file name="mysql4-upgrade-1.4.6-1.4.7.php" hash="923d491257ad9836738c1586d494e12c"/><file name="mysql4-upgrade-1.4.7-1.4.8.php" hash="a2c96553909227f5f5bd7a685691c0ac"/><file name="mysql4-upgrade-1.4.8-1.4.9.php" hash="86b6da79f302790ecb6a072c4ef68fb0"/><file name="mysql4-upgrade-1.4.9-1.5.0.php" hash="b10dd9d0dc951f3b783da743558af5ca"/><file name="mysql4-upgrade-1.5.0-1.5.1.php" hash="7f86ed73d2d35dd2989528046772fa8b"/><file name="mysql4-upgrade-1.5.1-1.5.2.php" hash="da8251355aa4811a099e5b22c9debca3"/><file name="mysql4-upgrade-1.5.2-1.5.3.php" hash="5ad2385bec084bc29a0673ed2a97231c"/><file name="mysql4-upgrade-1.5.3-1.5.4.php" hash="bda831da9d0a842c16092e1900d17087"/><file name="mysql4-upgrade-1.5.4-1.5.5.php" hash="b04a5a6ea7a5ec0df04a42953bb97729"/><file name=".DS_Store" hash="70fb1641ce88fc5fdb410744cb098089"/></dir><file name=".DS_Store" hash="fd4b270e5bdf8c2dbe56c9a98d4e6548"/></dir><file name="COPYING.txt" hash="4fe869ee987a340198fb0d54c55c47f1"/><file name=".DS_Store" hash="5fbb75ac088ce79fe0044c4951680ae6"/></dir><file name=".DS_Store" hash="6404be841b797bdacec75c7f7bb4a79c"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="recsins.xml" hash="c2608f0c7f9f6efcbeb74bd5b1427206"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="recsins"><file name="cart.phtml" hash="04ee1833a0177a83644e4d1f3211c789"/><file name="category.phtml" hash="1979377cb8f06740a6b44a922e46dacd"/><file name="product.phtml" hash="3a623d6b48cceae14912b4daf5113ca2"/><file name="recsins.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name=".DS_Store" hash="f0948e76df06a209a9b7f51ff398fd60"/></dir></dir><dir name="layout"><file name="recsins.xml" hash="9185dc1897ec93c400edd2cd95b6533d"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Brainsins_Recsins.xml" hash="54e1c94137477548911c4ebce7eb97fe"/></dir></target><target name="magelocale"><dir name="es_ES"><file name="Brainsins_Recsins.csv" hash="7f731ae9e9faa8b003a63722ef3ce18a"/></dir><dir name="en_US"><file name="Brainsins_Recsins.csv" hash="6381582be5edc31cba54a052bb48b86d"/></dir></target></contents>
27
  <compatible/>
28
  <dependencies/>
29
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Brainsins_Recommender</name>
4
+ <version>1.5.6</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.brainsins.es/contrato-de-prestacion-de-servicios-brainsin-para-plugins/">GPL 3.0</license>
7
  <channel>community</channel>
19
  Increase your cross-sell, up-sell and Average Order Value (AOV) rates. Send personalized emails to your clients to increase the return to your store, and measure and control the effect of all the recommendations in your online store.&#xD;
20
  &#xD;
21
  Install the plugin in a few minutes and offer more than 100 personalized recommenders in any web page of your online store in less than 24 hours. Choose the plan that better fits to your store at http://www.brainsins.es/tarifas/ and try it for Free 1 month, experimenting the benefits in your own online store without compromise.</description>
22
+ <notes>Now recommendations can be retrieved using an ajax call</notes>
23
  <authors><author><name>BrainSINS</name><user>auto-converted</user><email>alejandro.cuevas@brainsins.com</email></author></authors>
24
+ <date>2012-09-11</date>
25
+ <time>16:15:17</time>
26
+ <contents><target name="magecommunity"><dir name="Brainsins"><dir name="Recsins"><dir name="Block"><dir name="Adminhtml"><dir name="Recsins"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="f50e327073f6db6f0b7aaf2e6018834b"/></dir><file name="Form.php" hash="bbb8fd431ef3cd0e8213c3a1ac2d3dfe"/><file name="Tabs.php" hash="da7477ceefd6cc473fb2fb2a307f0282"/></dir><file name="Edit.php" hash="942d16b49fca2566799c7c393ffdd4d2"/><file name="Grid.php" hash="bf34a0c320aeebfe1cc645dc4120b4aa"/></dir><file name="Recsins.php" hash="f0bb580c8238818273726847917789f8"/></dir><file name="Category.php" hash="fa64d544ad0020dfa651b6c27f95d734"/><file name="Checkout.php" hash="e6e523a465b52ff1d93dea497c15db5e"/><file name="Home.php" hash="26eb9d8e4f796bb0a2ba8ea90691c943"/><file name="Product.php" hash="648d439dc8729a8205449c6887175371"/><file name="Recsins.php" hash="d1bbf6cb8e30386614b8de9e873c446d"/><file name=".LCKRecsins.php~" hash="ed46e9b84acaa2b3b33539877109417b"/></dir><dir name="Entity"><file name="Setup.php" hash="02af74b02e083c4552762ecc9987a1a7"/></dir><dir name="Helper"><file name="Data.php" hash="c117b4e42fef671651a78c8f4e01d0e5"/><file name="Recsins.php" hash="435d1402b9b860d906db3a3beb3c93de"/></dir><dir name="Model"><dir name="Api"><dir name="ficheros"><file name="Api.php" hash="1ee860dbae5f6b13258a0d0645d5adf8"/><file name="ProductsApi.php" hash="935bed7774eabfeda9949810faa116b0"/></dir><file name="Api.php" hash="93dc9bb52ecd977739361410c36f9881"/><file name="ProductsApi.php" hash="0af71e0b0a1f3b1884428a5e43dea402"/><file name="ficheros.zip" hash="aa99d1feccadf91c4e467075feb1a875"/></dir><dir name="Mysql4"><dir name="Recsins"><file name="Collection.php" hash="8c69337dee2f64516174e59805c6ec83"/></dir><file name="Recsins.php" hash="57256b85a9e1279e0875ea50cf8325d4"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><dir name="Recommender"><file name="Collection.php" hash="6c36324bb84cba28f6a5bdb7eb0c2bce"/></dir><file name="Recommender.php" hash="f6857e56874c6480447b5c411aa7a066"/></dir></dir><file name="Setup.php" hash="02af74b02e083c4552762ecc9987a1a7"/></dir><file name="Cart.php" hash="d19925676d18f200f25b1c995f035300"/><file name="CartProduct.php" hash="fffddbe0a759335f89bbdbcec7b4d2eb"/><file name="Client.php" hash="54ab4289c332f4414761ba4256dc205e"/><file name="NewFile.xml" hash="93286b7fccf6f6092628ada8b85c0727"/><file name="Observer.php" hash="6c0ff3f353947cda424057117c5ba530"/><file name="Order.php" hash="b8dcb3adfe676725fe4f09acff84cd97"/><file name="OrderProduct.php" hash="1d33e879db0bb8557704ed3b66fb584d"/><file name="Product.php" hash="222db5151109eb9e6741cc1fe0d1ba7f"/><file name="Recommender.php" hash="12532b4efd6fdec560522a2ecf029ed9"/><file name="Recsins.php" hash="1a4d3ff6a94336a08a709f925cf0579c"/><file name="Status.php" hash="e3f1a39141d7a4aaa99252937f60ca8d"/><file name="User.php" hash="3244421d7331e5167e910f6fc3827361"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="RecsinsController.php" hash="7280e9bdf771aee3be0c294ad6c4fbe7"/></dir><file name="IndexController.php" hash="f111c628424a8e5fb0b8b883b9fc72c5"/></dir><dir name="etc"><file name="api.xml" hash="c82c8df487ba808a8851ea9f1a8fe197"/><file name="config.xml" hash="e2a848e588161a46ad05782ada26f0c9"/><file name="widget.xml" hash="c4f1829fa161f1119d817b64878f3b2f"/></dir><dir name="sql"><dir name="recsins_setup"><file name="mysql4-install-1.4.0.php" hash="33ae9091e3066779c13e738beae3650c"/><file name="mysql4-upgrade-1.4.0-1.4.1.php" hash="b636f16be2575bff013c14c012b34625"/><file name="mysql4-upgrade-1.4.1-1.4.2.php" hash="e73c5189c851c1ddb94d8ce8acd6f1a6"/><file name="mysql4-upgrade-1.4.2-1.4.3.php" hash="2297a4e5670b28a24c1fcd3d5d47aca6"/><file name="mysql4-upgrade-1.4.3-1.4.4.php" hash="6c76f6d7ffe9da72ebabd44779d13bde"/><file name="mysql4-upgrade-1.4.4-1.4.5.php" hash="1b932c2afb4543c6e067a7b769d48eb8"/><file name="mysql4-upgrade-1.4.5-1.4.6.php" hash="a851ccc0fa73440b74828c0b2ee993d9"/><file name="mysql4-upgrade-1.4.6-1.4.7.php" hash="923d491257ad9836738c1586d494e12c"/><file name="mysql4-upgrade-1.4.7-1.4.8.php" hash="a2c96553909227f5f5bd7a685691c0ac"/><file name="mysql4-upgrade-1.4.8-1.4.9.php" hash="86b6da79f302790ecb6a072c4ef68fb0"/><file name="mysql4-upgrade-1.4.9-1.5.0.php" hash="b10dd9d0dc951f3b783da743558af5ca"/><file name="mysql4-upgrade-1.5.0-1.5.1.php" hash="7f86ed73d2d35dd2989528046772fa8b"/><file name="mysql4-upgrade-1.5.1-1.5.2.php" hash="da8251355aa4811a099e5b22c9debca3"/><file name="mysql4-upgrade-1.5.2-1.5.3.php" hash="5ad2385bec084bc29a0673ed2a97231c"/><file name="mysql4-upgrade-1.5.3-1.5.4.php" hash="bda831da9d0a842c16092e1900d17087"/><file name="mysql4-upgrade-1.5.4-1.5.5.php" hash="b04a5a6ea7a5ec0df04a42953bb97729"/><file name="mysql4-upgrade-1.5.5-1.5.6.php" hash="cd94c569ee573f51e3e6062cfa25cb7e"/></dir></dir><file name="COPYING.txt" hash="4fe869ee987a340198fb0d54c55c47f1"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="recsins.xml" hash="c2608f0c7f9f6efcbeb74bd5b1427206"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="recsins"><file name="cart.phtml" hash="04ee1833a0177a83644e4d1f3211c789"/><file name="category.phtml" hash="1979377cb8f06740a6b44a922e46dacd"/><file name="product.phtml" hash="3a623d6b48cceae14912b4daf5113ca2"/><file name="recsins.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name=".DS_Store" hash="f0948e76df06a209a9b7f51ff398fd60"/></dir></dir><dir name="layout"><file name="recsins.xml" hash="9185dc1897ec93c400edd2cd95b6533d"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Brainsins_Recsins.xml" hash="54e1c94137477548911c4ebce7eb97fe"/></dir></target><target name="magelocale"><dir name="es_ES"><file name="Brainsins_Recsins.csv" hash="7f731ae9e9faa8b003a63722ef3ce18a"/></dir><dir name="en_US"><file name="Brainsins_Recsins.csv" hash="6381582be5edc31cba54a052bb48b86d"/></dir></target></contents>
27
  <compatible/>
28
  <dependencies/>
29
  </package>