Version Notes
Expertrec Recommendation plugin for magento sites.
Download this release
Release Info
Developer | melchi |
Extension | Expertrec_Recommendation |
Version | 1.1.0 |
Comparing to | |
See all releases |
Version 1.1.0
- app/code/community/Expertrec/Recommendation/Helper/Data.php +222 -0
- app/code/community/Expertrec/Recommendation/Helper/Filehelper.php +88 -0
- app/code/community/Expertrec/Recommendation/Helper/Search/Layout.php +75 -0
- app/code/community/Expertrec/Recommendation/Helper/Searchhelper.php +210 -0
- app/code/community/Expertrec/Recommendation/Helper/Suggestionhelper.php +122 -0
- app/code/community/Expertrec/Recommendation/Model/Api/Request.php +147 -0
- app/code/community/Expertrec/Recommendation/Model/Catalogsearch/Layer.php +101 -0
- app/code/community/Expertrec/Recommendation/Model/Feed.php +43 -0
- app/code/community/Expertrec/Recommendation/Model/Feed/Feedconfig.php +79 -0
- app/code/community/Expertrec/Recommendation/Model/Feed/Feedcreator.php +138 -0
- app/code/community/Expertrec/Recommendation/Model/Feed/Feedfilter.php +28 -0
- app/code/community/Expertrec/Recommendation/Model/Feed/Formatter.php +98 -0
- app/code/community/Expertrec/Recommendation/Model/Log.php +61 -0
- app/code/community/Expertrec/Recommendation/Model/Observer.php +257 -0
- app/code/community/Expertrec/Recommendation/Model/Translator/Category.php +60 -0
- app/code/community/Expertrec/Recommendation/Model/Validate.php +47 -0
- app/code/community/Expertrec/Recommendation/Model/Writer/Abstract.php +61 -0
- app/code/community/Expertrec/Recommendation/Model/Writer/Csv.php +89 -0
- app/code/community/Expertrec/Recommendation/controllers/Adminhtml/IndexController.php +10 -0
- app/code/community/Expertrec/Recommendation/controllers/ApiController.php +558 -0
- app/code/community/Expertrec/Recommendation/controllers/CatalogSearch/ResultController.php +13 -0
- app/code/community/Expertrec/Recommendation/controllers/ConfigController.php +236 -0
- app/code/community/Expertrec/Recommendation/controllers/IndexController.php +210 -0
- app/code/community/Expertrec/Recommendation/etc/adminhtml.xml +16 -0
- app/code/community/Expertrec/Recommendation/etc/config.xml +117 -0
- app/code/community/Expertrec/Recommendation/sql/expertrec_setup/mysql4-install-1.0.0.php +17 -0
- app/design/frontend/base/default/layout/expertrec/recommendation.xml +17 -0
- app/design/frontend/base/default/template/expertrec/recommendation/tracker.phtml +49 -0
- app/design/frontend/base/default/template/expertrec/recommendation/tracking/product.phtml +15 -0
- app/etc/modules/Expertrec_Recommendation.xml +9 -0
- package.xml +18 -0
app/code/community/Expertrec/Recommendation/Helper/Data.php
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @category Expertrec
|
6 |
+
* @package Expertrec_Recommendation
|
7 |
+
* @copyright Copyright (c) 2016 CloudInfra LLC.
|
8 |
+
*/
|
9 |
+
class Expertrec_Recommendation_Helper_Data extends Mage_Core_Helper_Abstract {
|
10 |
+
|
11 |
+
const CONFIG_PREFIX = 'expertrec/general';
|
12 |
+
const FEED_UPLOAD_ENDPOINT = 'expertrec/general/upload_endpoint';
|
13 |
+
|
14 |
+
public function getUniqueId($product, $item=null) {
|
15 |
+
$type= null;
|
16 |
+
if($product->hasData('type_id')) {
|
17 |
+
$type = $product->getData('type_id');
|
18 |
+
}
|
19 |
+
|
20 |
+
if($type =='simple'){
|
21 |
+
|
22 |
+
if ($item != null && $item instanceof Mage_Sales_Model_Order) {
|
23 |
+
if($item->getParentItem() != null) {
|
24 |
+
$productId = $item->getParentItem()->getProductId();
|
25 |
+
return $productId;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
|
30 |
+
|
31 |
+
if(!isset($parentIds) || sizeof($parentIds) == 0) {
|
32 |
+
$parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
|
33 |
+
if(isset($parentIds) && sizeof($parentIds) > 0) {
|
34 |
+
return $parentIds[0];
|
35 |
+
}
|
36 |
+
}else {
|
37 |
+
return $parentIds[0];
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
$productId = $product->getData('entity_id');
|
42 |
+
return $productId;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function saveConfig($key, $value, $scope = 'default', $scopeId = 0){
|
46 |
+
if(is_null($value) || is_array($value) || is_object($value)){
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
$path = self::CONFIG_PREFIX . '/' . $key;
|
51 |
+
Mage::getConfig()->saveConfig(rtrim($path, '/'), (string)$value, $scope, $scopeId);
|
52 |
+
|
53 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Successfully updated : <".$key."> in core_config_data table.");
|
54 |
+
return $this;
|
55 |
+
}
|
56 |
+
|
57 |
+
public function getConfig($key){
|
58 |
+
$path = self::CONFIG_PREFIX . '/' . $key;
|
59 |
+
|
60 |
+
return Mage::getStoreConfig($path);
|
61 |
+
}
|
62 |
+
|
63 |
+
public function clearCache($type='config'){
|
64 |
+
Mage::app()->getCacheInstance()->cleanType($type);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function sendCurl($command){
|
68 |
+
if (isset($ch)) {
|
69 |
+
unset($ch);
|
70 |
+
}
|
71 |
+
|
72 |
+
if (function_exists('curl_setopt')) {
|
73 |
+
$ch = curl_init();
|
74 |
+
curl_setopt($ch, CURLOPT_URL, $command);
|
75 |
+
curl_setopt($ch, CURLOPT_HEADER, 0);
|
76 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
77 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
78 |
+
$str = curl_exec($ch);
|
79 |
+
} else {
|
80 |
+
$str = 'failed';
|
81 |
+
}
|
82 |
+
|
83 |
+
return $str;
|
84 |
+
}
|
85 |
+
|
86 |
+
public function getPages($curPage,$count,$displayPages=5,$itemPerPage=20){
|
87 |
+
$totalPages = ceil($count / $itemPerPage);
|
88 |
+
$pages = array();
|
89 |
+
if ($totalPages <= $displayPages) {
|
90 |
+
$pages = range(1, $totalPages);
|
91 |
+
}
|
92 |
+
else{
|
93 |
+
$half = ceil($displayPages / 2);
|
94 |
+
if ($curPage >= $half && $curPage <= $totalPages - $half){
|
95 |
+
$start = ($curPage - $half) + 1;
|
96 |
+
$finish = ($start + $displayPages) - 1;
|
97 |
+
}elseif ($curPage < $half) {
|
98 |
+
$start = 1;
|
99 |
+
$finish = $displayPages;
|
100 |
+
}elseif ($curPage > ($totalPages - $half)) {
|
101 |
+
$finish = $totalPages;
|
102 |
+
$start = $finish - $displayPages + 1;
|
103 |
+
}
|
104 |
+
$pages = range($start, $finish);
|
105 |
+
}
|
106 |
+
return $pages;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function getAddToCartUrl($productId){
|
110 |
+
try{
|
111 |
+
$product=Mage::getModel('catalog/product')->load($productId);
|
112 |
+
return Mage::helper('checkout/cart')->getAddUrl($product);
|
113 |
+
}catch(Exception $e){
|
114 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Error in getting AddToCart Url: ".$e->getMessage());
|
115 |
+
}
|
116 |
+
return '';
|
117 |
+
}
|
118 |
+
|
119 |
+
public function getWishlistUrl($productId){
|
120 |
+
try{
|
121 |
+
$product=Mage::getModel('catalog/product')->load($productId);
|
122 |
+
return Mage::helper('wishlist')->getAddUrl($product);
|
123 |
+
}catch(Exception $e){
|
124 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Error in getting Wishlist Url: ".$e->getMessage());
|
125 |
+
}
|
126 |
+
return '';
|
127 |
+
}
|
128 |
+
|
129 |
+
|
130 |
+
public function getProductCompareUrl($productId){
|
131 |
+
try{
|
132 |
+
$product=Mage::getModel('catalog/product')->load($productId);
|
133 |
+
return Mage::helper('catalog/product_compare')->getAddUrl($product);
|
134 |
+
}catch(Exception $e){
|
135 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Error in getting Product-Compare Url: ".$e->getMessage());
|
136 |
+
}
|
137 |
+
return '';
|
138 |
+
|
139 |
+
}
|
140 |
+
|
141 |
+
public function getFormatCurrency($price=0,$productId=0,$fetchPrice=false){
|
142 |
+
try{
|
143 |
+
if($fetchPrice){
|
144 |
+
$product=Mage::getModel('catalog/product')->load($productId);
|
145 |
+
if($product){
|
146 |
+
$price = $product->fetchPrice();
|
147 |
+
}
|
148 |
+
}
|
149 |
+
if(empty($price)){
|
150 |
+
return $price;
|
151 |
+
}
|
152 |
+
$formattedPrice = Mage::helper('core')->currency((int)$price, true, true);
|
153 |
+
return $formattedPrice;
|
154 |
+
}catch(Exception $e){
|
155 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Error in getting FormattedPrice: ".$e->getMessage());
|
156 |
+
}
|
157 |
+
return '';
|
158 |
+
}
|
159 |
+
|
160 |
+
public function getFormatPrice($price){
|
161 |
+
try{
|
162 |
+
if(empty($price)){
|
163 |
+
return $price;
|
164 |
+
}
|
165 |
+
return Mage::helper('core')->formatPrice($price,false);
|
166 |
+
}catch(Exception $e){
|
167 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Error in getting Format Price: ".$e->getMessage());
|
168 |
+
}
|
169 |
+
return '';
|
170 |
+
}
|
171 |
+
|
172 |
+
public function getProductDescription($productId){
|
173 |
+
try{
|
174 |
+
$product=Mage::getModel('catalog/product')->load($productId);
|
175 |
+
return $product->getDescription();
|
176 |
+
}catch(Exception $e){
|
177 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Error in getting Product Description: ".$e->getMessage());
|
178 |
+
}
|
179 |
+
return '';
|
180 |
+
}
|
181 |
+
|
182 |
+
public function pushFeed($filepath){
|
183 |
+
try{
|
184 |
+
$logger = Mage::getSingleton('expertrec_recommendation/log');
|
185 |
+
$url = Mage::getStoreConfig(self::FEED_UPLOAD_ENDPOINT);
|
186 |
+
if(empty($url)){
|
187 |
+
$logger->log("Upload endpoint is not configured");
|
188 |
+
return false;
|
189 |
+
}
|
190 |
+
|
191 |
+
$filename = end(explode("/", $filepath));
|
192 |
+
$file = new CurlFile($filepath,'',$filename);
|
193 |
+
$fields = array('file'=>$file);
|
194 |
+
|
195 |
+
$ch = curl_init();
|
196 |
+
curl_setopt($ch, CURLOPT_URL,$url);
|
197 |
+
curl_setopt($ch, CURLOPT_POST,true);
|
198 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
|
199 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
200 |
+
|
201 |
+
$logger->log('Pushing the feed to '.$url);
|
202 |
+
// push the feed to the server
|
203 |
+
$response = curl_exec($ch);
|
204 |
+
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
205 |
+
$logger->log("Response from the server: ".json_encode($response));
|
206 |
+
|
207 |
+
if($status != 200) {
|
208 |
+
throw new Exception('Unexpected response from server');
|
209 |
+
}
|
210 |
+
$logger->log("File Successfully uploaded to the server.");
|
211 |
+
Mage::helper('expertrec_recommendation/filehelper')->deleteFile($filepath);
|
212 |
+
}catch(Exception $ex){
|
213 |
+
$logger->log("Error while uploading the feed because of " . $ex->getMessage());
|
214 |
+
return false;
|
215 |
+
}
|
216 |
+
curl_close($ch);
|
217 |
+
return true;
|
218 |
+
}
|
219 |
+
|
220 |
+
|
221 |
+
}
|
222 |
+
?>
|
app/code/community/Expertrec/Recommendation/Helper/Filehelper.php
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Helper_Filehelper extends Mage_Core_Helper_Abstract{
|
4 |
+
|
5 |
+
public function createFeedZipFile($rootPath,$zipFileName) {
|
6 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Feed compression initiated");
|
7 |
+
|
8 |
+
if(!is_dir($rootPath)){return $this;}
|
9 |
+
|
10 |
+
try{
|
11 |
+
// Create recursive directory iterator
|
12 |
+
$files = new RecursiveIteratorIterator(
|
13 |
+
new RecursiveDirectoryIterator($rootPath),
|
14 |
+
RecursiveIteratorIterator::LEAVES_ONLY
|
15 |
+
);
|
16 |
+
|
17 |
+
if(count($files)){
|
18 |
+
$zip = new ZipArchive();
|
19 |
+
$zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
20 |
+
|
21 |
+
foreach ($files as $name => $file){
|
22 |
+
// Skip directories (they would be added automatically)
|
23 |
+
if (!$file->isDir()){
|
24 |
+
// Get real and relative path for current file
|
25 |
+
$filePath = $file->getRealPath();
|
26 |
+
$relativePath = substr($filePath, strlen($rootPath) + 1);
|
27 |
+
|
28 |
+
// Add current file to archive
|
29 |
+
$zip->addFile($filePath, $relativePath);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
// Zip archive will be created only after closing object
|
34 |
+
$zip->close();
|
35 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Feed compression done");
|
36 |
+
}
|
37 |
+
}catch(Exception $e){
|
38 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error: feed compression error: ".$e->getMessage());
|
39 |
+
}
|
40 |
+
return $this;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function createZipFile($path,$fileName,$zipFileName){
|
44 |
+
Mage::getSingleton('expertrec_recommendation/log')->log($zipFileName." compression initiated");
|
45 |
+
try{
|
46 |
+
$zip = new ZipArchive();
|
47 |
+
if ( $zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
|
48 |
+
$zip->addFile($path.'/'.$fileName, $fileName);
|
49 |
+
$zip->close();
|
50 |
+
Mage::getSingleton('expertrec_recommendation/log')->log($zipFileName." compression done");
|
51 |
+
}
|
52 |
+
|
53 |
+
}catch(Exception $e){
|
54 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error: Create Zip file error: ".$e->getMessage());
|
55 |
+
}
|
56 |
+
return $this;
|
57 |
+
}
|
58 |
+
|
59 |
+
public function deleteFile($file){
|
60 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Deleting file: ".$file);
|
61 |
+
unlink($file);
|
62 |
+
return $this;
|
63 |
+
}
|
64 |
+
|
65 |
+
public function cleanDir($path) {
|
66 |
+
try{
|
67 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Deleting feed directory: ".$path);
|
68 |
+
if (is_dir($path) === true){
|
69 |
+
$files = array_diff(scandir($path), array('.', '..'));
|
70 |
+
|
71 |
+
foreach ($files as $file){
|
72 |
+
if (is_dir($file) === true ) {
|
73 |
+
self::deleteDir(realpath($path) . '/' . $file);
|
74 |
+
}else {
|
75 |
+
unlink(realpath($path) . '/' . $file);
|
76 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Deleted file: ".$file);
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
}
|
81 |
+
|
82 |
+
}catch(Exception $e){
|
83 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error: deleting dir error: ".$e->getMessage());
|
84 |
+
}
|
85 |
+
return $this;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
?>
|
app/code/community/Expertrec/Recommendation/Helper/Search/Layout.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Helper_Search_Layout extends Mage_Core_Helper_Abstract{
|
4 |
+
|
5 |
+
const SEARCH_SINGLE_SELECT_FILTERS = 'search/single_select_filters';
|
6 |
+
const SEARCH_IS_AJAX = 'search/is_ajax';
|
7 |
+
|
8 |
+
protected $_isAjax = false;
|
9 |
+
protected $_confArray;
|
10 |
+
|
11 |
+
protected $_singleSelectFilters = array();
|
12 |
+
|
13 |
+
public function init($confArray){
|
14 |
+
$this->_confArray = $confArray;
|
15 |
+
try{
|
16 |
+
$singleFilters = Mage::helper('expertrec_recommendation')->getConfig(self::SEARCH_SINGLE_SELECT_FILTERS);
|
17 |
+
$isAjax = Mage::helper('expertrec_recommendation')->getConfig(self::SEARCH_IS_AJAX);
|
18 |
+
|
19 |
+
|
20 |
+
$this->_singleSelectFilters = isset($singleFilters) ? explode(',', $singleFilters) : $this->_singleSelectFilters;
|
21 |
+
$this->_isAjax = isset($isAjax) && $isAjax == 'true' ? true : false;
|
22 |
+
|
23 |
+
}catch (Exception $e) {
|
24 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('Search Layout Helper::init exception: '.$e->getMessage());
|
25 |
+
}
|
26 |
+
return $this;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getIsAjax(){
|
30 |
+
return $this->_isAjax;
|
31 |
+
}
|
32 |
+
|
33 |
+
protected function removeRequestParam($paramKey,$url=''){
|
34 |
+
$url = !empty($url) ? $url : $this->_confArray["url"];
|
35 |
+
$finalUrl = rtrim(Mage::helper('core/url')->removeRequestParam($url, $paramKey, false),'&');
|
36 |
+
return $finalUrl;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @param string facet-header
|
41 |
+
* @param string facet-label
|
42 |
+
* @return string url
|
43 |
+
*/
|
44 |
+
protected function getFacetUrl($fhead,$facetLabel){
|
45 |
+
$confArray = $this->_confArray;
|
46 |
+
$url = $this->removeRequestParam($fhead);
|
47 |
+
|
48 |
+
$filter = isset($confArray["filters"][$fhead]) ? $confArray["filters"][$fhead] : '';
|
49 |
+
$label = str_replace(" ","+",$facetLabel);
|
50 |
+
if(!in_array($fhead, $this->_singleSelectFilters) && !empty($filter)){
|
51 |
+
$att = preg_split('/(%2C|,)/', $filter);
|
52 |
+
if(!in_array($label, $att)){
|
53 |
+
$att[] = $label;
|
54 |
+
}
|
55 |
+
$url .= "&".str_replace(" ","_",$fhead).'='.implode('%2C', $att);
|
56 |
+
}else{
|
57 |
+
$url .= "&".str_replace(" ","_",$fhead).'='.$label;
|
58 |
+
}
|
59 |
+
return rtrim($url,'&');
|
60 |
+
}
|
61 |
+
|
62 |
+
/*
|
63 |
+
* @param filterkey string
|
64 |
+
* @param filterlist Array
|
65 |
+
* @return url
|
66 |
+
*/
|
67 |
+
protected function getClearLinkUrl($fKey,$flist){
|
68 |
+
$baseUrl = $this->removeRequestParam($fKey);
|
69 |
+
$linkUrl = $baseUrl.'&'.str_replace(' ', '_', $fKey)."=".implode('%2C', $flist);
|
70 |
+
return $linkUrl;
|
71 |
+
}
|
72 |
+
|
73 |
+
}
|
74 |
+
|
75 |
+
?>
|
app/code/community/Expertrec/Recommendation/Helper/Searchhelper.php
ADDED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Helper_Searchhelper extends Mage_Core_Helper_Abstract{
|
4 |
+
|
5 |
+
const SEARCH_LIST_API = 'search/api';
|
6 |
+
const SEARCH_FACET_LIST = 'search/facets_list';
|
7 |
+
|
8 |
+
|
9 |
+
protected $_facetList = array();
|
10 |
+
protected $_resultIds = array();
|
11 |
+
|
12 |
+
public function getResultIds(){
|
13 |
+
return $this->_resultIds;
|
14 |
+
}
|
15 |
+
|
16 |
+
protected function getFormatUrl($url){
|
17 |
+
$splitedUrl = explode("?", $url);
|
18 |
+
$newUrl = preg_replace('/\/ajax/',"",$splitedUrl[0]);
|
19 |
+
if(count($splitedUrl) == 2){
|
20 |
+
$newUrl .= '?'.$splitedUrl[1];
|
21 |
+
}
|
22 |
+
|
23 |
+
return $newUrl;
|
24 |
+
}
|
25 |
+
|
26 |
+
protected function getSearchApi($confArray){
|
27 |
+
|
28 |
+
$searchApi = "";
|
29 |
+
|
30 |
+
try{
|
31 |
+
$storeSearchApi = Mage::helper('expertrec_recommendation')->getConfig(self::SEARCH_LIST_API);
|
32 |
+
}catch(Exception $e){
|
33 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('Searchhelper::getting searchApi exception: '.$e->getMessage());
|
34 |
+
}
|
35 |
+
|
36 |
+
if(!empty($storeSearchApi)){
|
37 |
+
$searchApi = $storeSearchApi;
|
38 |
+
|
39 |
+
// searching for cat and other facets
|
40 |
+
// if(isset($confArray["facetPortion"]))
|
41 |
+
// {
|
42 |
+
// // $confArray["cat"] is to add cat and facets in searchapi
|
43 |
+
// $searchApi .= "?q=".urlencode($confArray["query"]).$confArray["facetPortion"]."&page=0&src=magento";
|
44 |
+
// }
|
45 |
+
|
46 |
+
$searchApi .= "?q=".urlencode($confArray["query"])."&page=0&src=magento";
|
47 |
+
|
48 |
+
$splitedUrl = explode("?",html_entity_decode($confArray["url"]));
|
49 |
+
|
50 |
+
if(count($splitedUrl)==2)
|
51 |
+
{
|
52 |
+
$searchApi .= "&oq=".urlencode($splitedUrl[1]);
|
53 |
+
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("The search URL sent to Expertrec BE is : ".print_r($searchApi,1),null);
|
58 |
+
|
59 |
+
//print_r($searchApi);
|
60 |
+
|
61 |
+
return $searchApi;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function getNonQueryUrlParameters($searchUrl)
|
65 |
+
{
|
66 |
+
//checking for cat and facets
|
67 |
+
$facetPortion = "";
|
68 |
+
$limitQuery = "";
|
69 |
+
|
70 |
+
if(!strpos($searchUrl,"?q")){
|
71 |
+
|
72 |
+
$parsedUrl = parse_url($searchUrl);
|
73 |
+
$newQuery = array();
|
74 |
+
$categoryArr = array();
|
75 |
+
$query1 = "";
|
76 |
+
|
77 |
+
$getCategory = explode("&",html_entity_decode($parsedUrl["query"]));
|
78 |
+
|
79 |
+
// spliting queries
|
80 |
+
foreach ($getCategory as $key => $value) {
|
81 |
+
list($key1, $val) = explode('=', $value);
|
82 |
+
|
83 |
+
//Excluding query term and cifr from categories
|
84 |
+
if(!in_array($key1,array("q","cifr","limit","dir","order")))
|
85 |
+
{
|
86 |
+
$categoryArr[$key1] = $val;
|
87 |
+
}
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
// getting all attributes
|
92 |
+
$attributes = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter(0)->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code');
|
93 |
+
|
94 |
+
// changing id to name for cat and facets
|
95 |
+
if(isset($categoryArr))
|
96 |
+
{
|
97 |
+
foreach ($categoryArr as $key => $value) {
|
98 |
+
|
99 |
+
if($key == 'cat')
|
100 |
+
{
|
101 |
+
$id = $value;
|
102 |
+
$cat = Mage::getModel('catalog/category')->load($id);
|
103 |
+
$newQuery['category'] = $cat->getName();
|
104 |
+
}
|
105 |
+
else
|
106 |
+
{
|
107 |
+
//For all attributes not under the sortables, use attribute table
|
108 |
+
if(!in_array($key,array("limit","order","dir")))
|
109 |
+
{
|
110 |
+
$attrMatched = false;
|
111 |
+
|
112 |
+
foreach ($attributes as $attribute) {
|
113 |
+
if ($attribute->getOptionId()==$value) {
|
114 |
+
$newQuery[$key] = $attribute->getValue();
|
115 |
+
$attrMatched = true;
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
//If the attribute is not a category and it is not matched, just pass it to BE.
|
120 |
+
if(!$attrMatched)
|
121 |
+
{
|
122 |
+
$newQuery[$key] = $value;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
else if($key == 'limit')
|
126 |
+
{
|
127 |
+
$limitQuery = "size=".urlencode($value);
|
128 |
+
}
|
129 |
+
else if($key == 'order')
|
130 |
+
{
|
131 |
+
$newQuery[$key] = $value." ".$categoryArr["dir"];
|
132 |
+
}
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
// changing to normal array
|
137 |
+
foreach($newQuery as $k=>$v)
|
138 |
+
{
|
139 |
+
$finalQuery[] = $k.":".urlencode($v);
|
140 |
+
}
|
141 |
+
|
142 |
+
// implode with &fq as in url
|
143 |
+
if(isset($finalQuery))
|
144 |
+
{
|
145 |
+
$query1 = "&fq=".implode("&fq=",$finalQuery);
|
146 |
+
}
|
147 |
+
|
148 |
+
|
149 |
+
if(strlen($limitQuery) > 0)
|
150 |
+
{
|
151 |
+
$query1 .= "&".$limitQuery;
|
152 |
+
}
|
153 |
+
|
154 |
+
$facetPortion = $query1;
|
155 |
+
|
156 |
+
}
|
157 |
+
|
158 |
+
}
|
159 |
+
|
160 |
+
return $facetPortion;
|
161 |
+
}
|
162 |
+
|
163 |
+
public function prepareLayer($requestParams){
|
164 |
+
$confArray = array();
|
165 |
+
$filters = array();
|
166 |
+
|
167 |
+
try{
|
168 |
+
$confArray["url"] = $this->getFormatUrl(Mage::helper('core/url')->getCurrentUrl(),$confArray);
|
169 |
+
$confArray["query"] = $requestParams['q'];
|
170 |
+
//$confArray["facetPortion"] = $this->getNonQueryUrlParameters($confArray["url"]);
|
171 |
+
|
172 |
+
//setup search url
|
173 |
+
$searchApi = $this->getSearchApi($confArray);
|
174 |
+
|
175 |
+
if(!empty($searchApi)){
|
176 |
+
|
177 |
+
//sending request
|
178 |
+
$resp = Mage::helper('expertrec_recommendation')->sendCurl($searchApi);
|
179 |
+
$response_json = json_decode($resp,true);
|
180 |
+
|
181 |
+
if(isset($response_json["res"]) && isset($response_json["res"]["count"])){
|
182 |
+
$confArray["count"] = (int)$response_json["res"]["count"];
|
183 |
+
}
|
184 |
+
|
185 |
+
//Initiate search layout
|
186 |
+
$layoutHelper = Mage::helper('expertrec_recommendation/search_layout')->init($confArray);
|
187 |
+
|
188 |
+
$searchListData = $response_json["results"];
|
189 |
+
$itemIds = array();
|
190 |
+
|
191 |
+
if(isset($searchListData))
|
192 |
+
{
|
193 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Number of items returned by Expertrec BE ".count($searchListData));
|
194 |
+
|
195 |
+
foreach ($searchListData as $item) {
|
196 |
+
$itemIds[] = $item['entity_id'];
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
$this->_resultIds = $itemIds;
|
201 |
+
}
|
202 |
+
|
203 |
+
}catch (Exception $e) {
|
204 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('Searchhelper::prepareLayer exception: '.$e->getMessage());
|
205 |
+
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
}
|
210 |
+
?>
|
app/code/community/Expertrec/Recommendation/Helper/Suggestionhelper.php
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Helper_Suggestionhelper extends Mage_Core_Helper_Abstract{
|
4 |
+
|
5 |
+
protected $_fileName='expertrec_sugg_feed';
|
6 |
+
protected $_oWriter;
|
7 |
+
protected $_ofields;
|
8 |
+
|
9 |
+
public function exportPopularProducts() {
|
10 |
+
try {
|
11 |
+
$logger = Mage::getSingleton('expertrec_recommendation/log');
|
12 |
+
$feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
|
13 |
+
$storeId = $feedConfig->storeId;
|
14 |
+
|
15 |
+
//load Store by given store id
|
16 |
+
$oStore = Mage::getModel('core/store')->load($storeId);
|
17 |
+
if(!isset($oStore)){
|
18 |
+
$logger->log("Store id is not set");
|
19 |
+
return false;
|
20 |
+
}
|
21 |
+
|
22 |
+
$logger->log("Beginning ".$this->_fileName." export for store #".$storeId);
|
23 |
+
$logger->logMemoryUsage();
|
24 |
+
$logger->log("Initialising file writers...");
|
25 |
+
$this->initWriters($oStore, $this->_fileName);
|
26 |
+
|
27 |
+
// Prepare the csv file header
|
28 |
+
$logger->log("Begin preparing header rows...");
|
29 |
+
|
30 |
+
//if any error occur during header writing, it will return false
|
31 |
+
if(!$this->prepareHeaders()){
|
32 |
+
return false;
|
33 |
+
}
|
34 |
+
|
35 |
+
$collection = $this->getSuggestionCollection($storeId)->setPageSize($feedConfig->pageSize);
|
36 |
+
|
37 |
+
$pageEnd = $feedConfig->pageEnd;
|
38 |
+
$lastPageNumber = $collection->getLastPageNumber();
|
39 |
+
|
40 |
+
if($pageEnd != 0 && $pageEnd < $lastPageNumber){
|
41 |
+
$pages = $pageEnd;
|
42 |
+
}else{
|
43 |
+
$pages = $lastPageNumber;
|
44 |
+
}
|
45 |
+
$logger->log("Total no. of pages for which we are collecting popular products feed in this reqeust: #".$pages);
|
46 |
+
|
47 |
+
for($currentPage = $feedConfig->pageStart; $currentPage <= $pages; $currentPage++) {
|
48 |
+
$logger->log("Collecting popular products feed for page: #".$currentPage);
|
49 |
+
$collection->setCurPage($currentPage);
|
50 |
+
foreach ($collection as $suggestion) {
|
51 |
+
$aRow = array();
|
52 |
+
foreach ($this->_ofields as $field) {
|
53 |
+
$fValue = $suggestion->getData($field);
|
54 |
+
if(empty($fValue)){
|
55 |
+
$fValue = 'None';
|
56 |
+
}
|
57 |
+
//$logger->log("key: ".$field." value: ".$fValue);
|
58 |
+
$aRow[$field] = $fValue;
|
59 |
+
}
|
60 |
+
|
61 |
+
//writing data row
|
62 |
+
$this->_oWriter->writeDataRow($aRow);
|
63 |
+
}
|
64 |
+
$collection->clear();
|
65 |
+
}
|
66 |
+
|
67 |
+
$this->closeWriters();
|
68 |
+
|
69 |
+
$logger->log("Finished ".$this->_fileName." data export for store #".$storeId);
|
70 |
+
$logger->logMemoryUsage();
|
71 |
+
|
72 |
+
return true;
|
73 |
+
|
74 |
+
} catch (Exception $e) {
|
75 |
+
$logger->log( "Exception during suggestion feed generation: ".$e->getMessage());
|
76 |
+
return false;
|
77 |
+
}
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
+
protected function getSuggestionCollection($storeId){
|
82 |
+
|
83 |
+
$collection = Mage::getResourceModel('catalogsearch/query_collection')
|
84 |
+
->addStoreFilter($storeId)
|
85 |
+
->setStoreId($storeId);
|
86 |
+
|
87 |
+
$collection->getSelect()->where('query_text != "__empty__"');
|
88 |
+
|
89 |
+
return $collection;
|
90 |
+
}
|
91 |
+
|
92 |
+
protected function initWriters(Mage_Core_Model_Store $oStore, $vFeedname) {
|
93 |
+
|
94 |
+
$oWriter = Mage::getModel('expertrec_recommendation/writer_csv')->init($oStore->getCode(), $vFeedname);
|
95 |
+
if ($oWriter instanceof Expertrec_Recommendation_Model_Writer_Abstract) {
|
96 |
+
$this->_oWriter = $oWriter;
|
97 |
+
}
|
98 |
+
|
99 |
+
return $this;
|
100 |
+
}
|
101 |
+
|
102 |
+
protected function prepareHeaders() {
|
103 |
+
try{
|
104 |
+
$this->_ofields = array('query_id','query_text','num_results','popularity','redirect',' synonym_for','is_active','is_processed','updated_at');
|
105 |
+
|
106 |
+
//writing header row
|
107 |
+
$this->_oWriter->setHeader($this->_ofields)->writeHeaderRow();
|
108 |
+
|
109 |
+
}catch (Exception $e) {
|
110 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error in writing header: ".$e->getMessage());
|
111 |
+
return false;
|
112 |
+
}
|
113 |
+
|
114 |
+
return true;
|
115 |
+
}
|
116 |
+
|
117 |
+
protected function closeWriters() {
|
118 |
+
$this->_oWriter->close();
|
119 |
+
return $this;
|
120 |
+
}
|
121 |
+
}
|
122 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Api/Request.php
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class to make the request to the Expertrec api
|
5 |
+
*
|
6 |
+
* @category Expertrec
|
7 |
+
* @package Expertrec_Recommendation
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
class Expertrec_Recommendation_Model_Api_Request extends Varien_Object {
|
11 |
+
|
12 |
+
const LOG_URL = "https://log.expertrec.com/v2/collect/";
|
13 |
+
|
14 |
+
/**
|
15 |
+
* end url where the request is firing
|
16 |
+
*/
|
17 |
+
protected $url = "";
|
18 |
+
|
19 |
+
protected $userId = "";
|
20 |
+
|
21 |
+
protected $prepareRequestStatus=false;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* http method
|
25 |
+
*/
|
26 |
+
protected $method = Zend_Http_Client::GET;
|
27 |
+
|
28 |
+
|
29 |
+
protected $headers = array();
|
30 |
+
|
31 |
+
|
32 |
+
public function setHeaders(array $headers) {
|
33 |
+
$this->headers = $headers;
|
34 |
+
return $this;
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
public function setHeader($header,$value) {
|
39 |
+
$this->headers[$header] = $value;
|
40 |
+
return $this;
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
public function setUrl($url) {
|
45 |
+
$this->url = $url;
|
46 |
+
return $this;
|
47 |
+
}
|
48 |
+
|
49 |
+
|
50 |
+
public function setUserId($uid){
|
51 |
+
$this->userId = $uid;
|
52 |
+
return $this;
|
53 |
+
}
|
54 |
+
|
55 |
+
|
56 |
+
public function setMethod($method) {
|
57 |
+
$this->method = $method;
|
58 |
+
return $this;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function setPrepareRequestStatus($status=false){
|
62 |
+
$this->prepareRequestStatus = $status;
|
63 |
+
return $this;
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Prepare Url and User_id before sending request
|
69 |
+
*/
|
70 |
+
|
71 |
+
public function prepareRequest(){
|
72 |
+
$uid = array_key_exists('ci_id', $_COOKIE) ? $_COOKIE['ci_id'] : 'Not_Found';
|
73 |
+
|
74 |
+
$mid = Mage::getModel('expertrec_recommendation/validate')->getSiteKey();
|
75 |
+
|
76 |
+
if (empty($mid)) {
|
77 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("merchant_id missing",Zend_Log::ERR);
|
78 |
+
$this->setPrepareRequestStatus(false);
|
79 |
+
return $this;
|
80 |
+
}
|
81 |
+
|
82 |
+
|
83 |
+
$this->setUserId($uid);
|
84 |
+
|
85 |
+
$this->setUrl(self::LOG_URL.$mid);
|
86 |
+
|
87 |
+
$this->setPrepareRequestStatus(true);
|
88 |
+
|
89 |
+
return $this;
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* @return Zend_Http_Client
|
94 |
+
*/
|
95 |
+
protected function getRestClient(){
|
96 |
+
|
97 |
+
$request = new Zend_Http_Client();
|
98 |
+
$request->setUri($this->url)
|
99 |
+
->setHeaders($this->headers)
|
100 |
+
->setMethod($this->method)
|
101 |
+
->setParameterGet("user",$this->userId);
|
102 |
+
|
103 |
+
if($this->method == Zend_Http_Client::GET) {
|
104 |
+
$request->setParameterGet($this->getData());
|
105 |
+
} else {
|
106 |
+
$request->setParameterPost($this->getData());
|
107 |
+
}
|
108 |
+
return $request;
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Method which will make the api call
|
115 |
+
*
|
116 |
+
* @return boolean
|
117 |
+
*/
|
118 |
+
public function sendRequest(){
|
119 |
+
$status = 0;
|
120 |
+
|
121 |
+
//if mid and uid are not set, it will not proceed
|
122 |
+
if(!$this->prepareRequestStatus){
|
123 |
+
return false;
|
124 |
+
}
|
125 |
+
|
126 |
+
try {
|
127 |
+
$request = $this->getRestClient();
|
128 |
+
$response = $request->request();
|
129 |
+
|
130 |
+
//set status code
|
131 |
+
$status = (int)$response->getStatus();
|
132 |
+
|
133 |
+
} catch (Zend_Http_Client_Exception $e) {
|
134 |
+
Mage::getSingleton('expertrec_recommendation/log')->log(sprintf($this->url ." failed because HTTP error: %s", $e->getMessage()),Zend_Log::ERR);
|
135 |
+
return false;
|
136 |
+
}
|
137 |
+
|
138 |
+
if($status >= 200 && $status < 400){
|
139 |
+
return true;
|
140 |
+
}
|
141 |
+
return false;
|
142 |
+
}
|
143 |
+
|
144 |
+
|
145 |
+
}
|
146 |
+
|
147 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Catalogsearch/Layer.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Model_Catalogsearch_Layer extends Mage_CatalogSearch_Model_Layer{
|
4 |
+
|
5 |
+
var $searchEnable;
|
6 |
+
const SEARCH_LIST_ENABLE = 'search/enable';
|
7 |
+
const SEARCH_CUSTOM_TEMPLATE = 'search/custom_template';
|
8 |
+
|
9 |
+
private function setSearchEnable()
|
10 |
+
{
|
11 |
+
|
12 |
+
$this->searchEnable = Mage::helper('expertrec_recommendation')->getConfig(self::SEARCH_LIST_ENABLE);
|
13 |
+
}
|
14 |
+
|
15 |
+
private function setExpertrecSearchData(){
|
16 |
+
try
|
17 |
+
{
|
18 |
+
$app = Mage::app();
|
19 |
+
$pageIdentifier = $app->getFrontController()->getAction()->getFullActionName();
|
20 |
+
|
21 |
+
if ($pageIdentifier === 'catalogsearch_result_index' ||
|
22 |
+
$pageIdentifier === 'expertrec_result_index')
|
23 |
+
{
|
24 |
+
|
25 |
+
$customTemplate = Mage::helper('expertrec_recommendation')->getConfig(self::SEARCH_CUSTOM_TEMPLATE);
|
26 |
+
|
27 |
+
$requestParams = $app->getRequest()->getParams();
|
28 |
+
|
29 |
+
if( (isset($this->searchEnable) && $this->searchEnable == "true") ||
|
30 |
+
(isset($requestParams["expertrec"]) && $requestParams["expertrec"] == "search"))
|
31 |
+
{
|
32 |
+
if(isset($customTemplate) && $customTemplate == "true")
|
33 |
+
{
|
34 |
+
$observer->getLayout()
|
35 |
+
->getUpdate()
|
36 |
+
->addHandle('expertrec_custom_autocomplete');
|
37 |
+
}
|
38 |
+
else
|
39 |
+
{
|
40 |
+
//This sets the result IDs
|
41 |
+
Mage::getSingleton('expertrec_recommendation/log')->log(" Fetching search results from expertec ");
|
42 |
+
|
43 |
+
Mage::helper('expertrec_recommendation/searchhelper')->prepareLayer($requestParams);
|
44 |
+
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
catch (Exception $e)
|
50 |
+
{
|
51 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('setExpertrecSearchData exception: '.$e->getMessage());
|
52 |
+
}
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Prepare product collection
|
59 |
+
*
|
60 |
+
* @param Mage_Catalog_Model_Resource_Eav_Resource_Product_Collection $collection
|
61 |
+
* @return Mage_Catalog_Model_Layer
|
62 |
+
*/
|
63 |
+
public function prepareProductCollection($collection)
|
64 |
+
{
|
65 |
+
$this->setSearchEnable();
|
66 |
+
|
67 |
+
if(isset($this->searchEnable) && $this->searchEnable == "true")
|
68 |
+
{
|
69 |
+
//Setting product IDs
|
70 |
+
$this->setExpertrecSearchData();
|
71 |
+
$product_ids = Mage::helper('expertrec_recommendation/searchhelper')->getResultIds();
|
72 |
+
Mage::getSingleton('expertrec_recommendation/log')->log(" The expertrec result IDs are ".count($product_ids));
|
73 |
+
|
74 |
+
$collection
|
75 |
+
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
|
76 |
+
->addFieldToFilter('entity_id',array('in'=>$product_ids))
|
77 |
+
->setStore(Mage::app()->getStore())
|
78 |
+
->addMinimalPrice()
|
79 |
+
->addFinalPrice()
|
80 |
+
->addTaxPercents()
|
81 |
+
->addStoreFilter()
|
82 |
+
->addUrlRewrite();
|
83 |
+
|
84 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
|
85 |
+
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
|
86 |
+
}
|
87 |
+
else
|
88 |
+
{
|
89 |
+
//Call parent function if search is not enabled
|
90 |
+
Mage::getSingleton('expertrec_recommendation/log')->log(" Default search returned products ");
|
91 |
+
return parent::prepareProductCollection($collection);
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
return $collection;
|
96 |
+
}
|
97 |
+
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Feed.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Feed generator class
|
5 |
+
*
|
6 |
+
* @category Expertrec
|
7 |
+
* @package Expertrec_Recommendation
|
8 |
+
* @copyright Copyright (c) 2016 CloudInfra LLC.
|
9 |
+
*/
|
10 |
+
class Expertrec_Recommendation_Model_Feed {
|
11 |
+
|
12 |
+
protected $_feedName='expertrec_feed';
|
13 |
+
|
14 |
+
public function exportFeeds() {
|
15 |
+
try {
|
16 |
+
$status = false;
|
17 |
+
//load Website by given website id
|
18 |
+
$website = Mage::getModel('core/website')->load(Mage::getSingleton('expertrec_recommendation/feed_feedconfig')->websiteId);
|
19 |
+
|
20 |
+
//load Store by given store id
|
21 |
+
$oStore = Mage::getModel('core/store')->load(Mage::getSingleton('expertrec_recommendation/feed_feedconfig')->storeId);
|
22 |
+
|
23 |
+
if(isset($website) && isset($oStore)){
|
24 |
+
//Appending website name to feedName
|
25 |
+
$this->_feedName .= '_'.str_replace(" ", "", (string)$website->getName());
|
26 |
+
|
27 |
+
//Start feed creation process
|
28 |
+
$status = Mage::getSingleton('expertrec_recommendation/feed_feedcreator')->export($website,$oStore,$this->_feedName);
|
29 |
+
|
30 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('Expertrec Datafeeder finished creating file');
|
31 |
+
}else{
|
32 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Website id and Store id are not set",Zend_Log::ERR);
|
33 |
+
}
|
34 |
+
return $status;
|
35 |
+
|
36 |
+
} catch (Exception $e) {
|
37 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Exception during feed generation: ".$e->getMessage(),Zend_Log::ERR);
|
38 |
+
return false;
|
39 |
+
}
|
40 |
+
|
41 |
+
}
|
42 |
+
}
|
43 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Feed/Feedconfig.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Model_Feed_Feedconfig {
|
4 |
+
|
5 |
+
var $pageSize=500;
|
6 |
+
var $imageWidth = 250;
|
7 |
+
var $imageHeight = 250;
|
8 |
+
var $generateImage=false;
|
9 |
+
var $websiteId=0;
|
10 |
+
var $storeId=0;
|
11 |
+
var $feedFilePath='';
|
12 |
+
var $pageStart=1;
|
13 |
+
var $pageEnd =0;
|
14 |
+
|
15 |
+
protected $secret;
|
16 |
+
protected $merchant_id;
|
17 |
+
|
18 |
+
public function setImageHeight($height=250) {
|
19 |
+
$this->imageHeight = (int)$height;
|
20 |
+
return $this;
|
21 |
+
}
|
22 |
+
|
23 |
+
public function setImageWidth($wid=250) {
|
24 |
+
$this->imageWidth = (int)$wid;
|
25 |
+
return $this;
|
26 |
+
}
|
27 |
+
|
28 |
+
public function setGenerateImage($img=true){
|
29 |
+
$this->generateImage = $img;
|
30 |
+
return $this;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function setWebsiteId($wid=0){
|
34 |
+
$this->websiteId = (int)$wid;
|
35 |
+
return $this;
|
36 |
+
}
|
37 |
+
|
38 |
+
public function setStoreId($sid=0){
|
39 |
+
$this->storeId = (int)$sid;
|
40 |
+
return $this;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function setFeedFilePath($path=''){
|
44 |
+
$this->feedFilePath=$path;
|
45 |
+
return $this;
|
46 |
+
}
|
47 |
+
|
48 |
+
public function setSecret($pwd=null){
|
49 |
+
$this->secret = $pwd;
|
50 |
+
return $this;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function getSecret(){
|
54 |
+
return $this->secret;
|
55 |
+
}
|
56 |
+
|
57 |
+
public function setMerchantId($mid=''){
|
58 |
+
$this->merchant_id = (string)$mid;
|
59 |
+
return $this;
|
60 |
+
}
|
61 |
+
|
62 |
+
public function getMerchantId(){
|
63 |
+
return $this->merchant_id;
|
64 |
+
}
|
65 |
+
|
66 |
+
public function setPageStart($st=1){
|
67 |
+
$this->pageStart = (int)$st;
|
68 |
+
return $this;
|
69 |
+
}
|
70 |
+
|
71 |
+
public function setPageEnd($en=0){
|
72 |
+
$this->pageEnd = (int)$en;
|
73 |
+
return $this;
|
74 |
+
}
|
75 |
+
public function setPageSize($size=500) {
|
76 |
+
$this->pageSize = (int)$size;
|
77 |
+
return $this;
|
78 |
+
}
|
79 |
+
}
|
app/code/community/Expertrec/Recommendation/Model/Feed/Feedcreator.php
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Feed generator class
|
5 |
+
*
|
6 |
+
* @category Expertrec
|
7 |
+
* @package Expertrec_Recommendation
|
8 |
+
* @copyright Copyright (c) 2016 CloudInfra LLC.
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php
|
10 |
+
*/
|
11 |
+
class Expertrec_Recommendation_Model_Feed_Feedcreator {
|
12 |
+
|
13 |
+
const CONFIG_HEADERS = 'expertrec/general/headers';
|
14 |
+
protected $_oWriter;
|
15 |
+
protected $_ofields=array();
|
16 |
+
|
17 |
+
public function export(Mage_Core_Model_Website $website, Mage_Core_Model_Store $oStore, $vFeedname) {
|
18 |
+
|
19 |
+
$logger = Mage::getSingleton('expertrec_recommendation/log');
|
20 |
+
|
21 |
+
try{
|
22 |
+
$logger->log("Beginning $vFeedname export for store #".$oStore->getId()." - ".$oStore->getName());
|
23 |
+
$logger->logMemoryUsage();
|
24 |
+
$logger->log("Initialising file writers...");
|
25 |
+
$this->initWriters($oStore, $vFeedname);
|
26 |
+
|
27 |
+
// Prepare the csv file header
|
28 |
+
$logger->log("Begin preparing header rows...");
|
29 |
+
$logger->logMemoryUsage();
|
30 |
+
|
31 |
+
//if any error occur during header writing, it will return false
|
32 |
+
if(!$this->prepareHeaders()){
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
|
36 |
+
// Initialise the formatter
|
37 |
+
$logger->log("Initialising Feed Formatter...");
|
38 |
+
$formatter = Mage::getSingleton('expertrec_recommendation/feed_formatter');
|
39 |
+
$formatter->init();
|
40 |
+
$logger->log("Initialised Feed Formatter.");
|
41 |
+
|
42 |
+
$logger->logMemoryUsage();
|
43 |
+
|
44 |
+
//get product collection
|
45 |
+
$logger->log("Getting product collection for store#".$oStore->getId()." - ".$oStore->getName());
|
46 |
+
|
47 |
+
$feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
|
48 |
+
|
49 |
+
$collection=Mage::getSingleton('expertrec_recommendation/feed_feedfilter')->addBasicFilter($website,$oStore)
|
50 |
+
->setPageSize($feedConfig->pageSize);
|
51 |
+
|
52 |
+
$pageEnd = $feedConfig->pageEnd;
|
53 |
+
$lastPageNumber = $collection->getLastPageNumber();
|
54 |
+
|
55 |
+
if($pageEnd != 0 && $pageEnd < $lastPageNumber){
|
56 |
+
$pages = $pageEnd;
|
57 |
+
}else{
|
58 |
+
$pages = $lastPageNumber;
|
59 |
+
}
|
60 |
+
$logger->log("Total no. of pages for which we are collecting feed in this reqeust: #".$pages);
|
61 |
+
|
62 |
+
for($currentPage = $feedConfig->pageStart; $currentPage <= $pages; $currentPage++) {
|
63 |
+
$logger->log("Collecting feed for page: #".$currentPage);
|
64 |
+
$collection->setCurPage($currentPage);
|
65 |
+
foreach ($collection as $product) {
|
66 |
+
|
67 |
+
$aRow = $formatter->prepareRow($this->_ofields,$product);
|
68 |
+
|
69 |
+
//writing data row
|
70 |
+
$this->_oWriter->writeDataRow($aRow);
|
71 |
+
}
|
72 |
+
$collection->clear();
|
73 |
+
}
|
74 |
+
|
75 |
+
$this->closeWriters();
|
76 |
+
|
77 |
+
$logger->log("Finished $vFeedname data export for store #".$oStore->getId()." - ".$oStore->getName());
|
78 |
+
$logger->logMemoryUsage();
|
79 |
+
return true;
|
80 |
+
}catch (Exception $e) {
|
81 |
+
$logger->log("Error in feed creation:--".$e->getMessage());
|
82 |
+
return false;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
|
87 |
+
protected function initWriters(Mage_Core_Model_Store $oStore, $vFeedname) {
|
88 |
+
|
89 |
+
$oWriter = Mage::getModel('expertrec_recommendation/writer_csv')->init($oStore->getCode(), $vFeedname);
|
90 |
+
if ($oWriter instanceof Expertrec_Recommendation_Model_Writer_Abstract) {
|
91 |
+
$this->_oWriter = $oWriter;
|
92 |
+
}
|
93 |
+
|
94 |
+
return $this;
|
95 |
+
}
|
96 |
+
|
97 |
+
protected function prepareHeaders() {
|
98 |
+
try{
|
99 |
+
$storedHeaders = Mage::getStoreConfig(self::CONFIG_HEADERS);
|
100 |
+
if (isset($storedHeaders)){
|
101 |
+
$header = explode(',', $storedHeaders);
|
102 |
+
}else{
|
103 |
+
$header = array();
|
104 |
+
}
|
105 |
+
|
106 |
+
if(empty($header)){
|
107 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Headers are not selected. Go to the info page,select headers and try again.");
|
108 |
+
return false;
|
109 |
+
}
|
110 |
+
|
111 |
+
//setting header fields array to this, so we can use it later
|
112 |
+
$this->_ofields=array_merge($header);
|
113 |
+
|
114 |
+
//writing header row
|
115 |
+
$this->_oWriter->setHeader($header)->writeHeaderRow();
|
116 |
+
|
117 |
+
}catch (Exception $e) {
|
118 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error in writing header: ".$e->getMessage());
|
119 |
+
return false;
|
120 |
+
}
|
121 |
+
|
122 |
+
return true;
|
123 |
+
}
|
124 |
+
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Closes the file writer once finished
|
128 |
+
*
|
129 |
+
* @return $this
|
130 |
+
*/
|
131 |
+
protected function closeWriters() {
|
132 |
+
$this->_oWriter->close();
|
133 |
+
return $this;
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
}
|
138 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Feed/Feedfilter.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Expertrec_Recommendation_Model_Feed_Feedfilter {
|
3 |
+
public function addBasicFilter(Mage_Core_Model_Website $website,Mage_Core_Model_Store $oStore){
|
4 |
+
|
5 |
+
$collection = Mage::getModel('catalog/product')->getCollection();
|
6 |
+
$visiblityCondition = array('in' => array(2,3,4));
|
7 |
+
$coreResource = Mage::getSingleton("core/resource");
|
8 |
+
$catalogInventoryTable = method_exists($coreResource, 'getTableName')
|
9 |
+
? $coreResource->getTableName('cataloginventory_stock_item') : 'cataloginventory_stock_item';
|
10 |
+
$stockfields = array("qty" => "qty", "manage_stock" => "manage_stock",
|
11 |
+
"use_config_manage_stock" => "use_config_manage_stock", "is_in_stock" => "is_in_stock");
|
12 |
+
|
13 |
+
$collection
|
14 |
+
->addWebsiteFilter($website->getWebsiteId())
|
15 |
+
->setStoreId($oStore->getId())
|
16 |
+
->addAttributeToSelect('*')
|
17 |
+
->joinTable($catalogInventoryTable, 'product_id=entity_id', $stockfields, null, 'left')
|
18 |
+
->addCategoryIds()
|
19 |
+
->addAttributeToFilter('visibility',$visiblityCondition)
|
20 |
+
->addPriceData(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID, $website->getWebsiteId());
|
21 |
+
|
22 |
+
//filters out products which are Disabled
|
23 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
|
24 |
+
|
25 |
+
return $collection;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Feed/Formatter.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Model_Feed_Formatter {
|
4 |
+
|
5 |
+
//getting image width and height from db
|
6 |
+
const IMAGE_WIDTH = 'expertrec/general/expertrec_image_width';
|
7 |
+
const IMAGE_HEIGHT = 'expertrec/general/expertrec_image_height';
|
8 |
+
|
9 |
+
protected $_oConfig= array();
|
10 |
+
|
11 |
+
public function init() {
|
12 |
+
$feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
|
13 |
+
$this->_oConfig['imageWidth'] = $feedConfig->imageWidth;
|
14 |
+
$this->_oConfig['imageHeight'] = $feedConfig->imageHeight;
|
15 |
+
$this->_oConfig['generateImage'] = $feedConfig->generateImage;
|
16 |
+
//Mage::getSingleton('expertrec_recommendation/log')->log($this->_oConfig['imageWidth']."---->".$this->_oConfig['imageHeight']."---->".$this->_oConfig['generateImage']);
|
17 |
+
return $this;
|
18 |
+
}
|
19 |
+
|
20 |
+
public function prepareRow($fields,$product) {
|
21 |
+
$aFeedRow = array();
|
22 |
+
|
23 |
+
foreach ($fields as $vKey) {
|
24 |
+
$vValue='';
|
25 |
+
$skey = (string) $vKey;
|
26 |
+
switch ($skey) {
|
27 |
+
case 'expert_image':
|
28 |
+
$vValue = $this->_getImage($skey,$product);
|
29 |
+
break;
|
30 |
+
case 'expert_smallImage':
|
31 |
+
$vValue = $this->_getImage($skey,$product);
|
32 |
+
break;
|
33 |
+
case 'expert_thumbnail':
|
34 |
+
$vValue = $this->_getImage($skey,$product);
|
35 |
+
break;
|
36 |
+
case 'expert_category':
|
37 |
+
$vValue = $this->_getCategories($product);
|
38 |
+
break;
|
39 |
+
case 'expert_url':
|
40 |
+
$vValue=$product->getProductUrl();
|
41 |
+
break;
|
42 |
+
case 'qty':
|
43 |
+
$vValue = (int)$product->getData("qty");
|
44 |
+
break;
|
45 |
+
default:
|
46 |
+
$vValue =$product->getData($skey);
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
if(empty($vValue)){
|
51 |
+
$vValue = (string)$vValue == "0" ? 0 : 'None';
|
52 |
+
}
|
53 |
+
//Mage::getSingleton('expertrec_recommendation/log')->log("data---------->: ".$skey."----------->".$vValue);
|
54 |
+
$aFeedRow[$skey] = $vValue;
|
55 |
+
}
|
56 |
+
|
57 |
+
return $aFeedRow;
|
58 |
+
}
|
59 |
+
|
60 |
+
protected function _getCategories($product){
|
61 |
+
$path = Mage::getSingleton('expertrec_recommendation/translator_category')
|
62 |
+
->translate($product);
|
63 |
+
return $path;
|
64 |
+
}
|
65 |
+
|
66 |
+
protected function _getImage($fieldName, $product) {
|
67 |
+
try {
|
68 |
+
$width = Mage::getStoreConfig(self::IMAGE_WIDTH);
|
69 |
+
$height = Mage::getStoreConfig(self::IMAGE_HEIGHT);
|
70 |
+
|
71 |
+
if('expert_image' == $fieldName && $this->_oConfig['generateImage']){
|
72 |
+
return (string)Mage::helper('catalog/image')->init($product, 'image')->resize($this->_oConfig['imageWidth'], $this->_oConfig['imageHeight']);
|
73 |
+
}
|
74 |
+
else if(!empty($width) && !empty($height)){
|
75 |
+
return (string)Mage::helper('catalog/image')->init($product, 'image')->resize($width, $height);
|
76 |
+
}
|
77 |
+
else if(empty($width) && !empty($height)){
|
78 |
+
return (string)Mage::helper('catalog/image')->init($product, 'image')->resize($this->_oConfig['imageWidth'], $height);
|
79 |
+
}
|
80 |
+
else if(empty($height) && !empty($width)){
|
81 |
+
return (string)Mage::helper('catalog/image')->init($product, 'image')->resize($width, $this->_oConfig['imageHeight']);
|
82 |
+
}
|
83 |
+
else if(empty($height) && empty($width)){
|
84 |
+
return (string)Mage::helper('catalog/image')->init($product, 'image')->resize($this->_oConfig['imageWidth'], $this->_oConfig['imageHeight']);
|
85 |
+
}
|
86 |
+
else if('expert_smallImage' == $fieldName){
|
87 |
+
return (string)Mage::helper('catalog/image')->init($product, 'image')->resize(250,250);
|
88 |
+
} else if ('expert_thumbnail' == $fieldName) {
|
89 |
+
return (string)Mage::helper('catalog/image')->init($product, 'image')->resize(80,80);
|
90 |
+
}
|
91 |
+
} catch (Exception $e) {
|
92 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error while fetching the image" . $e->getMessage());
|
93 |
+
}
|
94 |
+
|
95 |
+
return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getData('image');
|
96 |
+
}
|
97 |
+
}
|
98 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Log.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Simple logging interface for this extension
|
5 |
+
*
|
6 |
+
* @category Expertrec
|
7 |
+
* @package Expertrec_Recommendation
|
8 |
+
* @copyright Copyright (c) 2016 CloudInfra LLC.
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php
|
10 |
+
*/
|
11 |
+
class Expertrec_Recommendation_Model_Log {
|
12 |
+
|
13 |
+
// Name of the log file in var/log
|
14 |
+
const LOG_FILE = 'expertrec_feed.log';
|
15 |
+
const FEED_PATH = '/Expertrec';
|
16 |
+
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Logging for Feed exporter
|
20 |
+
* @param string $message
|
21 |
+
* @param int $level ZEND_LOG log level
|
22 |
+
* @param boolean $bDeveloperModeOnly True to log only in Developer mode
|
23 |
+
*/
|
24 |
+
public function log($message, $level = Zend_Log::INFO, $bDeveloperModeOnly = false) {
|
25 |
+
|
26 |
+
try{
|
27 |
+
$vFeedDir = Mage::getBaseDir().self::FEED_PATH;
|
28 |
+
if (!is_dir($vFeedDir)) {
|
29 |
+
$vFeedDir_status=mkdir($vFeedDir);
|
30 |
+
if(!$vFeedDir_status){
|
31 |
+
return $this;
|
32 |
+
}
|
33 |
+
}
|
34 |
+
$filename = $vFeedDir.'/'.self::LOG_FILE;
|
35 |
+
// open file
|
36 |
+
$fd = fopen($filename, "a+");
|
37 |
+
// append date/time to message
|
38 |
+
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . (string)$message;
|
39 |
+
// write string
|
40 |
+
fwrite($fd, $str . "\n");
|
41 |
+
// close file
|
42 |
+
fclose($fd);
|
43 |
+
}catch(Exception $e){
|
44 |
+
return $this;
|
45 |
+
}
|
46 |
+
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Logs the current php memory usage.
|
51 |
+
*
|
52 |
+
*/
|
53 |
+
public function logMemoryUsage() {
|
54 |
+
$iCurrentKb = ceil(memory_get_usage(true) / 1024);
|
55 |
+
$iPeakKb = ceil(memory_get_peak_usage(true) / 1024);
|
56 |
+
$this->log("Memory Usage - Current (Kb): ".$iCurrentKb." Peak (Kb): ".$iPeakKb, Zend_Log::DEBUG);
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
}
|
app/code/community/Expertrec/Recommendation/Model/Observer.php
ADDED
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @category Expertrec
|
6 |
+
* @package Expertrec_Recommendation
|
7 |
+
*
|
8 |
+
*/
|
9 |
+
class Expertrec_Recommendation_Model_Observer {
|
10 |
+
|
11 |
+
const CONFIG_HEADERS = 'expertrec/general/headers';
|
12 |
+
const FEED_LOG_ENDPOINT = 'expertrec/general/log_endpoint';
|
13 |
+
const SEARCH_LIST_ENABLE = 'search/enable';
|
14 |
+
const SEARCH_CUSTOM_TEMPLATE = 'search/custom_template';
|
15 |
+
/**
|
16 |
+
* Method to track the add to cart
|
17 |
+
*/
|
18 |
+
public function trackAddToCart(Varien_Event_Observer $observer) {
|
19 |
+
$product = $observer->getEvent()->getProduct();
|
20 |
+
if(!$product instanceof Mage_Catalog_Model_Product) {
|
21 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('AddToCart_Track: product is not a valid type',Zend_Log::ERR);
|
22 |
+
return $this;
|
23 |
+
}
|
24 |
+
|
25 |
+
//return unique product id
|
26 |
+
$uniqueId = Mage::helper('expertrec_recommendation')->getUniqueId($product);
|
27 |
+
|
28 |
+
//sending request
|
29 |
+
//return boolean
|
30 |
+
$response = Mage::getModel('expertrec_recommendation/api_request')
|
31 |
+
->setPrepareRequestStatus(false)
|
32 |
+
->setData(array(
|
33 |
+
'item' => $uniqueId,
|
34 |
+
'event' => 3,
|
35 |
+
'sku' => $product->getSku(),
|
36 |
+
'domain' => $_SERVER['HTTP_HOST'],
|
37 |
+
'ip' => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'])
|
38 |
+
)
|
39 |
+
->setHeader("User-Agent",$_SERVER['HTTP_USER_AGENT'])
|
40 |
+
->prepareRequest()
|
41 |
+
->sendRequest();
|
42 |
+
|
43 |
+
//Mage::getSingleton('expertrec_recommendation/log')->log("AddToCart_Track: request with uniqueId ".$uniqueId);
|
44 |
+
if(!$response) {
|
45 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('AddToCart_Track: request failed for product with uniqueId #'.$uniqueId,Zend_Log::ERR);
|
46 |
+
}
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Method to track orders
|
52 |
+
*/
|
53 |
+
public function trackOrder(Varien_Event_Observer $observer) {
|
54 |
+
|
55 |
+
$payment = $observer->getEvent()->getPayment();
|
56 |
+
|
57 |
+
if(!$payment instanceof Mage_Sales_Model_Order_Payment) {
|
58 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('Order_Track: payment is not a valid type',Zend_Log::ERR);
|
59 |
+
return $this;
|
60 |
+
}
|
61 |
+
$items = $payment->getOrder()->getAllVisibleItems();
|
62 |
+
|
63 |
+
if(!is_array($items)) {
|
64 |
+
return $this;
|
65 |
+
}
|
66 |
+
|
67 |
+
foreach($items as $item) {
|
68 |
+
if($item instanceof Mage_Sales_Model_Order) {
|
69 |
+
Mage::getSingleton('expertrec_recommendation/log')
|
70 |
+
->log('Order_Track: request failed because item is of instancetype '.get_class($item), Zend_Log::ERR);
|
71 |
+
continue;
|
72 |
+
}
|
73 |
+
$product =$item->getProduct();
|
74 |
+
if(!$product instanceof Mage_Catalog_Model_Product) {
|
75 |
+
return $this;
|
76 |
+
}
|
77 |
+
|
78 |
+
//return unique product id
|
79 |
+
$uniqueId = Mage::helper('expertrec_recommendation')->getUniqueId($product, $item);
|
80 |
+
|
81 |
+
//sending request
|
82 |
+
//return boolean
|
83 |
+
$response = Mage::getModel('expertrec_recommendation/api_request')
|
84 |
+
->setPrepareRequestStatus(false)
|
85 |
+
->setData(array(
|
86 |
+
'item' => $uniqueId,
|
87 |
+
'event' => 2,
|
88 |
+
'sku' => $item->getSku(),
|
89 |
+
'qty' => $item->getQtyOrdered(),
|
90 |
+
'price' => $item->getPriceInclTax(),
|
91 |
+
'domain' => $_SERVER['HTTP_HOST'],
|
92 |
+
'ip' => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'])
|
93 |
+
)
|
94 |
+
->setHeader("User-Agent",$_SERVER['HTTP_USER_AGENT'])
|
95 |
+
->prepareRequest()
|
96 |
+
->sendRequest();
|
97 |
+
|
98 |
+
//Mage::getSingleton('expertrec_recommendation/log')->log("Order_Track: request with uniqueId ".$uniqueId);
|
99 |
+
|
100 |
+
if(!$response) {
|
101 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('Order_Track: request failed for product with uniqueId #'.$uniqueId,Zend_Log::ERR);
|
102 |
+
}
|
103 |
+
}
|
104 |
+
return $this;
|
105 |
+
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Method to track remove item from cart
|
110 |
+
*/
|
111 |
+
public function trackRemoveItem(Varien_Event_Observer $observer){
|
112 |
+
|
113 |
+
$product = $observer->getQuoteItem()->getProduct();
|
114 |
+
if(!$product instanceof Mage_Catalog_Model_Product) {
|
115 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('RemoveItemFromCart_Track: product is not a valid type',Zend_Log::ERR);
|
116 |
+
return $this;
|
117 |
+
}
|
118 |
+
|
119 |
+
//return unique product id
|
120 |
+
$uniqueId = Mage::helper('expertrec_recommendation')->getUniqueId($product);
|
121 |
+
|
122 |
+
$sku = $product->getSku();
|
123 |
+
|
124 |
+
//sending request
|
125 |
+
//return boolean
|
126 |
+
$response = Mage::getModel('expertrec_recommendation/api_request')
|
127 |
+
->setPrepareRequestStatus(false)
|
128 |
+
->setData(array(
|
129 |
+
'item' => $uniqueId,
|
130 |
+
'event' => 11,
|
131 |
+
'sku' => $sku,
|
132 |
+
'domain' => $_SERVER['HTTP_HOST'],
|
133 |
+
'ip' => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'])
|
134 |
+
)
|
135 |
+
->setHeader("User-Agent",$_SERVER['HTTP_USER_AGENT'])
|
136 |
+
->prepareRequest()
|
137 |
+
->sendRequest();
|
138 |
+
|
139 |
+
//Mage::getSingleton('expertrec_recommendation/log')->log("RemoveItemFromCart_Track: request with uniqueId #".$uniqueId." and sku: ".$sku);
|
140 |
+
if(!$response) {
|
141 |
+
Mage::getSingleton('expertrec_recommendation/log')->log('RemoveItemFromCart_Track: request failed for product with uniqueId #'.$uniqueId,Zend_Log::ERR);
|
142 |
+
}
|
143 |
+
return $this;
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Method to track deleted item from catalog
|
148 |
+
*/
|
149 |
+
public function trackDelete(Varien_Event_Observer $observer) {
|
150 |
+
$logger = Mage::getSingleton('expertrec_recommendation/log');
|
151 |
+
$product = $observer->getEvent()->getDataObject();
|
152 |
+
|
153 |
+
if (!isset($product) ||
|
154 |
+
!$product instanceof Mage_Catalog_Model_Product ||
|
155 |
+
!$product->hasData('entity_id'))
|
156 |
+
{
|
157 |
+
|
158 |
+
$logger->log('DeleteCatalogProduct_Track: product is not a valid type');
|
159 |
+
return $this;
|
160 |
+
}
|
161 |
+
|
162 |
+
$finalUrl = $this->getFeedEndpoint();
|
163 |
+
if(empty($finalUrl)){
|
164 |
+
return $this;
|
165 |
+
}
|
166 |
+
|
167 |
+
//sending request
|
168 |
+
$response = Mage::getModel('expertrec_recommendation/api_request')
|
169 |
+
->setPrepareRequestStatus(false)
|
170 |
+
->setUserId('expertrec')
|
171 |
+
->setUrl($finalUrl)
|
172 |
+
->setData(array('item' => $product->getId()))
|
173 |
+
->setPrepareRequestStatus(true)
|
174 |
+
->sendRequest();
|
175 |
+
|
176 |
+
|
177 |
+
if(!$response) {
|
178 |
+
$logger->log('DeleteCatalogProduct_Track: request failed for product with Id #'.$product->getId());
|
179 |
+
}
|
180 |
+
|
181 |
+
return $this;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Method to track save product
|
186 |
+
*/
|
187 |
+
public function saveProduct(Varien_Event_Observer $observer){
|
188 |
+
$logger = Mage::getSingleton('expertrec_recommendation/log');
|
189 |
+
$product = $observer->getEvent()->getDataObject();
|
190 |
+
|
191 |
+
if (!isset($product) ||
|
192 |
+
!$product instanceof Mage_Catalog_Model_Product ||
|
193 |
+
!$product->hasData('entity_id'))
|
194 |
+
{
|
195 |
+
$logger->log('SaveCatalogProduct_Track: product is not a valid type');
|
196 |
+
return $this;
|
197 |
+
}
|
198 |
+
|
199 |
+
try{
|
200 |
+
$storedHeaders = Mage::getStoreConfig(self::CONFIG_HEADERS);
|
201 |
+
if (isset($storedHeaders)){
|
202 |
+
$header = explode(',', $storedHeaders);
|
203 |
+
}else{
|
204 |
+
$header = array();
|
205 |
+
}
|
206 |
+
|
207 |
+
if(!empty($header)){
|
208 |
+
$finalUrl = $this->getFeedEndpoint();
|
209 |
+
if(empty($finalUrl)){
|
210 |
+
return $this;
|
211 |
+
}
|
212 |
+
$resultArray = Mage::getSingleton('expertrec_recommendation/feed_formatter')
|
213 |
+
->init()
|
214 |
+
->prepareRow($header,$product);
|
215 |
+
|
216 |
+
|
217 |
+
//sending request
|
218 |
+
$response = Mage::getModel('expertrec_recommendation/api_request')
|
219 |
+
->setPrepareRequestStatus(false)
|
220 |
+
->setUserId('expertrec')
|
221 |
+
->setUrl($finalUrl)
|
222 |
+
->setMethod(Zend_Http_Client::POST)
|
223 |
+
->setData($resultArray)
|
224 |
+
->setHeader("Content-Type",'application/json')
|
225 |
+
->setPrepareRequestStatus(true)
|
226 |
+
->sendRequest();
|
227 |
+
|
228 |
+
|
229 |
+
if(!$response) {
|
230 |
+
$logger->log('SaveCatalogProduct_Track: request failed for product with Id #'.$product->getId());
|
231 |
+
}
|
232 |
+
}
|
233 |
+
}catch (Exception $e) {
|
234 |
+
$logger->log("SaveCatalogProduct_Track error: ".$e->getMessage());
|
235 |
+
}
|
236 |
+
return $this;
|
237 |
+
}
|
238 |
+
|
239 |
+
protected function getFeedEndpoint(){
|
240 |
+
try{
|
241 |
+
$endpoint = Mage::getStoreConfig(self::FEED_LOG_ENDPOINT);
|
242 |
+
$mid = Mage::getModel('expertrec_recommendation/validate')->getSiteKey();
|
243 |
+
|
244 |
+
if(empty($endpoint) || empty($mid)){
|
245 |
+
Mage::getSingleton('expertrec_recommendation/log')
|
246 |
+
->log("feed endpoint or merchand id is not configured Properly");
|
247 |
+
return '';
|
248 |
+
}
|
249 |
+
|
250 |
+
return rtrim($endpoint,'/').'/'.$mid;
|
251 |
+
}catch(Exception $e){
|
252 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error in getting feed endpoint: ".$e->getMessage());
|
253 |
+
return '';
|
254 |
+
}
|
255 |
+
}
|
256 |
+
}
|
257 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Translator/Category.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Translates category ids into a complete path.
|
5 |
+
*/
|
6 |
+
|
7 |
+
class Expertrec_Recommendation_Model_Translator_Category {
|
8 |
+
|
9 |
+
protected $_categoryPaths = array();
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Translates a category id stored in the supplied field to a full category path.
|
13 |
+
*
|
14 |
+
* @param $product
|
15 |
+
* @return string
|
16 |
+
*/
|
17 |
+
public function translate($product) {
|
18 |
+
$categoryPathArray=array();
|
19 |
+
$categoryArray = array_unique($product->getCategoryIds());
|
20 |
+
foreach ($categoryArray as $category_id) {
|
21 |
+
$curPath=$this->_getCategoryPath($category_id);
|
22 |
+
if(!empty($curPath) && !in_array($curPath, $categoryPathArray)){
|
23 |
+
$categoryPathArray[] = $curPath;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
return implode(chr(4),$categoryPathArray);
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* First check given category_id present in the global category_path Array or not. If not found then make a db call to
|
32 |
+
* fetch category path and set it to category_path array.
|
33 |
+
*
|
34 |
+
* @param category id
|
35 |
+
* @return category path
|
36 |
+
*/
|
37 |
+
protected function _getCategoryPath($categoryId) {
|
38 |
+
try{
|
39 |
+
if (!array_key_exists($categoryId, $this->_categoryPaths)) {
|
40 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
41 |
+
if ($category === null || !$category->getIsActive() || $category->getLevel() == 1){
|
42 |
+
$this->_categoryPaths[$categoryId] = '';
|
43 |
+
}else {
|
44 |
+
$parentCategoryPath = $this->_getCategoryPath($category->getParentId());
|
45 |
+
if ($parentCategoryPath == '') {
|
46 |
+
$this->_categoryPaths[$categoryId] = $category->getName();
|
47 |
+
}else {
|
48 |
+
$this->_categoryPaths[$categoryId] = $parentCategoryPath . chr(3) . $category->getName();
|
49 |
+
}
|
50 |
+
}
|
51 |
+
}
|
52 |
+
return $this->_categoryPaths[$categoryId];
|
53 |
+
}catch (Exception $e) {
|
54 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error in getCategoryPath: ".$e->getMessage());
|
55 |
+
return '';
|
56 |
+
}
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
}
|
app/code/community/Expertrec/Recommendation/Model/Validate.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
**Validate Password class
|
4 |
+
**
|
5 |
+
** @category Expertrec
|
6 |
+
** @package Expertrec_Recommendation
|
7 |
+
** @copyright Copyright (c) 2016 CloudInfra LLC.
|
8 |
+
**/
|
9 |
+
|
10 |
+
class Expertrec_Recommendation_Model_Validate {
|
11 |
+
|
12 |
+
const CONFIG_SECRET = 'expertrec/general/secret';
|
13 |
+
const CONFIG_MID = 'expertrec/general/mid';
|
14 |
+
const DEFAULT_SECRET = '519545f988a1c619ad9927f704914753';
|
15 |
+
|
16 |
+
/*
|
17 |
+
*@param password
|
18 |
+
*@return boolean
|
19 |
+
*/
|
20 |
+
public function checkPassword($Password){
|
21 |
+
if($Password == '' || $Password == self::DEFAULT_SECRET || $Password != $this->getPassword()){
|
22 |
+
return false;
|
23 |
+
}
|
24 |
+
return true;
|
25 |
+
}
|
26 |
+
|
27 |
+
public function getPassword(){
|
28 |
+
$storedPwd = base64_decode(Mage::getStoreConfig(self::CONFIG_SECRET));
|
29 |
+
return $storedPwd;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function getSiteKey(){
|
33 |
+
|
34 |
+
$storedMid = Mage::getSingleton('expertrec_recommendation/feed_feedconfig')->getMerchantId();
|
35 |
+
|
36 |
+
if(empty($storedMid)){
|
37 |
+
$storedMid = Mage::getStoreConfig(self::CONFIG_MID);
|
38 |
+
Mage::getSingleton('expertrec_recommendation/feed_feedconfig')
|
39 |
+
->setSecret($storedMid);
|
40 |
+
}
|
41 |
+
|
42 |
+
return $storedMid;
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
46 |
+
|
47 |
+
?>
|
app/code/community/Expertrec/Recommendation/Model/Writer/Abstract.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class Expertrec_Recommendation_Model_Writer_Abstract extends Varien_Object {
|
4 |
+
|
5 |
+
protected $_vFileExtension = 'csv';
|
6 |
+
const FEED_PATH = '/Expertrec';
|
7 |
+
|
8 |
+
public function init($vStoreCode, $vFeedname) {
|
9 |
+
$this->setFilename($this->_getFilename($vStoreCode, $vFeedname));
|
10 |
+
}
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Writes the header row to the file where appropriate
|
14 |
+
*
|
15 |
+
* @return $this
|
16 |
+
*/
|
17 |
+
abstract function writeHeaderRow();
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Writes a data row to the file
|
21 |
+
*
|
22 |
+
* @param array $aData Data to write. keys in this array must be the same as the keys in the setHeader array.
|
23 |
+
* @return $this
|
24 |
+
*/
|
25 |
+
abstract function writeDataRow($aRow);
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Closes the file once finished.
|
29 |
+
*/
|
30 |
+
abstract function close();
|
31 |
+
|
32 |
+
protected function _getFilename($vStoreCode, $vFeedname) {
|
33 |
+
$vFeedDir = Mage::getBaseDir().self::FEED_PATH;
|
34 |
+
if (!is_dir($vFeedDir)) {
|
35 |
+
$vFeedDir_status=mkdir($vFeedDir);
|
36 |
+
if(!$vFeedDir_status){
|
37 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Feed export directory does not exist: ".$vFeedDir);
|
38 |
+
return false;
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
//Appending storecode,timestamp and file_extension in feedname
|
43 |
+
$vtimestamp = (string)time();
|
44 |
+
$vFileName = $vFeedDir.'/'.$vFeedname.'-'.$vStoreCode.'_'.$vtimestamp.'.'.$this->_vFileExtension;
|
45 |
+
|
46 |
+
if (!file_exists($vFileName)) {
|
47 |
+
touch($vFileName);
|
48 |
+
}
|
49 |
+
//setting filename to file config
|
50 |
+
Mage::getSingleton('expertrec_recommendation/feed_feedconfig')->setFeedFilePath($vFileName);
|
51 |
+
|
52 |
+
if (is_writable($vFileName)) {
|
53 |
+
return $vFileName;
|
54 |
+
} else {
|
55 |
+
$this->_log("Feed file is not writable: ".$vFileName);
|
56 |
+
return false;
|
57 |
+
}
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
}
|
app/code/community/Expertrec/Recommendation/Model/Writer/Csv.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Very lightweight CSV file writer. No formatting or validation of the export
|
5 |
+
* data is performed, however care is taken to ensure fields are always
|
6 |
+
* exported in the correct order even when fields are missing.
|
7 |
+
*
|
8 |
+
* @category Expertrec
|
9 |
+
* @package Expertrec_Recommendation
|
10 |
+
* @copyright Copyright (c) 2016 CloudInfra LLC.
|
11 |
+
* @license http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* @method setHeader()
|
13 |
+
* @method getHeader()
|
14 |
+
* @method setStreamWriter()
|
15 |
+
* @method getStreamWriter()
|
16 |
+
*/
|
17 |
+
class Expertrec_Recommendation_Model_Writer_Csv extends Expertrec_Recommendation_Model_Writer_Abstract {
|
18 |
+
|
19 |
+
protected $_vFileExtension = 'csv';
|
20 |
+
|
21 |
+
public function __construct() {
|
22 |
+
$this
|
23 |
+
->setDelimiter("\002")
|
24 |
+
->setEnclosure('"');
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
public function init($vStoreCode, $vFeedname) {
|
29 |
+
parent::init($vStoreCode, $vFeedname);
|
30 |
+
|
31 |
+
// Fail if there are issues creating the output file.
|
32 |
+
if ($this->getFilename() === false) {
|
33 |
+
return false;
|
34 |
+
} else {
|
35 |
+
// Open the output file
|
36 |
+
$vFileName = $this->getFilename();
|
37 |
+
$oIo = new Varien_Io_File();
|
38 |
+
$oIo->open(array('path' => dirname($vFileName)));
|
39 |
+
$oIo->streamOpen($vFileName);
|
40 |
+
|
41 |
+
$this->setStreamWriter($oIo);
|
42 |
+
}
|
43 |
+
|
44 |
+
return $this;
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Writes the header row to the csv
|
50 |
+
*
|
51 |
+
* @return $this
|
52 |
+
*/
|
53 |
+
public function writeHeaderRow() {
|
54 |
+
$this->getStreamWriter()->streamWriteCsv($this->getHeader(), $this->getDelimiter(), $this->getEnclosure());
|
55 |
+
return $this;
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Writes a data row to the csv
|
61 |
+
*
|
62 |
+
* @param array $aData Data to write. keys in this array must be the same as the keys in the setHeader array.
|
63 |
+
* @return $this
|
64 |
+
*/
|
65 |
+
public function writeDataRow($aData) {
|
66 |
+
$aRow = array();
|
67 |
+
foreach ($this->getHeader() as $vKey) {
|
68 |
+
|
69 |
+
if (is_array($aData[$vKey])) {
|
70 |
+
$aRow[] = implode(',', $aData[$vKey]);
|
71 |
+
} else {
|
72 |
+
$aRow[] = $aData[$vKey];
|
73 |
+
}
|
74 |
+
|
75 |
+
}
|
76 |
+
$this->getStreamWriter()->streamWriteCsv($aRow, $this->getDelimiter(), $this->getEnclosure());
|
77 |
+
|
78 |
+
return $this;
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Closes the CSV file once finished.
|
84 |
+
*/
|
85 |
+
public function close() {
|
86 |
+
$this->getStreamWriter()->streamClose();
|
87 |
+
return $this;
|
88 |
+
}
|
89 |
+
}
|
app/code/community/Expertrec/Recommendation/controllers/Adminhtml/IndexController.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_Adminhtml_IndexController extends Mage_Core_Controller_Front_Action
|
4 |
+
{
|
5 |
+
|
6 |
+
public function indexAction(){
|
7 |
+
return $this->_redirectUrl("https://magento.expertrec.com/autocomplete/signup");
|
8 |
+
}
|
9 |
+
}
|
10 |
+
?>
|
app/code/community/Expertrec/Recommendation/controllers/ApiController.php
ADDED
@@ -0,0 +1,558 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_ApiController extends Mage_Core_Controller_Front_Action {
|
4 |
+
|
5 |
+
const CONFIG_HEADERS = 'expertrec/general/headers';
|
6 |
+
const SEARCH_LIST_ENABLE = 'search/enable';
|
7 |
+
const SEARCH_LIST_API = 'search/api';
|
8 |
+
const SEARCH_FACET_LIST = 'search/facets_list';
|
9 |
+
const SEARCH_SINGLE_SELECT_FILTERS = 'search/single_select_filters';
|
10 |
+
const SEARCH_IS_AJAX = 'search/is_ajax';
|
11 |
+
const SEARCH_ITEMS_PER_PAGE = 'search/items_per_page';
|
12 |
+
const SEARCH_DISPLAY_PAGES = 'search/display_pages';
|
13 |
+
const SEARCH_FETCH_PRICE = 'search/fetch_price';
|
14 |
+
const SEARCH_CONVERT_PRICE = 'search/convert_price';
|
15 |
+
const SEARCH_CUSTOM_TEMPLATE = 'search/custom_template';
|
16 |
+
const FEED_LOG_ENDPOINT = 'log_endpoint';
|
17 |
+
const FEED_UPLOAD_ENDPOINT = 'upload_endpoint';
|
18 |
+
const IS_UPLOAD_FEED = 'is_upload';
|
19 |
+
const IMAGE_WIDTH = 'expertrec/general/expertrec_image_width';
|
20 |
+
const IMAGE_HEIGHT = 'expertrec/general/expertrec_image_height';
|
21 |
+
|
22 |
+
const BUILD_NO = "1484913773";
|
23 |
+
private $_password;
|
24 |
+
|
25 |
+
// return websites and stores information
|
26 |
+
public function infoAction(){
|
27 |
+
|
28 |
+
//return array of all parameters sent
|
29 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
30 |
+
|
31 |
+
$Password = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
32 |
+
|
33 |
+
// Check password. if invalid password, it will not proceed.
|
34 |
+
if(!Mage::getModel('expertrec_recommendation/validate')->checkPassword($Password)){
|
35 |
+
die('ERROR: The specified password is invalid.');
|
36 |
+
}
|
37 |
+
|
38 |
+
$this->_password = Mage::getModel('expertrec_recommendation/validate')->getPassword();
|
39 |
+
|
40 |
+
// Set character set to UTF-8
|
41 |
+
header("Content-Type: text/html; charset=UTF-8");
|
42 |
+
?>
|
43 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
44 |
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
45 |
+
<head>
|
46 |
+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
47 |
+
<title>Expertrec Feed Collection Api</title>
|
48 |
+
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
|
49 |
+
<style type="text/css">
|
50 |
+
table {border-spacing: 0;border-collapse: collapse;width: 100%;}
|
51 |
+
.table-hover > tbody > tr:hover {background-color: #f5f5f5;}
|
52 |
+
tbody td, thead th{padding: 8px;line-height: 1.42857143;vertical-align: top;border-top: 1px solid #ddd;text-align:left;}
|
53 |
+
thead:first-child > tr:first-child > th {border-top: 0;}
|
54 |
+
thead th {vertical-align: bottom;border-bottom:2px solid #ddd;background-color:#f5f5f5;text-align:center;}
|
55 |
+
fieldset { display: block;margin:10px 2px;padding: .35em .625em .75em; border: 1px solid silver; }
|
56 |
+
legend{padding: 0px 5px; width: auto; border: 0px none;margin:0;}
|
57 |
+
fieldset p { text-align: left; display: block; }
|
58 |
+
#searchConfSection input[type="checkbox"]{bottom: 2px;}
|
59 |
+
</style>
|
60 |
+
</head>
|
61 |
+
<body>
|
62 |
+
<div class="container-fluid">
|
63 |
+
<?php
|
64 |
+
$version = (string)Mage::getConfig()->getNode('modules/Expertrec_Recommendation/version');
|
65 |
+
echo "<h4 style='margin:20px auto 10px;'>Extension Version: <span style='color:red;'>".$version."</span></h4>";
|
66 |
+
echo "<h4 style='margin:10px auto;'>Extension Build No.: <span style='color:red;'>".self::BUILD_NO."</span></h4>";
|
67 |
+
try{
|
68 |
+
echo "<h4 style='margin:10px auto;'>Magento Version: <span style='color:red;'>".Mage::getVersion()."</span></h4>";
|
69 |
+
}catch(Exception $em){};
|
70 |
+
?>
|
71 |
+
<ul class="nav nav-tabs" style="margin-top:20px;">
|
72 |
+
<li class="active"><a data-toggle="tab" href="#apiSection">Api</a></li>
|
73 |
+
<li><a data-toggle="tab" href="#feedHeader">Feed Header</a></li>
|
74 |
+
<li><a data-toggle="tab" href="#feedEndpointSection">Feed Config</a></li>
|
75 |
+
<li><a data-toggle="tab" href="#searchConfSection">Search</a></li>
|
76 |
+
<li><a data-toggle="tab" href="#siteDetailsSection">Details</a></li>
|
77 |
+
</ul>
|
78 |
+
<div style="clear:both;"></div>
|
79 |
+
<div class="tab-content">
|
80 |
+
<div id="apiSection" class="tab-pane fade in active">
|
81 |
+
<div style="margin-top:20px;">
|
82 |
+
<fieldset>
|
83 |
+
<legend>Getting Feeds Api</legend>
|
84 |
+
<table class="table-hover" style="margin: 1em auto;">
|
85 |
+
<thead>
|
86 |
+
<tr>
|
87 |
+
<th>Website ID</th>
|
88 |
+
<th>Website Name</th>
|
89 |
+
<th>Store ID</th>
|
90 |
+
<th>Store Name</th>
|
91 |
+
<th>Total Pages</th>
|
92 |
+
<th>Url</th>
|
93 |
+
</tr>
|
94 |
+
</thead>
|
95 |
+
<tbody>
|
96 |
+
<?php
|
97 |
+
|
98 |
+
//site url
|
99 |
+
$baseUrl=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
100 |
+
$feedFilter = Mage::getSingleton('expertrec_recommendation/feed_feedfilter');
|
101 |
+
|
102 |
+
// List all website-stores
|
103 |
+
$websiteCollection = Mage::getModel('core/website')->getCollection()->load();
|
104 |
+
foreach ($websiteCollection as $website){
|
105 |
+
$wid=$website->getWebsiteId();
|
106 |
+
foreach ($website->getGroups() as $group) {
|
107 |
+
$stores = $group->getStores();
|
108 |
+
foreach ($stores as $oStore) {
|
109 |
+
$sid=$oStore->getId();
|
110 |
+
$apiUrl=$baseUrl.'index.php/expertrec-feed?secret='.$this->_password.'&cmd=export&wid='.$wid.'&sid='.$sid;
|
111 |
+
// Display the store-website details with feed api
|
112 |
+
echo '<tr>';
|
113 |
+
echo '<td style="text-align:center;">'.$wid.'</td>';
|
114 |
+
echo '<td style="text-align:center;">'.$website->getName().'</td>';
|
115 |
+
echo '<td style="text-align:center;">'.$sid.'</td>';
|
116 |
+
echo '<td style="text-align:center;">'.$oStore->getName().'</td>';
|
117 |
+
try{
|
118 |
+
$collection=$feedFilter->addBasicFilter($website,$oStore)
|
119 |
+
->setPageSize(500);
|
120 |
+
$pages = $collection->getLastPageNumber();
|
121 |
+
echo '<td style="text-align:center;">'.(string)$pages.'</td>';
|
122 |
+
|
123 |
+
}catch(Exception $e){
|
124 |
+
echo '<td style="text-align:center;"><b style="color:red;">Error: </b>'.$e->getMessage().'</td>';
|
125 |
+
}
|
126 |
+
echo '<td><a href="'.$apiUrl.'">'.$apiUrl.'</a></td>';
|
127 |
+
echo '</tr>';
|
128 |
+
}
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
?>
|
133 |
+
</tbody>
|
134 |
+
</table>
|
135 |
+
</fieldset>
|
136 |
+
|
137 |
+
</div>
|
138 |
+
<p>
|
139 |
+
<strong>Note:</strong><br />
|
140 |
+
<span>
|
141 |
+
1. Each page contains 500 products.<br />
|
142 |
+
2. For Getting custom image size, kindly add <b>width</b> and <b>height</b> parameter in the api url.
|
143 |
+
</span>
|
144 |
+
</p>
|
145 |
+
<fieldset>
|
146 |
+
<legend>Example</legend>
|
147 |
+
<?php
|
148 |
+
|
149 |
+
$apiUrlWithCustomConf=$baseUrl.'index.php/expertrec-feed?secret='.$this->_password.'&cmd=export&wid=1&sid=1';
|
150 |
+
|
151 |
+
echo '<p><b>With Custom image size</b><br />';
|
152 |
+
echo '<p><a href="'.$apiUrlWithCustomConf.'&width=170&height=170">'.$apiUrlWithCustomConf.'&width=170&height=170</a></p>';
|
153 |
+
|
154 |
+
echo '<p><b>With pagination without page size(default page size is 500)</b><br />';
|
155 |
+
echo '<p><a href="'.$apiUrlWithCustomConf.'&ps=1&pe=2">'.$apiUrlWithCustomConf.'&ps=1&pe=2</a></p>';
|
156 |
+
|
157 |
+
echo '<p><b>With pagination & page size</b><br />';
|
158 |
+
echo '<p><a href="'.$apiUrlWithCustomConf.'&ps=1&pe=2&psize=50">'.$apiUrlWithCustomConf.'&ps=1&pe=2&psize=50</a></p>';
|
159 |
+
echo '</fieldset>';
|
160 |
+
|
161 |
+
echo $this->displaySuggestionApi($baseUrl);
|
162 |
+
echo $this->displayLogApi($baseUrl);
|
163 |
+
?>
|
164 |
+
|
165 |
+
</div> <!-- api section end -->
|
166 |
+
|
167 |
+
<!-- header section start -->
|
168 |
+
<div id="feedHeader" class="tab-pane fade">
|
169 |
+
<div style="margin-top:20px">
|
170 |
+
<?php
|
171 |
+
$allAttribute = $this->getAllAttributes();
|
172 |
+
//display header form
|
173 |
+
echo $this->displayHeaderForm($baseUrl,$allAttribute);
|
174 |
+
?>
|
175 |
+
</div>
|
176 |
+
</div> <!-- header section end -->
|
177 |
+
|
178 |
+
<!-- Feed api configuration section start -->
|
179 |
+
<div id="feedEndpointSection" class="tab-pane fade">
|
180 |
+
<div style="margin-top:20px">
|
181 |
+
<?php echo $this->displayFeedConf($baseUrl); ?>
|
182 |
+
</div>
|
183 |
+
</div>
|
184 |
+
<!-- Feed api configuration section end -->
|
185 |
+
|
186 |
+
<!-- search section start -->
|
187 |
+
<div id="searchConfSection" class="tab-pane fade">
|
188 |
+
<div style="margin-top:20px">
|
189 |
+
<?php echo $this->displaySearchConf($baseUrl); ?>
|
190 |
+
</div>
|
191 |
+
</div>
|
192 |
+
|
193 |
+
<!-- site details -->
|
194 |
+
<div id="siteDetailsSection" class="tab-pane fade">
|
195 |
+
<div style="margin-top:20px">
|
196 |
+
<?php echo $this->displaySiteDetails(); ?>
|
197 |
+
</div>
|
198 |
+
</div>
|
199 |
+
</div> <!-- tab-content end-->
|
200 |
+
</div> <!-- container-fluid end-->
|
201 |
+
<!-- script section-->
|
202 |
+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
203 |
+
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
204 |
+
|
205 |
+
</body>
|
206 |
+
</html>
|
207 |
+
<?php
|
208 |
+
|
209 |
+
}
|
210 |
+
|
211 |
+
private function displayLogApi($baseUrl){
|
212 |
+
$result = '<div style="margin-top:20px">';
|
213 |
+
$result .= '<fieldset>';
|
214 |
+
$result .= '<legend>Getting log & Cleaning Expertrec Directory Api\'s</legend>';
|
215 |
+
|
216 |
+
$logUrl = $baseUrl.'index.php/expertrec-feed/index/getlog?secret='.$this->_password;
|
217 |
+
$cleanDirUrl = $baseUrl.'index.php/expertrec-feed/index/clean?secret='.$this->_password;
|
218 |
+
|
219 |
+
$result .= '<p><b>Get log url</b><br />';
|
220 |
+
$result .= '<p><a href="'.$logUrl.'">'.$logUrl.'</a></p>';
|
221 |
+
$result .= '<p><b>Clean directory url</b><br />';
|
222 |
+
$result .= '<p><a href="'.$cleanDirUrl.'" target="_blank">'.$cleanDirUrl.'</a></p>';
|
223 |
+
|
224 |
+
$result .= '</fieldset>';
|
225 |
+
$result .= '</div>';
|
226 |
+
|
227 |
+
return $result;
|
228 |
+
|
229 |
+
}
|
230 |
+
|
231 |
+
private function displaySuggestionApi($baseUrl){
|
232 |
+
$result = '<div style="margin-top:20px">';
|
233 |
+
$result .= '<fieldset>';
|
234 |
+
$result .= '<legend>Getting Popular products Api</legend>';
|
235 |
+
|
236 |
+
$apiUrlWithCustomConf=$baseUrl.'index.php/expertrec-feed?secret='.$this->_password.'&cmd=getpp&wid=1&sid=1';
|
237 |
+
|
238 |
+
$result .= '<p><b>Without pagination</b><br />';
|
239 |
+
$result .= '<p><a href="'.$apiUrlWithCustomConf.'">'.$apiUrlWithCustomConf.'</a></p>';
|
240 |
+
|
241 |
+
$result .= '<p><b>With pagination without page size(default page size is 500)</b><br />';
|
242 |
+
$result .= '<p><a href="'.$apiUrlWithCustomConf.'&ps=1&pe=2">'.$apiUrlWithCustomConf.'&ps=1&pe=2</a></p>';
|
243 |
+
|
244 |
+
$result .= '<p><b>With pagination & page size</b><br />';
|
245 |
+
$result .= '<p><a href="'.$apiUrlWithCustomConf.'&ps=1&pe=2&psize=50">'.$apiUrlWithCustomConf.'&ps=1&pe=2&psize=50</a></p>';
|
246 |
+
|
247 |
+
$result .= '</fieldset>';
|
248 |
+
$result .= '</div>';
|
249 |
+
|
250 |
+
return $result;
|
251 |
+
}
|
252 |
+
|
253 |
+
private function getAllAttributes(){
|
254 |
+
$attrArray = array('qty','is_in_stock','expert_image','expert_smallImage','expert_thumbnail','expert_category','expert_url','final_price','entity_id','attribute_set_id','type_id','entity_type_id','rating_summary');
|
255 |
+
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')->getItems();
|
256 |
+
|
257 |
+
foreach ($attributes as $attribute) {
|
258 |
+
$attrCode = $attribute->getAttributeCode();
|
259 |
+
if (!in_array($attrCode, $attrArray)) {
|
260 |
+
$attrArray[] = $attrCode;
|
261 |
+
}
|
262 |
+
|
263 |
+
}
|
264 |
+
return $attrArray;
|
265 |
+
}
|
266 |
+
|
267 |
+
private function displayHeaderForm($baseUrl,$attributes){
|
268 |
+
$saveHeaderUrl = $baseUrl."index.php/expertrec-feed/config/saveheaders?secret=".$this->_password;
|
269 |
+
|
270 |
+
$result = '<style type="text/css"> .setHeadersForm label{padding:0px 10px 10px 0px;} .setHeadersForm input{vertical-align: middle;} </style>';
|
271 |
+
|
272 |
+
$result .= '<script type="text/javascript">';
|
273 |
+
$result .= 'function toggle_select(){var checkboxes = document.getElementsByName("check_list[]"); var button = document.getElementById("toggleSelect"); if(button.value == "Select All"){for (var i in checkboxes){checkboxes[i].checked = "checked"; } button.value = "Deselect All"}else{for (var i in checkboxes){checkboxes[i].checked = ""; } button.value = "Select All";}}';
|
274 |
+
$result .= '</script>';
|
275 |
+
|
276 |
+
$storedHeaders = Mage::getStoreConfig(self::CONFIG_HEADERS);
|
277 |
+
if (isset($storedHeaders)){
|
278 |
+
$storedHeadersArray = explode(',', $storedHeaders);
|
279 |
+
}
|
280 |
+
|
281 |
+
$result .= '<fieldset>';
|
282 |
+
$result .= '<legend>Configure Feed Headers</legend>';
|
283 |
+
|
284 |
+
$result .= '<form class="setHeadersForm" action="'.$saveHeaderUrl.'" method="post" role="form" target="_blank">';
|
285 |
+
|
286 |
+
foreach ($attributes as $attr) {
|
287 |
+
if (isset($storedHeadersArray) && in_array($attr, $storedHeadersArray)){
|
288 |
+
$result .= '<input type="checkbox" id="'.$attr.'" name="check_list[]" value="'.$attr.'" checked>';
|
289 |
+
}else{
|
290 |
+
$result .= '<input type="checkbox" id="'.$attr.'" name="check_list[]" value="'.$attr.'">';
|
291 |
+
}
|
292 |
+
$result .= '<label for="'.$attr.'">'.$attr.'</label>';
|
293 |
+
}
|
294 |
+
|
295 |
+
// adding image width and height
|
296 |
+
$result .= '<div style="display:block"><label for="imagewidth">Image Width</label><input type="text" id="imagewidth" name="imagewidth" placeholder="Give image width" value="'.Mage::getStoreConfig(self::IMAGE_WIDTH).'"></div>';
|
297 |
+
$result .= '<div style="display:block"><label for="imageheight">Image Height</label><input type="text" id="imageheight" name="imageheight" placeholder="Give image height" value="'.Mage::getStoreConfig(self::IMAGE_HEIGHT).'"></div>';
|
298 |
+
|
299 |
+
$result .= '<div style="text-align:center;margin:10px auto;"> ';
|
300 |
+
$result .= '<input type="button" class="btn btn-md btn-primary" id="toggleSelect" value="Select All" onClick="toggle_select()" style="padding:5px; margin: 5px;"/>';
|
301 |
+
$result .= '<input type="submit" class="btn btn-md btn-primary" name="selected_headers" value="Submit" style= "padding:5px; margin: 5px;"/>';
|
302 |
+
$result .= '</div>';
|
303 |
+
$result .= '</form>';
|
304 |
+
$result .= '</fieldset>';
|
305 |
+
|
306 |
+
$result .= '<fieldset style="margin-top:20px;">';
|
307 |
+
$result .= '<legend>Selected Headers</legend>';
|
308 |
+
$result .= '<div class="setHeadersForm">';
|
309 |
+
|
310 |
+
if (isset($storedHeadersArray) && count($storedHeadersArray) > 0){
|
311 |
+
foreach ($storedHeadersArray as $header) {
|
312 |
+
$result .= '<input type="checkbox" name="'.$header.'" value="'.$header.'" disabled checked>';
|
313 |
+
$result .= '<label>'.$header.'</label>';
|
314 |
+
}
|
315 |
+
}
|
316 |
+
|
317 |
+
$result .= '</div>';
|
318 |
+
$result .= '</fieldset>';
|
319 |
+
|
320 |
+
return $result;
|
321 |
+
}
|
322 |
+
|
323 |
+
private function displaySearchConf($baseUrl){
|
324 |
+
$saveSearchUrl = $baseUrl."index.php/expertrec-feed/config/savesearch?secret=".$this->_password;
|
325 |
+
$result = '<fieldset>';
|
326 |
+
$result .= '<legend>Configure Search</legend>';
|
327 |
+
$result .= '<form class="form-horizontal" action="'.$saveSearchUrl.'" method="post" role="form" target="_blank">';
|
328 |
+
|
329 |
+
$textArray = array("api"=>"Search endpoint", "facet_list"=>"Facet list comma separated", "single_select_filter"=>"Single select filters comma separated", "items_per_page"=>"No of items per page","display_pages"=>"No. of pages to display");
|
330 |
+
|
331 |
+
$textToStoreKeyMapArray = array("api"=>self::SEARCH_LIST_API,"facet_list"=>self::SEARCH_FACET_LIST,"single_select_filter"=>self::SEARCH_SINGLE_SELECT_FILTERS,"items_per_page"=>self::SEARCH_ITEMS_PER_PAGE,"display_pages"=>self::SEARCH_DISPLAY_PAGES);
|
332 |
+
|
333 |
+
$chekboxArray = array("search_enable"=>self::SEARCH_LIST_ENABLE,"fetch_price"=>self::SEARCH_FETCH_PRICE,"convert_price"=>self::SEARCH_CONVERT_PRICE,"is_ajax"=>self::SEARCH_IS_AJAX,"custom_template"=>self::SEARCH_CUSTOM_TEMPLATE);
|
334 |
+
|
335 |
+
// input
|
336 |
+
foreach ($textArray as $tKey => $tValue) {
|
337 |
+
$label = ucwords(str_replace("_", " ", $tKey));
|
338 |
+
$storeValue = Mage::helper('expertrec_recommendation')->getConfig($textToStoreKeyMapArray[$tKey]);
|
339 |
+
|
340 |
+
$result .= '<div class="form-group">';
|
341 |
+
$result .= '<label class="control-label col-sm-2" for="search_'.$tKey.'">'.$label.':</label>';
|
342 |
+
$result .= '<div class="col-sm-8">';
|
343 |
+
if(isset($storeValue)){
|
344 |
+
$result .= '<input type="text" class="form-control" name="'.$tKey.'" value="'.$storeValue.'" id="search_'.$tKey.'" placeholder="'.$tValue.'">';
|
345 |
+
}else{
|
346 |
+
$result .= '<input type="text" class="form-control" name="'.$tKey.'" id="search_'.$tKey.'" placeholder="'.$tValue.'">';
|
347 |
+
}
|
348 |
+
$result .= '</div>';
|
349 |
+
$result .= '</div>';
|
350 |
+
}
|
351 |
+
|
352 |
+
//checkbox
|
353 |
+
$result .= '<div class="form-group">';
|
354 |
+
$result .= '<div class="col-sm-2"></div>';
|
355 |
+
$result .= '<div class="col-sm-8">';
|
356 |
+
foreach ($chekboxArray as $cKey => $cValue) {
|
357 |
+
$label = ucwords(str_replace("_", " ", $cKey));
|
358 |
+
$storeValue = Mage::helper('expertrec_recommendation')->getConfig($cValue);
|
359 |
+
$checked = isset($storeValue) && $storeValue == "true" ? "checked" :'';
|
360 |
+
|
361 |
+
$result .= '<div class="col-sm-2">';
|
362 |
+
$result .= '<div class="checkbox">';
|
363 |
+
$result .= '<label><input type="checkbox" name="search_check_list[]" value="'.$cKey.'" '.$checked.'>'.$label.'</label>';
|
364 |
+
$result .= '</div>';
|
365 |
+
$result .= '</div>';
|
366 |
+
|
367 |
+
}
|
368 |
+
$result .= '</div>';
|
369 |
+
$result .= '</div>';
|
370 |
+
$result .= '<div style="text-align:center;margin:10px auto;">';
|
371 |
+
$result .= '<input type="submit" class="btn btn-md btn-primary" name="selected_search" value="Submit" style="padding:5px; "/>';
|
372 |
+
$result .= '</div>';
|
373 |
+
$result .= '</form>';
|
374 |
+
$result .= '</fieldset>';
|
375 |
+
|
376 |
+
return $result;
|
377 |
+
|
378 |
+
}
|
379 |
+
|
380 |
+
private function displayFeedConf($baseUrl){
|
381 |
+
$saveFeedApiUrl = $baseUrl."index.php/expertrec-feed/config/savefeedconf?secret=".$this->_password;
|
382 |
+
$result = '<fieldset>';
|
383 |
+
$result .= '<legend>Configure Search</legend>';
|
384 |
+
$result .= '<form class="form-horizontal" action="'.$saveFeedApiUrl.'" method="post" role="form" target="_blank">';
|
385 |
+
|
386 |
+
$textArray = array("log_api"=>"Feed log endpoint", "upload_api"=>"Feed upload endpoint");
|
387 |
+
$textToStoreKeyMapArray = array("log_api"=>self::FEED_LOG_ENDPOINT,"upload_api"=>self::FEED_UPLOAD_ENDPOINT);
|
388 |
+
|
389 |
+
foreach ($textArray as $tKey => $tValue) {
|
390 |
+
$label = ucwords(str_replace("_", " ", $tKey));
|
391 |
+
$storeValue = Mage::helper('expertrec_recommendation')->getConfig($textToStoreKeyMapArray[$tKey]);
|
392 |
+
|
393 |
+
$result .= '<div class="form-group">';
|
394 |
+
$result .= '<label class="control-label col-sm-2" for="search_'.$tKey.'">'.$label.':</label>';
|
395 |
+
$result .= '<div class="col-sm-8">';
|
396 |
+
|
397 |
+
if(isset($storeValue)){
|
398 |
+
$result .= '<input type="text" class="form-control" name="'.$tKey.'" value="'.$storeValue.'" placeholder="'.$tValue.'">';
|
399 |
+
}else{
|
400 |
+
$result .= '<input type="text" class="form-control" name="'.$tKey.'" placeholder="'.$tValue.'">';
|
401 |
+
}
|
402 |
+
$result .= '</div>';
|
403 |
+
$result .= '</div>';
|
404 |
+
}
|
405 |
+
|
406 |
+
//enable/disable feed upload
|
407 |
+
$isUpload = Mage::helper('expertrec_recommendation')->getConfig(self::IS_UPLOAD_FEED);
|
408 |
+
$result .= '<div class="row">';
|
409 |
+
$result .='<div class="col-sm-offset-2 col-sm-8" style="clear:both;">';
|
410 |
+
$result .= '<label class="checkbox-inline" style="padding-left: 20px;">';
|
411 |
+
if(isset($isUpload) && $isUpload == 'true'){
|
412 |
+
$result .= '<input type="checkbox" name="upload_feed" value="is_upload" checked>';
|
413 |
+
}else{
|
414 |
+
$result .= '<input type="checkbox" name="upload_feed" value="is_upload">';
|
415 |
+
}
|
416 |
+
$result .= 'Upload Feed';
|
417 |
+
$result .= '</label>';
|
418 |
+
$result .= '</div>';
|
419 |
+
$result .= '</div>';
|
420 |
+
|
421 |
+
$result .= '<div style="text-align:center;margin:10px auto;">';
|
422 |
+
$result .= '<input type="submit" class="btn btn-md btn-primary" name="feed_conf" value="Submit" style="padding:5px; "/>';
|
423 |
+
$result .= '</div>';
|
424 |
+
|
425 |
+
$result .= '</form>';
|
426 |
+
$result .= '</fieldset>';
|
427 |
+
|
428 |
+
return $result;
|
429 |
+
}
|
430 |
+
|
431 |
+
private function displaySiteDetails(){
|
432 |
+
$result = '<fieldset>';
|
433 |
+
$result .= '<legend>Site Info</legend>';
|
434 |
+
$result .= '<table class="table table-hover">';
|
435 |
+
$result .= '<tbody>';
|
436 |
+
try{
|
437 |
+
$adminEmail = Mage::getStoreConfig('trans_email/ident_general/email');
|
438 |
+
$adminName = Mage::getStoreConfig('trans_email/ident_general/name');
|
439 |
+
$salesEmail = Mage::getStoreConfig('trans_email/ident_sales/email');
|
440 |
+
$salesName = Mage::getStoreConfig('trans_email/ident_sales/name');
|
441 |
+
$secureUrl = Mage::getStoreConfig('web/secure/base_url');
|
442 |
+
$unsecureUrl = Mage::getStoreConfig('web/unsecure/base_url');
|
443 |
+
$baseCurrency = Mage::getStoreConfig('currency/options/base');
|
444 |
+
$defaultCurrency = Mage::getStoreConfig('currency/options/default');
|
445 |
+
$allowCurrency = Mage::getStoreConfig('currency/options/allow');
|
446 |
+
$timezone = Mage::getStoreConfig('general/locale/timezone');
|
447 |
+
$defaultCountry = Mage::getStoreConfig('general/country/default');
|
448 |
+
$installedCurrency = Mage::getStoreConfig('system/currency/installed');
|
449 |
+
}catch(Exception $e){}
|
450 |
+
|
451 |
+
if(isset($adminName)){
|
452 |
+
$result .= '<tr>';
|
453 |
+
$result .= '<td style="width: 20%;"><strong>Admin name: </strong></td>';
|
454 |
+
$result .= '<td>'.$adminName.'</td>';
|
455 |
+
$result .= '</tr>';
|
456 |
+
}
|
457 |
+
if(isset($adminEmail)){
|
458 |
+
$result .= '<tr>';
|
459 |
+
$result .= '<td style="width: 20%;"><strong>Admin email: </strong></td>';
|
460 |
+
$result .= '<td>'.$adminEmail.'</td>';
|
461 |
+
$result .= '</tr>';
|
462 |
+
}
|
463 |
+
if(isset($salesName)){
|
464 |
+
$result .= '<tr>';
|
465 |
+
$result .= '<td style="width: 20%;"><strong>Sales name: </strong></td>';
|
466 |
+
$result .= '<td>'.$salesName.'</td>';
|
467 |
+
$result .= '</tr>';
|
468 |
+
}
|
469 |
+
if(isset($salesEmail)){
|
470 |
+
$result .= '<tr>';
|
471 |
+
$result .= '<td style="width: 20%;"><strong>Sales email: </strong></td>';
|
472 |
+
$result .= '<td>'.$salesEmail.'</td>';
|
473 |
+
$result .= '</tr>';
|
474 |
+
}
|
475 |
+
if(isset($secureUrl)){
|
476 |
+
$result .= '<tr>';
|
477 |
+
$result .= '<td style="width: 20%;"><strong>Web secure base url: </strong></td>';
|
478 |
+
$result .= '<td>'.$secureUrl.'</td>';
|
479 |
+
$result .= '</tr>';
|
480 |
+
}
|
481 |
+
if(isset($unsecureUrl)){
|
482 |
+
$result .= '<tr>';
|
483 |
+
$result .= '<td style="width: 20%;"><strong>Web unsecure base url: </strong></td>';
|
484 |
+
$result .= '<td>'.$unsecureUrl.'</td>';
|
485 |
+
$result .= '</tr>';
|
486 |
+
}
|
487 |
+
if(isset($baseCurrency)){
|
488 |
+
$result .= '<tr>';
|
489 |
+
$result .= '<td style="width: 20%;"><strong>Base currency: </strong></td>';
|
490 |
+
$result .= '<td>'.$baseCurrency.'</td>';
|
491 |
+
$result .= '</tr>';
|
492 |
+
}
|
493 |
+
if(isset($defaultCurrency)){
|
494 |
+
$result .= '<tr>';
|
495 |
+
$result .= '<td style="width: 20%;"><strong>Default currency: </strong></td>';
|
496 |
+
$result .= '<td>'.$defaultCurrency.'</td>';
|
497 |
+
$result .= '</tr>';
|
498 |
+
}
|
499 |
+
if(isset($allowCurrency)){
|
500 |
+
$result .= '<tr>';
|
501 |
+
$result .= '<td style="width: 20%;"><strong>Allow currencies: </strong></td>';
|
502 |
+
$result .= '<td>'.str_replace(",", ", ",$allowCurrency).'</td>';
|
503 |
+
$result .= '</tr>';
|
504 |
+
}
|
505 |
+
if(isset($defaultCountry)){
|
506 |
+
$result .= '<tr>';
|
507 |
+
$result .= '<td style="width: 20%;"><strong>Default Country: </strong></td>';
|
508 |
+
$result .= '<td>'.$defaultCountry.'</td>';
|
509 |
+
$result .= '</tr>';
|
510 |
+
}
|
511 |
+
if(isset($timezone)){
|
512 |
+
$result .= '<tr>';
|
513 |
+
$result .= '<td style="width: 20%;"><strong>Timezone: </strong></td>';
|
514 |
+
$result .= '<td>'.$timezone.'</td>';
|
515 |
+
$result .= '</tr>';
|
516 |
+
}
|
517 |
+
if(isset($installedCurrency)){
|
518 |
+
$result .= '<tr>';
|
519 |
+
$result .= '<td style="width: 20%;"><strong>Installed currencies: </strong></td>';
|
520 |
+
$result .= '<td>'.str_replace(",", ", ",$installedCurrency).'</td>';
|
521 |
+
$result .= '</tr>';
|
522 |
+
}
|
523 |
+
|
524 |
+
try{
|
525 |
+
$modulesArray = (array)Mage::getConfig()->getNode('modules')->children();
|
526 |
+
$modulesNameArray = array_keys($modulesArray);
|
527 |
+
|
528 |
+
//displaying list of installed modules
|
529 |
+
$result .= '<tr>';
|
530 |
+
$result .= '<td style="width: 20%;"><strong>Installed Extensions: </strong></td>';
|
531 |
+
$result .= '<td>'.implode(", ", $modulesNameArray).'</td>';
|
532 |
+
$result .= '</tr>';
|
533 |
+
|
534 |
+
//displaying list of active modules
|
535 |
+
$activeModules = array();
|
536 |
+
$coreHelper = Mage::helper('core');
|
537 |
+
foreach ($modulesNameArray as $module) {
|
538 |
+
if($coreHelper->isModuleEnabled($module)){
|
539 |
+
$activeModules[] = $module;
|
540 |
+
}
|
541 |
+
}
|
542 |
+
$result .= '<tr>';
|
543 |
+
$result .= '<td style="width: 20%;"><strong>Active Extensions: </strong></td>';
|
544 |
+
$result .= '<td>'.implode(", ", $activeModules).'</td>';
|
545 |
+
$result .= '</tr>';
|
546 |
+
}catch(Exception $e){$result .= '<tr>';
|
547 |
+
$result .= '<tr><td>Error</td><td style="color:red;">'.$e->getMessage().'</td></tr>';
|
548 |
+
}
|
549 |
+
|
550 |
+
|
551 |
+
$result .= '</tbody>';
|
552 |
+
$result .= '</table>';
|
553 |
+
$result .= '</fieldset>';
|
554 |
+
return $result;
|
555 |
+
}
|
556 |
+
|
557 |
+
}
|
558 |
+
?>
|
app/code/community/Expertrec/Recommendation/controllers/CatalogSearch/ResultController.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once 'Mage/CatalogSearch/controllers/ResultController.php';
|
4 |
+
|
5 |
+
class Expertrec_Recommendation_CatalogSearch_ResultController extends Mage_CatalogSearch_ResultController
|
6 |
+
{
|
7 |
+
public function indexAction(){
|
8 |
+
$this->loadLayout();
|
9 |
+
$this->renderLayout();
|
10 |
+
}
|
11 |
+
}
|
12 |
+
|
13 |
+
?>
|
app/code/community/Expertrec/Recommendation/controllers/ConfigController.php
ADDED
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Expertrec_Recommendation_ConfigController extends Mage_Core_Controller_Front_Action {
|
4 |
+
|
5 |
+
const SEARCH_LIST_ENABLE = 'search/enable';
|
6 |
+
const SEARCH_LIST_API = 'search/api';
|
7 |
+
const SEARCH_FACET_LIST = 'search/facets_list';
|
8 |
+
const SEARCH_SINGLE_SELECT_FILTERS = 'search/single_select_filters';
|
9 |
+
const SEARCH_IS_AJAX = 'search/is_ajax';
|
10 |
+
const SEARCH_ITEMS_PER_PAGE = 'search/items_per_page';
|
11 |
+
const SEARCH_DISPLAY_PAGES = 'search/display_pages';
|
12 |
+
const SEARCH_FETCH_PRICE = 'search/fetch_price';
|
13 |
+
const SEARCH_CONVERT_PRICE = 'search/convert_price';
|
14 |
+
const SEARCH_CUSTOM_TEMPLATE = 'search/custom_template';
|
15 |
+
const FEED_LOG_ENDPOINT = 'log_endpoint';
|
16 |
+
const FEED_UPLOAD_ENDPOINT = 'upload_endpoint';
|
17 |
+
|
18 |
+
// return websites and stores information
|
19 |
+
public function editAction(){
|
20 |
+
try{
|
21 |
+
//return array of all parameters sent
|
22 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
23 |
+
|
24 |
+
// Get parameters from the requestParams array
|
25 |
+
$mid = isset($requestParams['mid']) ? $requestParams['mid'] : '';
|
26 |
+
$secret = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
27 |
+
$pwd = isset($requestParams['pwd']) ? $requestParams['pwd'] : '';
|
28 |
+
|
29 |
+
if(empty($mid) || empty($secret) || empty($pwd)){
|
30 |
+
die("Invalid parameters given.");
|
31 |
+
}
|
32 |
+
|
33 |
+
$storedPwd = Mage::getModel('expertrec_recommendation/validate')->getPassword();
|
34 |
+
|
35 |
+
//if passwoed is not valid then it will not proceed
|
36 |
+
if($pwd != $storedPwd){
|
37 |
+
die("Authentication failed");
|
38 |
+
}
|
39 |
+
|
40 |
+
$encoded_secret = base64_encode($secret);
|
41 |
+
|
42 |
+
//store mid and secret then clear cache
|
43 |
+
Mage::helper("expertrec_recommendation")
|
44 |
+
->saveConfig('secret',$encoded_secret)
|
45 |
+
->saveConfig('mid',$mid)
|
46 |
+
->clearCache();
|
47 |
+
|
48 |
+
// need to remove, we now no longer use cache.
|
49 |
+
//update config variable
|
50 |
+
Mage::getSingleton('expertrec_recommendation/feed_feedconfig')
|
51 |
+
->setSecret($secret)
|
52 |
+
->setMerchantId($mid);
|
53 |
+
|
54 |
+
die("Successfully updated mid and secret");
|
55 |
+
}catch(Exception $e){
|
56 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Updating mid & secret error: ".$e->getMessage());
|
57 |
+
die("Unable to configure mid and secret");
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
public function saveheadersAction(){
|
64 |
+
try{
|
65 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
66 |
+
$Password = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
67 |
+
|
68 |
+
// Check password. if invalid password, it will not proceed.
|
69 |
+
if(!Mage::getModel('expertrec_recommendation/validate')->checkPassword($Password)){
|
70 |
+
die('ERROR: The specified password is invalid.');
|
71 |
+
}
|
72 |
+
|
73 |
+
$attrArray = array();
|
74 |
+
if(isset($requestParams['selected_headers'])){
|
75 |
+
|
76 |
+
if(!empty($requestParams['check_list'])){
|
77 |
+
|
78 |
+
foreach($requestParams['check_list'] as $selected){
|
79 |
+
$attrArray[] = $selected;
|
80 |
+
|
81 |
+
}
|
82 |
+
|
83 |
+
if(count($attrArray) > 0){
|
84 |
+
|
85 |
+
// check for field expert_image
|
86 |
+
if(in_array("expert_image", $attrArray)){
|
87 |
+
|
88 |
+
if(isset($requestParams['imagewidth']) ? $requestParams['imagewidth'] : ''){
|
89 |
+
$imageWidth = $requestParams['imagewidth'];
|
90 |
+
Mage::helper("expertrec_recommendation")
|
91 |
+
->saveConfig('expertrec_image_width',$imageWidth);
|
92 |
+
echo "Image Width updated</br>";
|
93 |
+
}
|
94 |
+
else{
|
95 |
+
Mage::helper("expertrec_recommendation")
|
96 |
+
->saveConfig('expertrec_image_width','');
|
97 |
+
echo "Not Updating Image Width</br>";
|
98 |
+
}
|
99 |
+
if(isset($requestParams['imageheight']) ? $requestParams['imageheight'] : ''){
|
100 |
+
$imageHeight = $requestParams['imageheight'];
|
101 |
+
|
102 |
+
// store image width and height
|
103 |
+
Mage::helper("expertrec_recommendation")
|
104 |
+
->saveConfig('expertrec_image_height',$imageHeight);
|
105 |
+
echo "Image Height updated</br>";
|
106 |
+
}
|
107 |
+
else{
|
108 |
+
Mage::helper("expertrec_recommendation")
|
109 |
+
->saveConfig('expertrec_image_height','');
|
110 |
+
echo "Not Updating Image Height</br>";
|
111 |
+
}
|
112 |
+
|
113 |
+
}
|
114 |
+
|
115 |
+
//store headers then clear cache
|
116 |
+
Mage::helper("expertrec_recommendation")
|
117 |
+
->saveConfig('headers',implode(',', $attrArray))
|
118 |
+
->clearCache();
|
119 |
+
|
120 |
+
die("Successfully updated selected headers. Please close this tab and reload the info page.");
|
121 |
+
}
|
122 |
+
}
|
123 |
+
}
|
124 |
+
die("Invalid request");
|
125 |
+
|
126 |
+
}catch(Exception $e){
|
127 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Updating feed header error: ".$e->getMessage());
|
128 |
+
die("Unable to update headers");
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
public function savefeedconfAction(){
|
133 |
+
try{
|
134 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
135 |
+
$Password = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
136 |
+
|
137 |
+
// Check password. if invalid password, it will not proceed.
|
138 |
+
if(!Mage::getModel('expertrec_recommendation/validate')->checkPassword($Password)){
|
139 |
+
die('ERROR: The specified password is invalid.');
|
140 |
+
}
|
141 |
+
|
142 |
+
$feedConfArray = array();
|
143 |
+
if(isset($requestParams['feed_conf'])){
|
144 |
+
if(!empty($requestParams['log_api'])){
|
145 |
+
$feedConfArray[self::FEED_LOG_ENDPOINT] = $requestParams['log_api'];
|
146 |
+
}
|
147 |
+
|
148 |
+
if(!empty($requestParams['upload_api'])){
|
149 |
+
$feedConfArray[self::FEED_UPLOAD_ENDPOINT] = $requestParams['upload_api'];
|
150 |
+
}
|
151 |
+
|
152 |
+
if(!empty($requestParams['upload_feed'])){
|
153 |
+
$feedConfArray["is_upload"] = "true";
|
154 |
+
}else{
|
155 |
+
$feedConfArray["is_upload"] = "false";
|
156 |
+
}
|
157 |
+
|
158 |
+
foreach ($feedConfArray as $sKey => $sValue) {
|
159 |
+
//storing search config
|
160 |
+
Mage::helper("expertrec_recommendation")
|
161 |
+
->saveConfig($sKey,$sValue);
|
162 |
+
}
|
163 |
+
|
164 |
+
//clear cache
|
165 |
+
Mage::helper("expertrec_recommendation")
|
166 |
+
->clearCache();
|
167 |
+
|
168 |
+
die("Successfully updated feed config. Please close this tab and reload the info page.");
|
169 |
+
}
|
170 |
+
|
171 |
+
die("Invalid request");
|
172 |
+
|
173 |
+
}catch(Exception $e){
|
174 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Updating feed config error: ".$e->getMessage());
|
175 |
+
die("Unable to update feed config");
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
public function savesearchAction(){
|
180 |
+
try{
|
181 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
182 |
+
$Password = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
183 |
+
|
184 |
+
// Check password. if invalid password, it will not proceed.
|
185 |
+
if(!Mage::getModel('expertrec_recommendation/validate')->checkPassword($Password)){
|
186 |
+
die('ERROR: The specified password is invalid.');
|
187 |
+
}
|
188 |
+
|
189 |
+
$searchConfArray = array();
|
190 |
+
|
191 |
+
if(isset($requestParams['selected_search'])){
|
192 |
+
|
193 |
+
if(!empty($requestParams['api'])){
|
194 |
+
$searchConfArray[self::SEARCH_LIST_API] = $requestParams['api'];
|
195 |
+
}
|
196 |
+
|
197 |
+
$searchConfArray[self::SEARCH_FACET_LIST] = isset($requestParams['facet_list']) ? $requestParams['facet_list'] : '';
|
198 |
+
|
199 |
+
$searchConfArray[self::SEARCH_SINGLE_SELECT_FILTERS] = isset($requestParams['single_select_filter']) ? $requestParams['single_select_filter'] : '';
|
200 |
+
|
201 |
+
$searchConfArray[self::SEARCH_ITEMS_PER_PAGE] = isset($requestParams['items_per_page']) ? $requestParams['items_per_page'] : '';
|
202 |
+
|
203 |
+
$searchConfArray[self::SEARCH_DISPLAY_PAGES] = isset($requestParams['display_pages']) ? $requestParams['display_pages'] : '';
|
204 |
+
|
205 |
+
$searchCheckedList = isset($requestParams['search_check_list']) ? $requestParams['search_check_list'] : array();
|
206 |
+
|
207 |
+
$searchConfArray[self::SEARCH_LIST_ENABLE] = in_array("search_enable", $searchCheckedList) ? "true" : "false";
|
208 |
+
$searchConfArray[self::SEARCH_FETCH_PRICE] = in_array("fetch_price", $searchCheckedList) ? "true" : "false";
|
209 |
+
$searchConfArray[self::SEARCH_CONVERT_PRICE] = in_array("convert_price", $searchCheckedList) ? "true" : "false";
|
210 |
+
$searchConfArray[self::SEARCH_IS_AJAX] = in_array("is_ajax", $searchCheckedList) ? "true" : "false";
|
211 |
+
$searchConfArray[self::SEARCH_CUSTOM_TEMPLATE] = in_array("custom_template", $searchCheckedList) ? "true" : "false";
|
212 |
+
|
213 |
+
|
214 |
+
foreach ($searchConfArray as $sKey => $sValue) {
|
215 |
+
//storing search config
|
216 |
+
Mage::helper("expertrec_recommendation")
|
217 |
+
->saveConfig($sKey,$sValue);
|
218 |
+
}
|
219 |
+
|
220 |
+
//clear cache
|
221 |
+
Mage::helper("expertrec_recommendation")
|
222 |
+
->clearCache();
|
223 |
+
|
224 |
+
die("Successfully updated search config. Please close this tab and reload the info page.");
|
225 |
+
}
|
226 |
+
|
227 |
+
die("Invalid request");
|
228 |
+
|
229 |
+
}catch(Exception $e){
|
230 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Updating search config error: ".$e->getMessage());
|
231 |
+
die("Unable to update search config");
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
}
|
236 |
+
?>
|
app/code/community/Expertrec/Recommendation/controllers/IndexController.php
ADDED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Expertrec_Recommendation_IndexController extends Mage_Core_Controller_Front_Action{
|
3 |
+
|
4 |
+
const FEED_PATH = '/Expertrec';
|
5 |
+
const IS_UPLOAD_FEED = 'expertrec/general/is_upload';
|
6 |
+
|
7 |
+
public function indexAction (){
|
8 |
+
try{
|
9 |
+
//Increase memory limit
|
10 |
+
ini_set('memory_limit', '1024M');
|
11 |
+
|
12 |
+
//Increase maximum execution time to 5 hours (default in magento)
|
13 |
+
set_time_limit(18000);
|
14 |
+
|
15 |
+
// Run main application
|
16 |
+
$isUpload = Mage::getStoreConfig(self::IS_UPLOAD_FEED);
|
17 |
+
if(isset($isUpload) && $isUpload == 'true'){
|
18 |
+
ob_end_clean();
|
19 |
+
//avoid apache to kill the php running
|
20 |
+
ignore_user_abort(true);
|
21 |
+
ob_start();//start buffer output
|
22 |
+
|
23 |
+
echo "Feed generation started in background.";
|
24 |
+
//close session file on server side to avoid blocking other requests
|
25 |
+
session_write_close();
|
26 |
+
|
27 |
+
//send header to avoid the browser side to take content as gzip format
|
28 |
+
header("Content-Encoding: none");
|
29 |
+
header("Content-Length: ".ob_get_length());
|
30 |
+
header("Connection: close");
|
31 |
+
ob_end_flush();
|
32 |
+
flush();
|
33 |
+
|
34 |
+
$this->runMain(true);
|
35 |
+
|
36 |
+
}else{
|
37 |
+
$this->runMain();
|
38 |
+
}
|
39 |
+
|
40 |
+
}catch (Exception $e) {
|
41 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Exception while preparing the main appilication: ".$e->getMessage());
|
42 |
+
}
|
43 |
+
}
|
44 |
+
public function cleanAction(){
|
45 |
+
try{
|
46 |
+
//return array of all parameters sent
|
47 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
48 |
+
$Password = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
49 |
+
|
50 |
+
// Check password. if invalid password, it will not proceed.
|
51 |
+
if(!Mage::getModel('expertrec_recommendation/validate')->checkPassword($Password)){
|
52 |
+
die('ERROR: The specified password is invalid.');
|
53 |
+
}
|
54 |
+
|
55 |
+
$vFeedDir = Mage::getBaseDir().self::FEED_PATH;
|
56 |
+
|
57 |
+
//delete all files in Expertrec
|
58 |
+
Mage::helper('expertrec_recommendation/filehelper')->cleanDir($vFeedDir);
|
59 |
+
|
60 |
+
die("successfully deleted all files.");
|
61 |
+
|
62 |
+
}catch (Exception $e) {
|
63 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Exception while cleaning Expertrec feed dir: ".$e->getMessage());
|
64 |
+
}
|
65 |
+
}
|
66 |
+
public function getlogAction(){
|
67 |
+
try{
|
68 |
+
//return array of all parameters sent
|
69 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
70 |
+
$Password = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
71 |
+
|
72 |
+
// Check password. if invalid password, it will not proceed.
|
73 |
+
if(!Mage::getModel('expertrec_recommendation/validate')->checkPassword($Password)){
|
74 |
+
die('ERROR: The specified password is invalid.');
|
75 |
+
}
|
76 |
+
|
77 |
+
//base Directory path
|
78 |
+
$basePath = Mage::getBaseDir();
|
79 |
+
$logPath = $basePath.self::FEED_PATH."/expertrec_feed.log";
|
80 |
+
$this->downloadFile($logPath);
|
81 |
+
return;
|
82 |
+
}catch (Exception $e) {
|
83 |
+
Mage::getSingleton('expertrec_recommendation/log')->log( "Exception while getting log file: ".$e->getMessage());
|
84 |
+
die('ERROR: Unable to download log file.');
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
private function runMain($upload = false){
|
89 |
+
try{
|
90 |
+
//return array of all parameters sent
|
91 |
+
$requestParams = Mage::app()->getRequest()->getParams();
|
92 |
+
|
93 |
+
// Get parameters from the requestParams array
|
94 |
+
$Command = isset($requestParams['cmd']) ? $requestParams['cmd'] : '';
|
95 |
+
|
96 |
+
$Password = isset($requestParams['secret']) ? $requestParams['secret'] : '';
|
97 |
+
|
98 |
+
$imageWidth = isset($requestParams['width']) ? $requestParams['width'] : '';
|
99 |
+
$imageHeight = isset($requestParams['height']) ? $requestParams['height'] : '';
|
100 |
+
$storeId = isset($requestParams['sid']) ? $requestParams['sid'] : '';
|
101 |
+
$websiteId = isset($requestParams['wid']) ? $requestParams['wid'] : '';
|
102 |
+
$pageStart = isset($requestParams['ps']) ? $requestParams['ps'] : '';
|
103 |
+
$pageEnd = isset($requestParams['pe']) ? $requestParams['pe'] : '';
|
104 |
+
$pageSize = isset($requestParams['psize']) ? $requestParams['psize'] : '';
|
105 |
+
|
106 |
+
// Check password. if invalid password, it will not proceed.
|
107 |
+
if(!Mage::getModel('expertrec_recommendation/validate')->checkPassword($Password)){
|
108 |
+
die('ERROR: The specified password is invalid.');
|
109 |
+
}
|
110 |
+
|
111 |
+
$feedConfig = Mage::getSingleton('expertrec_recommendation/feed_feedconfig');
|
112 |
+
|
113 |
+
|
114 |
+
// if website_id and store_id are not given in the request then retuen with error message
|
115 |
+
if(empty($storeId) && empty($websiteId)){
|
116 |
+
die("ERROR: Blank website_id and store_id are not alowed. Edit this request and set website_id and store_id.");
|
117 |
+
}else{
|
118 |
+
$feedConfig
|
119 |
+
->setWebsiteId($websiteId)
|
120 |
+
->setStoreId($storeId);
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
+
//Limiting feed collection in one request
|
125 |
+
if(!empty($pageStart) && !empty($pageEnd)){
|
126 |
+
$feedConfig->setPageStart($pageStart)
|
127 |
+
->setPageEnd($pageEnd);
|
128 |
+
}
|
129 |
+
|
130 |
+
//Limiting number of products in a page during feed collection
|
131 |
+
if(!empty($pageSize)){
|
132 |
+
$feedConfig->setPageSize($pageSize);
|
133 |
+
}
|
134 |
+
|
135 |
+
// check whether the image is to generate or not
|
136 |
+
if(!empty($imageWidth) && !empty($imageHeight)){
|
137 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("setting Image width and height.");
|
138 |
+
$feedConfig
|
139 |
+
->setGenerateImage(true)
|
140 |
+
->setImageHeight($imageHeight)
|
141 |
+
->setImageWidth($imageWidth);
|
142 |
+
}else{
|
143 |
+
$feedConfig->setGenerateImage(false);
|
144 |
+
}
|
145 |
+
|
146 |
+
// If the command is export, then run the native export
|
147 |
+
if($Command == 'export'){
|
148 |
+
if(!Mage::getModel('expertrec_recommendation/feed')->exportFeeds()){
|
149 |
+
die("Error: Feed not created. Please try again after some time.");
|
150 |
+
}
|
151 |
+
|
152 |
+
}else if($Command == 'getpp'){
|
153 |
+
if(!Mage::helper('expertrec_recommendation/suggestionhelper')->exportPopularProducts()){
|
154 |
+
die("Error: Popolar products feed not created. Please try again after some time.");
|
155 |
+
}
|
156 |
+
}else{
|
157 |
+
die("The requested URL /expertrec-feed/ was not found on this server.");
|
158 |
+
}
|
159 |
+
|
160 |
+
$feedFilePath=$feedConfig->feedFilePath;
|
161 |
+
|
162 |
+
if($upload){
|
163 |
+
Mage::helper('expertrec_recommendation')->pushFeed($feedFilePath);
|
164 |
+
}else{
|
165 |
+
$this->downloadFile($feedFilePath,true);
|
166 |
+
}
|
167 |
+
return;
|
168 |
+
}catch(Exception $e){
|
169 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error: Entry point error: ".$e->getMessage());
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
private function downloadFile($attachment_location,$delete = false){
|
174 |
+
try{
|
175 |
+
$fileName = substr($attachment_location, strrpos($attachment_location, '/') + 1);
|
176 |
+
|
177 |
+
if (file_exists($attachment_location)) {
|
178 |
+
|
179 |
+
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
|
180 |
+
header('Expires: 0');
|
181 |
+
header('Cache-Control: must-revalidate, post-check=0,pre-check=0');
|
182 |
+
header('Content-Description: File Transfer');
|
183 |
+
header("Content-Type: application/octet-stream");
|
184 |
+
header('Pragma: public');
|
185 |
+
header("Content-Length:".filesize($attachment_location));
|
186 |
+
header("Content-Disposition: attachment; filename=".$fileName);
|
187 |
+
|
188 |
+
//header is set, so clear the output buffer before downloading file
|
189 |
+
ob_clean();
|
190 |
+
flush();
|
191 |
+
|
192 |
+
//download file
|
193 |
+
readfile($attachment_location);
|
194 |
+
|
195 |
+
if($delete){
|
196 |
+
//deleting file
|
197 |
+
Mage::helper('expertrec_recommendation/filehelper')->deleteFile($attachment_location);
|
198 |
+
}
|
199 |
+
|
200 |
+
die("File downloaded successfully.");
|
201 |
+
} else {
|
202 |
+
die("Error: File not found.");
|
203 |
+
}
|
204 |
+
}catch(Exception $e){
|
205 |
+
Mage::getSingleton('expertrec_recommendation/log')->log("Error: returning feed error: ".$e->getMessage());
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
}
|
210 |
+
?>
|
app/code/community/Expertrec/Recommendation/etc/adminhtml.xml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<menu>
|
4 |
+
<expertrec translate="title" module="expertrec_recommendation">
|
5 |
+
<title>Expertrec</title>
|
6 |
+
<sort_order>99</sort_order>
|
7 |
+
<children>
|
8 |
+
<expertrec translate="title">
|
9 |
+
<title>Control Panel</title>
|
10 |
+
<sort_order>10</sort_order>
|
11 |
+
<action>expertrec-signup</action>
|
12 |
+
</expertrec>
|
13 |
+
</children>
|
14 |
+
</expertrec>
|
15 |
+
</menu>
|
16 |
+
</config>
|
app/code/community/Expertrec/Recommendation/etc/config.xml
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Expertrec_Recommendation>
|
5 |
+
<version>1.1.0</version>
|
6 |
+
</Expertrec_Recommendation>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<expertrec_recommendation>
|
11 |
+
<class>Expertrec_Recommendation_Model</class>
|
12 |
+
</expertrec_recommendation>
|
13 |
+
<catalogsearch>
|
14 |
+
<rewrite>
|
15 |
+
<layer>Expertrec_Recommendation_Model_Catalogsearch_Layer</layer>
|
16 |
+
</rewrite>
|
17 |
+
</catalogsearch>
|
18 |
+
</models>
|
19 |
+
<helpers>
|
20 |
+
<expertrec_recommendation>
|
21 |
+
<class>Expertrec_Recommendation_Helper</class>
|
22 |
+
</expertrec_recommendation>
|
23 |
+
</helpers>
|
24 |
+
<blocks>
|
25 |
+
<expertrec_recommendation>
|
26 |
+
<class>Expertrec_Recommendation_Block</class>
|
27 |
+
</expertrec_recommendation>
|
28 |
+
</blocks>
|
29 |
+
<resources>
|
30 |
+
<expertrec_setup>
|
31 |
+
<setup>
|
32 |
+
<module>Expertrec_Recommendation</module>
|
33 |
+
</setup>
|
34 |
+
</expertrec_setup>
|
35 |
+
</resources>
|
36 |
+
<events>
|
37 |
+
<checkout_cart_product_add_after>
|
38 |
+
<observers>
|
39 |
+
<expertrec_recommendation_track_addtocart>
|
40 |
+
<type>singleton</type>
|
41 |
+
<class>expertrec_recommendation/observer</class>
|
42 |
+
<method>trackAddToCart</method>
|
43 |
+
</expertrec_recommendation_track_addtocart>
|
44 |
+
</observers>
|
45 |
+
</checkout_cart_product_add_after>
|
46 |
+
<sales_order_payment_place_end>
|
47 |
+
<observers>
|
48 |
+
<expertrec_recommendation_track_order>
|
49 |
+
<type>singleton</type>
|
50 |
+
<class>expertrec_recommendation/observer</class>
|
51 |
+
<method>trackOrder</method>
|
52 |
+
</expertrec_recommendation_track_order>
|
53 |
+
</observers>
|
54 |
+
</sales_order_payment_place_end>
|
55 |
+
<sales_quote_remove_item>
|
56 |
+
<observers>
|
57 |
+
<expertrec_recommendation_track_remove_item>
|
58 |
+
<type>singleton</type>
|
59 |
+
<class>expertrec_recommendation/observer</class>
|
60 |
+
<method>trackRemoveItem</method>
|
61 |
+
</expertrec_recommendation_track_remove_item>
|
62 |
+
</observers>
|
63 |
+
</sales_quote_remove_item>
|
64 |
+
<catalog_product_delete_before>
|
65 |
+
<observers>
|
66 |
+
<expertrec_recommendation_track_delete>
|
67 |
+
<type>singleton</type>
|
68 |
+
<class>expertrec_recommendation/observer</class>
|
69 |
+
<method>trackDelete</method>
|
70 |
+
</expertrec_recommendation_track_delete>
|
71 |
+
</observers>
|
72 |
+
</catalog_product_delete_before>
|
73 |
+
<catalog_product_save_commit_after>
|
74 |
+
<observers>
|
75 |
+
<expertrec_recommendation_stockupdate>
|
76 |
+
<class>expertrec_recommendation/observer</class>
|
77 |
+
<method>saveProduct</method>
|
78 |
+
</expertrec_recommendation_stockupdate>
|
79 |
+
</observers>
|
80 |
+
</catalog_product_save_commit_after>
|
81 |
+
</events>
|
82 |
+
</global>
|
83 |
+
<frontend>
|
84 |
+
<layout>
|
85 |
+
<updates>
|
86 |
+
<expertrec_recommendation>
|
87 |
+
<file>expertrec/recommendation.xml</file>
|
88 |
+
</expertrec_recommendation>
|
89 |
+
</updates>
|
90 |
+
</layout>
|
91 |
+
<routers>
|
92 |
+
<expertrec_recommendation>
|
93 |
+
<use>standard</use>
|
94 |
+
<args>
|
95 |
+
<module>Expertrec_Recommendation</module>
|
96 |
+
<frontName>expertrec-feed</frontName>
|
97 |
+
</args>
|
98 |
+
</expertrec_recommendation>
|
99 |
+
<expertrec-signup>
|
100 |
+
<use>standard</use>
|
101 |
+
<args>
|
102 |
+
<module>Expertrec_Recommendation_Adminhtml</module>
|
103 |
+
<frontName>expertrec-signup</frontName>
|
104 |
+
</args>
|
105 |
+
</expertrec-signup>
|
106 |
+
<expertrec>
|
107 |
+
<use>standard</use>
|
108 |
+
<args>
|
109 |
+
<modules>
|
110 |
+
<Expertrec_Recommendation before="Mage_CatalogSearch">Expertrec_Recommendation_CatalogSearch</Expertrec_Recommendation>
|
111 |
+
</modules>
|
112 |
+
<frontName>expertrec</frontName>
|
113 |
+
</args>
|
114 |
+
</expertrec>
|
115 |
+
</routers>
|
116 |
+
</frontend>
|
117 |
+
</config>
|
app/code/community/Expertrec/Recommendation/sql/expertrec_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
$installer->startSetup();
|
5 |
+
|
6 |
+
$installer->run("
|
7 |
+
INSERT INTO {$this->getTable('core_config_data')} (`scope`, `scope_id`, `path`, `value`)
|
8 |
+
VALUES
|
9 |
+
('default',0,'expertrec/general/mid','new_user'),
|
10 |
+
('default',0,'expertrec/general/secret','NTE5NTQ1Zjk4OGExYzYxOWFkOTkyN2Y3MDQ5MTQ3NTM='),
|
11 |
+
('default',0,'expertrec/general/headers','is_in_stock,expert_image,expert_category,final_price,entity_id,rating_summary,expert_url,created_at,image,msrp,name,price,short_description,sku,small_image,special_price')
|
12 |
+
ON DUPLICATE KEY UPDATE `value`=`value`;
|
13 |
+
");
|
14 |
+
|
15 |
+
$installer->endSetup();
|
16 |
+
|
17 |
+
?>
|
app/design/frontend/base/default/layout/expertrec/recommendation.xml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<!-- ON ALL PAGES -->
|
4 |
+
<default>
|
5 |
+
<reference name="head">
|
6 |
+
<block name="expertrec.rec.tracking" template="expertrec/recommendation/tracker.phtml" after="-" type="core/template"/>
|
7 |
+
</reference>
|
8 |
+
</default>
|
9 |
+
|
10 |
+
<expertrec_custom_autocomplete>
|
11 |
+
<remove name="right"/>
|
12 |
+
<remove name="left"/>
|
13 |
+
<reference name="root">
|
14 |
+
<action method="setTemplate"><template>page/1column.phtml</template></action>
|
15 |
+
</reference>
|
16 |
+
</expertrec_custom_autocomplete>
|
17 |
+
</layout>
|
app/design/frontend/base/default/template/expertrec/recommendation/tracker.phtml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php ?>
|
2 |
+
<script type="text/javascript">
|
3 |
+
|
4 |
+
<?php $category = Mage::registry("current_category");?>
|
5 |
+
<?php
|
6 |
+
$formKey = '';
|
7 |
+
$currencyRates = array();
|
8 |
+
try{
|
9 |
+
$formkey_html = $this->getBlockHtml('formkey');
|
10 |
+
$pattern = '/.*form_key.*value=\"([^\"]+)\"/s';
|
11 |
+
if (preg_match($pattern, $formkey_html, $match)){
|
12 |
+
if ($match){
|
13 |
+
$formKey = $match[1];
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
//currency rate
|
18 |
+
$baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
|
19 |
+
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
|
20 |
+
$currencyRates = Mage::getModel('directory/currency')
|
21 |
+
->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
|
22 |
+
|
23 |
+
} catch (Exception $e){
|
24 |
+
Mage::logException($e);
|
25 |
+
}
|
26 |
+
|
27 |
+
?>
|
28 |
+
|
29 |
+
if(typeof expertSiteConf == 'undefined' || expertSiteConf == null) {
|
30 |
+
var expertSiteConf = {
|
31 |
+
currency: "<?php echo Mage::app()->getStore()->getCurrentCurrencyCode(); ?>",
|
32 |
+
formkey:"<?php echo $formKey; ?>"
|
33 |
+
<?php if (isset($category)) { ?>
|
34 |
+
,category:"<?php echo $category->getName(); ?>"
|
35 |
+
<?php } ?>
|
36 |
+
<?php if (!empty($currencyRates)) { ?>
|
37 |
+
,rates: <?php echo json_encode($currencyRates); ?>
|
38 |
+
<?php } ?>
|
39 |
+
};
|
40 |
+
}
|
41 |
+
|
42 |
+
/* * * DON'T EDIT BELOW LINE * * */
|
43 |
+
|
44 |
+
(function(){var domain=window.location.hostname.replace(/\./g,""),ea=document.createElement('script');ea.type='text/javascript';ea.async=true;ea.src='//d3qm5o86jyjko6.cloudfront.net/rec/expertrec_'+domain+'.js';var m=document.getElementsByTagName('script')[0];m.parentNode.insertBefore(ea,m)})();var _eaq=_eaq || [];function expertApi(){if(window.expertrec_true){var args=Array.prototype.slice.call(arguments);window.ea_apispec[args[0]](args.slice(1,args.length))}else{_eaq.push(arguments);}}
|
45 |
+
|
46 |
+
|
47 |
+
</script>
|
48 |
+
<?php ?>
|
49 |
+
|
app/design/frontend/base/default/template/expertrec/recommendation/tracking/product.phtml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php ?>
|
2 |
+
<script type="text/javascript">
|
3 |
+
<?php $product = Mage::registry('current_product');
|
4 |
+
if (isset($product)) { ?>
|
5 |
+
expertSiteConf["pid"] = "<?php echo Mage::helper('expertrec_recommendation')->getUniqueId($product); ?>";
|
6 |
+
<?php } ?>
|
7 |
+
|
8 |
+
(function(){
|
9 |
+
var pid = expertSiteConf.pid ? expertSiteConf.pid : window.location.href;
|
10 |
+
expertApi(1,pid);
|
11 |
+
})();
|
12 |
+
|
13 |
+
</script>
|
14 |
+
<?php ?>
|
15 |
+
|
app/etc/modules/Expertrec_Recommendation.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Expertrec_Recommendation>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Expertrec_Recommendation>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Expertrec_Recommendation</name>
|
4 |
+
<version>1.1.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Expertrec offers real-time personalized product recommendations to your customers. </summary>
|
10 |
+
<description>One of the best extension for Magento sites to personalize the user-experience for their visitors.</description>
|
11 |
+
<notes>Expertrec Recommendation plugin for magento sites.</notes>
|
12 |
+
<authors><author><name>melchi</name><user>melchi</user><email>magento@cloudinfra.in</email></author><author><name>magento</name><user>magento</user><email>magento-team@cloudinfra.in</email></author></authors>
|
13 |
+
<date>2017-01-20</date>
|
14 |
+
<time>12:04:14</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Expertrec"><dir name="Recommendation"><dir name="Helper"><file name="Data.php" hash="41afd664b2087bb1f9361f2630a82bf9"/><file name="Filehelper.php" hash="5ac956e12548398dc159a16eb1a03e8b"/><dir name="Search"><file name="Layout.php" hash="d7b7ec5f4bbd846dd063934f8a267d48"/></dir><file name="Searchhelper.php" hash="791c10fdcb603011004375eeb1cdf498"/><file name="Suggestionhelper.php" hash="93f3aa295761a510f782856c0180a799"/></dir><dir name="Model"><dir name="Api"><file name="Request.php" hash="7df8b22d74b6a05de86da287687a6e96"/></dir><dir name="Catalogsearch"><file name="Layer.php" hash="7324c8873030f230a637329c88b5e3a3"/></dir><dir name="Feed"><file name="Feedconfig.php" hash="013bd447dccc7cc4f073be5bd53a18c9"/><file name="Feedcreator.php" hash="39315afac20326fc7278d1014e0f1142"/><file name="Feedfilter.php" hash="d7599a63a8d1f2033cb1e56204809c2d"/><file name="Formatter.php" hash="e06f27ca673dc58789425ef965467275"/></dir><file name="Feed.php" hash="ddac87d6a060bc77fb7718e7b19e1273"/><file name="Log.php" hash="0d74f297e38bddff9f7c0a3cc86dce8c"/><file name="Observer.php" hash="59b33cf05ec3bf3b349cfef1aea8b84c"/><dir name="Translator"><file name="Category.php" hash="dd209cdda3a1a62042a8a3360ee2dbac"/></dir><file name="Validate.php" hash="7a5fd226b0055e39b725975113e42ee5"/><dir name="Writer"><file name="Abstract.php" hash="53ced825c40d5a6a1d4d35c6de79a68c"/><file name="Csv.php" hash="427fea44d988302f409e1860c18875b1"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="9cf617525636fba1ed4edf6befb5aeea"/></dir><file name="ApiController.php" hash="8229cf4e9a989f1d34eb5b07b519f7f0"/><dir name="CatalogSearch"><file name="ResultController.php" hash="9cb1406e901701ea58e663433358a4c6"/></dir><file name="ConfigController.php" hash="0094cf6ffb0410c79d9d5a5a90a31a2d"/><file name="IndexController.php" hash="e8158c90d1b342f4a262e67390bde523"/></dir><dir name="etc"><file name="adminhtml.xml" hash="189a254999463d2ea44669b58c6f0db6"/><file name="config.xml" hash="f94c08b8513dd71311b4d44059adeee8"/></dir><dir name="sql"><dir name="expertrec_setup"><file name="mysql4-install-1.0.0.php" hash="b85230589d57311ab9c8cc335d058770"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Expertrec_Recommendation.xml" hash="c314465f907c89dfe912035be8d48e71"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="expertrec"><file name="recommendation.xml" hash="29d78f020aa26eb5b5d8a2e274e60e4f"/></dir></dir><dir name="template"><dir name="expertrec"><dir name="recommendation"><file name="tracker.phtml" hash="591f8886ce547e817aa9066c85244645"/><dir name="tracking"><file name="product.phtml" hash="71d46668691668e475b9c8f418cf6cbd"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|