| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Clicks Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Click $Click
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class ClicksController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
| 13808 |
anikendra |
17 |
public $apihost;
|
| 13532 |
anikendra |
18 |
|
| 13558 |
anikendra |
19 |
public function beforeFilter() {
|
|
|
20 |
parent::beforeFilter();
|
| 14302 |
anikendra |
21 |
$this->Auth->allow('redirecttosaholic');
|
| 13808 |
anikendra |
22 |
$this->apihost = Configure::read('pythonapihost');
|
| 15188 |
anikendra |
23 |
$this->livepriceurl = Configure::read('livepriceurl');
|
| 13558 |
anikendra |
24 |
}
|
| 13532 |
anikendra |
25 |
/**
|
|
|
26 |
* index method
|
|
|
27 |
*
|
|
|
28 |
* @return void
|
|
|
29 |
*/
|
|
|
30 |
public function index() {
|
|
|
31 |
$this->Click->recursive = 0;
|
|
|
32 |
$this->set('clicks', $this->Paginator->paginate());
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* view method
|
|
|
37 |
*
|
|
|
38 |
* @throws NotFoundException
|
|
|
39 |
* @param string $id
|
|
|
40 |
* @return void
|
|
|
41 |
*/
|
|
|
42 |
public function view($id = null) {
|
|
|
43 |
if (!$this->Click->exists($id)) {
|
|
|
44 |
throw new NotFoundException(__('Invalid click'));
|
|
|
45 |
}
|
|
|
46 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
47 |
$this->set('click', $this->Click->find('first', $options));
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* add method
|
|
|
52 |
*
|
|
|
53 |
* @return void
|
|
|
54 |
*/
|
| 14345 |
anikendra |
55 |
public function add($userId=null,$storeProductId=null,$storeId=null) {
|
| 14387 |
anikendra |
56 |
session_write_close();
|
| 13558 |
anikendra |
57 |
if(!empty($userId) && !empty($storeProductId)){
|
| 14345 |
anikendra |
58 |
$url = $this->request->query('url');
|
|
|
59 |
$available_price = $this->request->query('price');
|
| 13558 |
anikendra |
60 |
//Get StoreProduct Info
|
| 13808 |
anikendra |
61 |
$this->loadModel('Store');
|
|
|
62 |
// $options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('source_id','available_price','url'),'recursive'=>-1);
|
|
|
63 |
// $storeProduct = $this->StoreProduct->find('first',$options);
|
|
|
64 |
$cachekey = 'storeproduct-'.$storeProductId;
|
| 14345 |
anikendra |
65 |
|
| 18478 |
manish.sha |
66 |
$product = Cache::read($cachekey,'five');
|
|
|
67 |
if(empty($product)) {
|
| 18480 |
manish.sha |
68 |
$producturl = $this->apihost.'masterData/getSkuById/'.$storeProductId;
|
|
|
69 |
$product = $this->make_request($producturl,null);
|
| 18478 |
manish.sha |
70 |
Cache::write($cachekey,$product,'five');
|
|
|
71 |
}
|
|
|
72 |
$storeProduct = json_decode($product[0],1);
|
|
|
73 |
$storeProductName = $storeProduct['source_product_name'];
|
|
|
74 |
$storeProductBrand = $storeProduct['brand'];
|
|
|
75 |
$storeProductCategory = $storeProduct['category_id'];
|
| 14345 |
anikendra |
76 |
if($url=='undefined' || $available_price=='undefined' || $storeId=='undefined') {
|
|
|
77 |
$url = $storeProduct['marketPlaceUrl'];
|
|
|
78 |
$storeId = $storeProduct['source_id'];
|
|
|
79 |
$available_price = $storeProduct['available_price'];
|
| 13808 |
anikendra |
80 |
}
|
| 18170 |
amit.gupta |
81 |
$url1=$url;
|
| 14345 |
anikendra |
82 |
$cachekey = 'store-'.$storeId;
|
| 15085 |
anikendra |
83 |
//$store = Cache::read($cachekey,'month');
|
| 14346 |
anikendra |
84 |
if(empty($store)) {
|
| 14786 |
anikendra |
85 |
$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeId)));
|
| 13903 |
anikendra |
86 |
Cache::write($cachekey,$store,'month');
|
|
|
87 |
}
|
| 14345 |
anikendra |
88 |
$prefix = "SHA".$storeId;
|
| 13599 |
anikendra |
89 |
$tag = $prefix.time();
|
| 14345 |
anikendra |
90 |
if($storeId == 2){
|
| 20402 |
amit.gupta |
91 |
$urlComponents = parse_url($url);
|
|
|
92 |
$url = 'http://dl.flipkart.com/dl/'.$urlComponents['path'].'?'.$urlComponents['query'];
|
| 14345 |
anikendra |
93 |
} elseif($storeId == 3) {
|
| 18263 |
manas |
94 |
//$tag='SHASNAPDEAL123';
|
| 14345 |
anikendra |
95 |
$url_parts = parse_url($url);
|
| 13903 |
anikendra |
96 |
$url_parts['path'] = str_replace('viewAllSellers/','',$url_parts['path']);//quickfix for snapdeal
|
| 18263 |
manas |
97 |
if(isset($url_parts['query'])) {
|
| 18164 |
amit.gupta |
98 |
//$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
|
| 20389 |
amit.gupta |
99 |
$url = "https://m.snapdeal.com".$url_parts['path'].'?'.'utm_source=aff_prog&utm_campaign=afts&offer_id=17';
|
| 13901 |
anikendra |
100 |
}else{
|
| 20389 |
amit.gupta |
101 |
$url = "https://m.snapdeal.com".$url_parts['path'].'?';
|
| 18164 |
amit.gupta |
102 |
}
|
| 14345 |
anikendra |
103 |
} elseif($storeId == 4){
|
| 14574 |
anikendra |
104 |
$urlparts = parse_url($url);
|
|
|
105 |
$url = $urlparts['path'];
|
|
|
106 |
if(!empty($urlparts['query'])){
|
|
|
107 |
$url .= '?'.$urlparts['query'];
|
| 15248 |
anikendra |
108 |
}
|
| 15335 |
anikendra |
109 |
$tokenValidated = $this->checkToken($userId);
|
| 15651 |
anikendra |
110 |
if(isset($userId) && !empty($userId) && $tokenValidated==1){
|
| 15248 |
anikendra |
111 |
$url = $this->getAutoLoginUrl($userId,$url);
|
| 16308 |
anikendra |
112 |
} else{
|
|
|
113 |
if($tokenValidated == 0){
|
|
|
114 |
$url = '/special/native/login';
|
|
|
115 |
}elseif($tokenValidated == -1){
|
|
|
116 |
$url = '/abouts/askforupdate';
|
|
|
117 |
}
|
| 15248 |
anikendra |
118 |
}
|
| 16308 |
anikendra |
119 |
$this->log(print_r($url,1),'headers');
|
| 15920 |
anikendra |
120 |
} elseif($storeId==5){
|
|
|
121 |
$url = "http://clk.omgt5.com/?PID=10314&r=$url";
|
| 16397 |
anikendra |
122 |
} elseif($storeId==6){
|
|
|
123 |
$url = "http://clk.omgt5.com/?PID=11365&r=$url";
|
| 17025 |
anikendra |
124 |
} elseif($storeId==7){
|
|
|
125 |
$url = "http://clk.omgt5.com/?PID=9419&r=$url";
|
| 16397 |
anikendra |
126 |
}
|
| 13558 |
anikendra |
127 |
if( strpos($url, '?') === false ) {
|
|
|
128 |
$firstChar = '?';
|
|
|
129 |
} else {
|
| 13561 |
anikendra |
130 |
$firstChar = '&';
|
| 13558 |
anikendra |
131 |
}
|
| 18164 |
amit.gupta |
132 |
if ($storeId!=3) {
|
|
|
133 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
|
|
134 |
if(!empty($store['Store']['sub_tag_param'])){
|
|
|
135 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
|
|
136 |
}
|
| 13558 |
anikendra |
137 |
}
|
| 18263 |
manas |
138 |
else{
|
|
|
139 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
|
|
140 |
if(!empty($store['Store']['sub_tag_param'])){
|
|
|
141 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
|
|
142 |
}
|
|
|
143 |
}
|
| 13558 |
anikendra |
144 |
$extras = array('store'=>$store['Store']['name']);
|
| 18479 |
manish.sha |
145 |
$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$available_price, 'product_name'=>$storeProductName, 'brand'=>$storeProductBrand, 'category_id'=>$storeProductCategory, 'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
|
| 13532 |
anikendra |
146 |
$this->Click->create();
|
| 18168 |
amit.gupta |
147 |
$curl = $this->livepriceurl."!latestPriceById?id=$storeProductId&source_id=$storeId&url=".base64_encode($url1);
|
| 15188 |
anikendra |
148 |
$response = $this->make_request($curl,null);
|
|
|
149 |
$this->log("live price response ".print_r($response,1),'api');
|
| 13558 |
anikendra |
150 |
if ($this->Click->save($data)) {
|
| 15188 |
anikendra |
151 |
if($response['result']){
|
|
|
152 |
$result = array('success'=>true,'message'=> $response['message'],'type'=>'redirect','url'=>$url,'showmessage'=>1);
|
|
|
153 |
}else{
|
|
|
154 |
$result = array('success'=>true,'message'=> __('The click has been saved.'),'type'=>'redirect','url'=>$url,'showmessage'=>0);
|
|
|
155 |
}
|
| 13532 |
anikendra |
156 |
} else {
|
| 13558 |
anikendra |
157 |
$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
|
| 13532 |
anikendra |
158 |
}
|
| 13558 |
anikendra |
159 |
$this->response->type('json');
|
|
|
160 |
$this->layout = 'ajax';
|
|
|
161 |
$callback = $this->request->query('callback');
|
|
|
162 |
$this->set(array(
|
|
|
163 |
'result' => $result,
|
|
|
164 |
'callback' => $callback,
|
|
|
165 |
'_serialize' => array('result')
|
|
|
166 |
));
|
| 15188 |
anikendra |
167 |
// $url = $this->apihost.'Catalog/fetchLivePrices/?id='.$storeProductId;
|
| 13558 |
anikendra |
168 |
$this->render('/Elements/jsonp');
|
| 13532 |
anikendra |
169 |
}
|
|
|
170 |
}
|
|
|
171 |
|
| 14302 |
anikendra |
172 |
public function redirecttosaholic() {
|
|
|
173 |
$userId = $this->request->query('user_id');
|
| 15767 |
anikendra |
174 |
$tokenValidated = $this->checkToken($userId);
|
|
|
175 |
if(isset($userId) && !empty($userId) && $tokenValidated==1){
|
|
|
176 |
$next = "&next=/private-deals/1";
|
|
|
177 |
$redirectUrl = $this->getAutoLoginUrl($userId,$next);
|
|
|
178 |
header('location:'.$redirectUrl);
|
|
|
179 |
exit();
|
|
|
180 |
} else{
|
| 16315 |
anikendra |
181 |
// $this->redirect(array('controller'=>'special','action'=>'native','login'));
|
| 16308 |
anikendra |
182 |
if($tokenValidated == 0){
|
| 15651 |
anikendra |
183 |
$this->redirect(array('controller'=>'special','action'=>'native','login'));
|
|
|
184 |
}elseif($tokenValidated == -1){
|
|
|
185 |
$this->redirect(array('controller'=>'abouts','action'=>'askforupdate'));
|
| 16308 |
anikendra |
186 |
}
|
| 15767 |
anikendra |
187 |
}
|
| 14302 |
anikendra |
188 |
}
|
|
|
189 |
|
| 13532 |
anikendra |
190 |
/**
|
|
|
191 |
* edit method
|
|
|
192 |
*
|
|
|
193 |
* @throws NotFoundException
|
|
|
194 |
* @param string $id
|
|
|
195 |
* @return void
|
|
|
196 |
*/
|
|
|
197 |
public function edit($id = null) {
|
|
|
198 |
if (!$this->Click->exists($id)) {
|
|
|
199 |
throw new NotFoundException(__('Invalid click'));
|
|
|
200 |
}
|
|
|
201 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
202 |
if ($this->Click->save($this->request->data)) {
|
|
|
203 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
204 |
return $this->redirect(array('action' => 'index'));
|
|
|
205 |
} else {
|
|
|
206 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
207 |
}
|
|
|
208 |
} else {
|
|
|
209 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
210 |
$this->request->data = $this->Click->find('first', $options);
|
|
|
211 |
}
|
|
|
212 |
$users = $this->Click->User->find('list');
|
|
|
213 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
214 |
$this->set(compact('users', 'storeProducts'));
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
/**
|
|
|
218 |
* delete method
|
|
|
219 |
*
|
|
|
220 |
* @throws NotFoundException
|
|
|
221 |
* @param string $id
|
|
|
222 |
* @return void
|
|
|
223 |
*/
|
|
|
224 |
public function delete($id = null) {
|
|
|
225 |
$this->Click->id = $id;
|
|
|
226 |
if (!$this->Click->exists()) {
|
|
|
227 |
throw new NotFoundException(__('Invalid click'));
|
|
|
228 |
}
|
|
|
229 |
$this->request->onlyAllow('post', 'delete');
|
|
|
230 |
if ($this->Click->delete()) {
|
|
|
231 |
$this->Session->setFlash(__('The click has been deleted.'));
|
|
|
232 |
} else {
|
|
|
233 |
$this->Session->setFlash(__('The click could not be deleted. Please, try again.'));
|
|
|
234 |
}
|
|
|
235 |
return $this->redirect(array('action' => 'index'));
|
|
|
236 |
}
|
|
|
237 |
|
| 14734 |
anikendra |
238 |
public function admin_by($userId = null) {
|
|
|
239 |
$this->Click->recursive = 0;
|
|
|
240 |
$q = $this->request->query('q');
|
|
|
241 |
if(isset($q) && !empty($q)){
|
|
|
242 |
$options = array('conditions' => array('Click.user_id' => $userId, 'Click.url LIKE'=>'%'.$q.'%'),'order'=>array('id'=>'desc'),'limit' => 100);
|
|
|
243 |
$this->set(compact('q'));
|
|
|
244 |
} else {
|
|
|
245 |
$options = array('conditions' => array('Click.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
|
|
|
246 |
}
|
|
|
247 |
$this->Paginator->settings = $options;
|
|
|
248 |
$clicks = $this->Paginator->paginate();
|
|
|
249 |
$this->set(compact('clicks'));
|
|
|
250 |
}
|
|
|
251 |
|
| 13532 |
anikendra |
252 |
/**
|
|
|
253 |
* admin_index method
|
|
|
254 |
*
|
|
|
255 |
* @return void
|
|
|
256 |
*/
|
|
|
257 |
public function admin_index() {
|
|
|
258 |
$this->Click->recursive = 0;
|
| 14734 |
anikendra |
259 |
$q = $this->request->query('q');
|
|
|
260 |
if(isset($q) && !empty($q)){
|
|
|
261 |
$this->Paginator->settings = array('conditions' => array('Click.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
|
|
|
262 |
$this->set(compact('q'));
|
|
|
263 |
} else {
|
|
|
264 |
$this->Paginator->settings = array('order' => array('id'=>'desc'));
|
|
|
265 |
}
|
| 13532 |
anikendra |
266 |
$this->set('clicks', $this->Paginator->paginate());
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
/**
|
|
|
270 |
* admin_view method
|
|
|
271 |
*
|
|
|
272 |
* @throws NotFoundException
|
|
|
273 |
* @param string $id
|
|
|
274 |
* @return void
|
|
|
275 |
*/
|
|
|
276 |
public function admin_view($id = null) {
|
|
|
277 |
if (!$this->Click->exists($id)) {
|
|
|
278 |
throw new NotFoundException(__('Invalid click'));
|
|
|
279 |
}
|
|
|
280 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
281 |
$this->set('click', $this->Click->find('first', $options));
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
/**
|
|
|
285 |
* admin_add method
|
|
|
286 |
*
|
|
|
287 |
* @return void
|
|
|
288 |
*/
|
|
|
289 |
public function admin_add() {
|
|
|
290 |
if ($this->request->is('post')) {
|
|
|
291 |
$this->Click->create();
|
|
|
292 |
if ($this->Click->save($this->request->data)) {
|
|
|
293 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
294 |
return $this->redirect(array('action' => 'index'));
|
|
|
295 |
} else {
|
|
|
296 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
$users = $this->Click->User->find('list');
|
|
|
300 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
301 |
$this->set(compact('users', 'storeProducts'));
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
/**
|
|
|
305 |
* admin_edit method
|
|
|
306 |
*
|
|
|
307 |
* @throws NotFoundException
|
|
|
308 |
* @param string $id
|
|
|
309 |
* @return void
|
|
|
310 |
*/
|
|
|
311 |
public function admin_edit($id = null) {
|
|
|
312 |
if (!$this->Click->exists($id)) {
|
|
|
313 |
throw new NotFoundException(__('Invalid click'));
|
|
|
314 |
}
|
|
|
315 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
316 |
if ($this->Click->save($this->request->data)) {
|
|
|
317 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
318 |
return $this->redirect(array('action' => 'index'));
|
|
|
319 |
} else {
|
|
|
320 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
321 |
}
|
|
|
322 |
} else {
|
|
|
323 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
324 |
$this->request->data = $this->Click->find('first', $options);
|
|
|
325 |
}
|
|
|
326 |
$users = $this->Click->User->find('list');
|
|
|
327 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
328 |
$this->set(compact('users', 'storeProducts'));
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
/**
|
|
|
332 |
* admin_delete method
|
|
|
333 |
*
|
|
|
334 |
* @throws NotFoundException
|
|
|
335 |
* @param string $id
|
|
|
336 |
* @return void
|
|
|
337 |
*/
|
|
|
338 |
public function admin_delete($id = null) {
|
|
|
339 |
$this->Click->id = $id;
|
|
|
340 |
if (!$this->Click->exists()) {
|
|
|
341 |
throw new NotFoundException(__('Invalid click'));
|
|
|
342 |
}
|
|
|
343 |
$this->request->onlyAllow('post', 'delete');
|
|
|
344 |
if ($this->Click->delete()) {
|
|
|
345 |
$this->Session->setFlash(__('The click has been deleted.'));
|
|
|
346 |
} else {
|
|
|
347 |
$this->Session->setFlash(__('The click could not be deleted. Please, try again.'));
|
|
|
348 |
}
|
|
|
349 |
return $this->redirect(array('action' => 'index'));
|
| 14302 |
anikendra |
350 |
}
|
| 18164 |
amit.gupta |
351 |
}
|