Subversion Repositories SmartDukaan

Rev

Rev 20237 | Rev 20267 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * StoreProducts Controller
5
 *
6
 * @property StoreProduct $StoreProduct
7
 * @property PaginatorComponent $Paginator
8
 */
14344 anikendra 9
 set_time_limit(180);
10
 
13532 anikendra 11
class StoreProductsController extends AppController {
12
 
13
/**
14
 * Components
15
 *
16
 * @var array
17
 */
18
	public $components = array('Paginator');
14969 anikendra 19
	public $helpers = array('Time');
13808 anikendra 20
	public $apihost;	
14386 anikendra 21
	public $livepriceurl;
13532 anikendra 22
 
23
	public function beforeFilter() {
24
		parent::beforeFilter();
20139 naman 25
// 		$this->Auth->allow('bycategory','category','mine','getdeals','getliveprice','search','filter','skus');
26
		$this->Auth->allow('bycategory','category','getdeals','getliveprice');
14386 anikendra 27
		$callback = $this->request->query('callback');	
28
		$this->livepriceurl = Configure::read('livepriceurl');	
20243 naman 29
		$this->pythonapihost = Configure::read('pythonapihost');
13532 anikendra 30
	}
13570 anikendra 31
 
15015 anikendra 32
	public function filter($type='brand',$categoryId=3){
33
		$url = $this->apihost.'deals/brands/?category_id='.$categoryId;
34
		$brands = $this->make_request($url,null);
35
		$this->layout = 'innerpages';
36
		$this->set(compact('brands','categoryId'));
37
	}
38
 
17684 naman 39
	public function subcategoryfilter($type='subcategory',$categoryId=6){
40
		$url = $this->apihost.'deals/subCategory/?category_id='.$categoryId;
19325 naman 41
        //debug($url);
17684 naman 42
		$brands = $this->make_request($url,null);
19325 naman 43
		// debug($brands);
17684 naman 44
		$this->layout = 'innerpages';
45
		$this->set(compact('brands','categoryId'));
46
	}	
47
 
13808 anikendra 48
	public function search() {
14215 anikendra 49
		$userId = $this->request->query('user_id');
20103 naman 50
// 		if(isset($userId) && !empty($userId)){
51
// 			$this->loadModel('User');
52
// 			$dbuser = $this->User->findById($userId);
53
// 			$this->Auth->login($dbuser['User']);
54
// 		}
13815 anikendra 55
		$this->layout = 'innerpages';
13808 anikendra 56
		$q = $this->request->query('q');
13901 anikendra 57
		$page = $this->request->query('page');
58
		if(!isset($page)){
59
			$page = 1;
60
		}
61
		$dealsperpage = Configure::read('dealsperpage');
62
		$offset = ($page - 1)*$dealsperpage;
14509 anikendra 63
		$this->loadModel('Campaign');
64
		$campaigns = $this->Campaign->getActiveCampaigns();
13808 anikendra 65
		if(isset($q) && !empty($q)){
13815 anikendra 66
			if (Configure::read('log_solr_queries') === true) {
67
				$this->loadModel('SearchTerm');
68
				$data = array('user_id' => $this->Auth->User('id'),'search_term' => $q);
69
				$this->SearchTerm->create();
70
				$this->SearchTerm->save($data);					
71
			}
13901 anikendra 72
			$result = $this->get_solr_result($q,$page);
19325 naman 73
			//debug($result);
13901 anikendra 74
			$this->set(compact('result','q','page'));
14509 anikendra 75
		}else{
76
			$this->set(compact('campaigns'));
13901 anikendra 77
		}
78
	}
13815 anikendra 79
 
13901 anikendra 80
	public function getsearchresults() {
81
		$this->layout = 'ajax';
82
		$q = $this->request->query('q');
83
		$page = $this->request->query('page');
84
		if(!isset($page)){
85
			$page = 1;
86
		}		
87
		if(isset($q) && !empty($q)){			
88
			$result = $this->get_solr_result($q,$page);
89
			$this->set(compact('result','q','page'));
90
			$this->render('/Elements/searchresult');
13808 anikendra 91
		}
92
	}
93
 
13736 anikendra 94
	public function mine() {		
13591 anikendra 95
		$userId = $this->request->query('user_id');
20103 naman 96
// 		if(isset($userId) && !empty($userId)){
97
// 			$this->loadModel('User');
98
// 			$dbuser = $this->User->findById($userId);
99
// 			$this->Auth->login($dbuser['User']);
100
// 		}
13808 anikendra 101
		// $this->checkMobileNumber();
13583 anikendra 102
		$likedDeals = $disLikedDeals = array();
13570 anikendra 103
		$this->loadModel('Api');
104
		$page = $this->request->query('page');
105
		if(!isset($page)){
106
			$page = 1;
13808 anikendra 107
		}				
108
		//Sort and Direction
109
		$sort = $this->request->query('sort');
110
		$direction = $this->request->query('direction');
111
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),0,$sort,$direction);		
13794 anikendra 112
		$deals = $this->make_request($url,null);
13583 anikendra 113
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
14928 anikendra 114
		$liveScore = $this->Api->getLiveScore();		
13583 anikendra 115
		if(!empty($myactions)) {
116
			foreach ($myactions['actions'] as $key => $value) {
117
				if($value['UserAction']['action'] == 'like'){
118
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
119
				}else{
120
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
121
				}
122
			}
123
		}
13794 anikendra 124
		$title_for_layout = "Get Cashback on favourite";
125
		$description = "Get cashback on your favourite products. Mouth watering deals";
14928 anikendra 126
		$this->set(compact('page', 'title_for_layout', 'description', 'deals', 'likedDeals','disLikedDeals','sort','direction','liveScore'));
13570 anikendra 127
		$this->render('/Pages/home');
128
	}
129
 
130
	public function getdeals() {
13583 anikendra 131
		$likedDeals = $disLikedDeals = array();
13570 anikendra 132
		$this->layout = 'ajax';
133
		$this->loadModel('Api');
134
		$page = $this->request->query('page');
135
		if(!isset($page)){
136
			$page = 1;
13794 anikendra 137
		}	
13815 anikendra 138
		//Sort and Direction
139
		$sort = $this->request->query('sort');
140
		$direction = $this->request->query('direction');
13808 anikendra 141
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),0,$sort,$direction);
13794 anikendra 142
		$deals = $this->make_request($url,null);
13583 anikendra 143
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
144
		if(!empty($myactions)) {
145
			foreach ($myactions['actions'] as $key => $value) {
146
				if($value['UserAction']['action'] == 'like'){
147
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
148
				}else{
149
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
150
				}
151
			}
152
		}
13794 anikendra 153
		$title_for_layout = "Get Cashback on your favourite products";
154
		$description = "Get cashback on your favourite products. Mouth watering deals";
13808 anikendra 155
		$this->set(compact('page', 'title_for_layout', 'description', 'deals', 'likedDeals','disLikedDeals','sort','direction'));
13570 anikendra 156
		$this->render('/Elements/deals');
157
	}	
13532 anikendra 158
/**
159
 * index method
160
 *
161
 * @return void
162
 */
13550 anikendra 163
	public function index($user_id=null) {
13532 anikendra 164
		$this->response->type('json');
165
		$this->layout = 'ajax';
13550 anikendra 166
		$limit = 20;
167
		$this->StoreProduct->recursive = -1;
168
		$count = $this->StoreProduct->find('count');
169
		$this->StoreProduct->Behaviors->attach('Containable');
13689 anikendra 170
		$this->Paginator->settings = array('order'=>array('rank'=>'asc'),'contain'=>array('Product'),'limit'=>$limit,'fields'=>array('Product.category_id','StoreProduct.id','StoreProduct.title','StoreProduct.thumbnail','StoreProduct.available_price','StoreProduct.cashback','StoreProduct.tagline','StoreProduct.offer','StoreProduct.cashback','StoreProduct.available_price','Product.name'));
13550 anikendra 171
		$result = array('products' => $this->Paginator->paginate(),'maxresults'=>ceil($count/$limit));
13532 anikendra 172
		$callback = $this->request->query('callback');
173
		$this->set(array(
174
		    'result' => $result,
175
		    'callback' => $callback,
176
		    '_serialize' => array('result')
177
		));
13567 anikendra 178
		$this->render('/Elements/json');
13532 anikendra 179
	}
180
 
13579 anikendra 181
	public function category($user_id=null,$categoryId=null) {
182
		$this->response->type('json');
183
		$this->layout = 'ajax';
184
		$limit = 20;
185
		$this->StoreProduct->recursive = -1;
186
		// $count = $this->StoreProduct->find('count');
187
		$this->StoreProduct->Behaviors->attach('Containable');
13723 anikendra 188
		$this->Paginator->settings = array('order'=>array('rank'=>'asc'),'conditions'=>array('StoreProduct.category_id'=>$categoryId),'contain'=>array('Product'),'limit'=>$limit,'fields'=>array('Product.category_id','StoreProduct.id','StoreProduct.title','StoreProduct.thumbnail','StoreProduct.available_price','StoreProduct.cashback','StoreProduct.tagline','StoreProduct.offer','StoreProduct.available_price'));
13583 anikendra 189
		$result = array('products' => $this->Paginator->paginate());
13579 anikendra 190
		$callback = $this->request->query('callback');
191
		$this->set(array(
192
		    'result' => $result,
193
		    'callback' => $callback,
194
		    '_serialize' => array('result')
195
		));
196
		$this->render('/Elements/json');
197
	}
198
 
13550 anikendra 199
	public function bycategory($userId=null) {
13541 anikendra 200
		$this->loadModel('UserCategory');
201
		$options = array('conditions' => array('user_id'=>$userId),'recursive'=>-1);
202
		$userCategories = $this->UserCategory->find('all',$options);		
203
		$this->response->type('json');
204
		$this->layout = 'ajax';
13550 anikendra 205
		$limit = 20;
13541 anikendra 206
		$conditions = null;
13550 anikendra 207
		$this->StoreProduct->recursive = -1;
208
		$this->StoreProduct->Behaviors->attach('Containable');
209
		$products = array();
13700 anikendra 210
		// if(!empty($userCategories)){
211
		if(1==2){
13541 anikendra 212
			foreach ($userCategories as $key => $value) {
213
				$categoryIds[] = $value['UserCategory']['category_id'];
13700 anikendra 214
				$conditions = array('StoreProduct.category_id'=>$value['UserCategory']['category_id']);
13689 anikendra 215
				$this->Paginator->settings = array('contain'=>array('Product'),'limit'=>$limit,'fields'=>array('Product.category_id','StoreProduct.id','StoreProduct.title','StoreProduct.thumbnail','StoreProduct.available_price','StoreProduct.cashback','StoreProduct.available_price','StoreProduct.tagline','StoreProduct.offer'),'conditions'=>$conditions);
13550 anikendra 216
				$rows = $this->Paginator->paginate();				
217
				foreach($rows AS $key => $product){
218
					$products[$value['UserCategory']['category_id']][$key][] = $product;
219
				}
13541 anikendra 220
			}
13567 anikendra 221
		}else{
222
			//Fetch all categories
223
			$categories = $this->StoreProduct->Product->Category->find('all');
224
			foreach ($categories as $key => $value) {
225
				$categoryIds[] = $value['Category']['id'];
13700 anikendra 226
				$conditions = array('StoreProduct.category_id'=>$value['Category']['id']);
13689 anikendra 227
				$this->Paginator->settings = array('contain'=>array('Product'),'limit'=>$limit,'fields'=>array('Product.category_id','StoreProduct.id','StoreProduct.title','StoreProduct.thumbnail','StoreProduct.available_price','StoreProduct.cashback','StoreProduct.available_price','StoreProduct.tagline','StoreProduct.offer'),'conditions'=>$conditions);
13567 anikendra 228
				$rows = $this->Paginator->paginate();				
229
				foreach($rows AS $key => $product){
230
					$products[$value['Category']['id']][$key][] = $product;
231
				}
232
			}
13700 anikendra 233
		}		
234
		$this->log(print_r($products,1),'bycategory')	;		
13550 anikendra 235
		$result = array('products' => $products);//,'categories'=>$categoryIds);
13541 anikendra 236
		$callback = $this->request->query('callback');
237
		$this->set(array(
238
		    'result' => $result,
239
		    'callback' => $callback,
240
		    '_serialize' => array('result')
241
		));
13567 anikendra 242
		$this->render('/Elements/json');
13541 anikendra 243
	}
244
 
13532 anikendra 245
/**
246
 * view method
247
 *
248
 * @throws NotFoundException
249
 * @param string $id
250
 * @return void
251
 */
13901 anikendra 252
	public function view($id = null,$bundleId=null) {
15311 anikendra 253
		$userId = $this->request->query('user_id');
20103 naman 254
// 		if(isset($userId) && !empty($userId)){
255
// 			$this->loadModel('User');
256
// 			$dbuser = $this->User->findById($userId);
257
// 			$this->Auth->login($dbuser['User']);
258
// 		}
13901 anikendra 259
		$this->layout = "innerpages";
260
		$cachekey = 'storeproduct-'.$id;
16234 anikendra 261
		// $product = Cache::read($cachekey,'fivemin');
13901 anikendra 262
		if(empty($product)) {
16234 anikendra 263
			$url = $this->apihost.'masterData/getSkuById/'.$id.'?showDp=1';
13901 anikendra 264
			$product = $this->make_request($url,null);
14139 anikendra 265
			Cache::write($cachekey,$product,'fivemin');			
13532 anikendra 266
		}
13901 anikendra 267
		$storeProduct = json_decode($product[0],1);
268
		$activestores = Configure::read('activestores');
269
		$this->set(compact('storeProduct','activestores'));
13532 anikendra 270
	}
271
 
13901 anikendra 272
	public function getliveprice($bundleId=null,$storeId=null) {
14386 anikendra 273
		// $cachekey = 'liveprice-'.$bundleId.'-'.$storeId;
274
		// $this->log($cachekey,'api');
14345 anikendra 275
		// $products = Cache::read($cachekey,'fivemin');
14386 anikendra 276
		// if(empty($products)) {
14387 anikendra 277
		session_write_close();
14386 anikendra 278
		$result = array();
279
		$this->response->type('json');
280
		$this->layout = 'ajax';
20103 naman 281
// 		$dealpin = $this->getpin();
14386 anikendra 282
		$url = $this->livepriceurl."?skuBundleId=$bundleId&source_id=$storeId";
20103 naman 283
// 		$url = $url."&pin=".$dealpin;
14386 anikendra 284
		$products = $this->make_request($url,null);
285
			// Cache::write($cachekey,$products,'fivemin');			
286
		// }
13901 anikendra 287
		if(!empty($products)){
288
			$result['products'] = array();
289
			foreach($products AS $product) {
14386 anikendra 290
				// debug($product);
291
				array_push($result['products'],$product);
13901 anikendra 292
			}
293
			$products = json_decode(stripslashes(json_encode($products)));
294
			$result['success'] = true;
19325 naman 295
			$subcat_id = $result['products'][0]['subCategoryId'];
296
			$cat_id = $result['products'][0]['category_id'];
297
 
298
			//check for offer start
299
			$user_id = $this->Auth->user('id');
300
			$cachekey = 'target-'.$user_id;
301
			$getoffer = Cache::read($cachekey,'target');
302
 
303
			$offertext = "";
304
			$offerresponse = "";
305
			if($result['products'][0]['source_id'] == 4){
306
				if($getoffer === false){
307
					$offerurl = $this->apihost."getOfferForUser/?user_id=".$user_id;
308
					$offerresponse = $this->make_request($offerurl,null);
309
					Cache::write($cachekey , $offerresponse ,'target');
310
					if(!empty($offerresponse)){
311
						$current_time = time();
312
						if($offerresponse['startDate']/1000 <= $current_time && $offerresponse['endDate']/1000 >= $current_time ){
313
 
314
							if( isset($offerresponse['categories_applicable']) && in_array( $cat_id ,$offerresponse['categories_applicable']) && isset($offerresponse['sub_categories_not_applicable']) && !in_array($subcat_id ,$offerresponse['sub_categories_not_applicable'])){
315
								$offertext = $offerresponse['offer_description'];
316
							}
317
						}
318
 
319
					}
320
				}else{
321
					if(!empty($getoffer)){
322
							$offerresponse = $getoffer;
323
							$current_time = time();
324
							if($offerresponse['startDate']/1000 <= $current_time && $offerresponse['endDate']/1000 >= $current_time ){
325
 
326
								if( isset($offerresponse['categories_applicable']) && in_array( $cat_id ,$offerresponse['categories_applicable']) && isset($offerresponse['sub_categories_not_applicable']) && !in_array($subcat_id ,$offerresponse['sub_categories_not_applicable'])){
327
									$offertext = $offerresponse['offer_description'];
328
								}
329
							}
330
 
331
						}
332
				}
333
			}	
334
 
335
			$result['offertext'] = $offertext;
336
			//check for offer end
337
 
13901 anikendra 338
			// $result['products'] = $products;
14386 anikendra 339
		} else{
13901 anikendra 340
			$result['success'] = false;
341
		}
342
		$this->response->type('json');
343
		$this->layout = 'ajax';
344
		$this->set(array(
345
		    'result' => $result,
346
		    '_serialize' => array('result')
347
		));
348
		$this->render('/Elements/json');
349
	}
350
 
13532 anikendra 351
/**
352
 * add method
353
 *
354
 * @return void
355
 */
356
	public function add() {
357
		if ($this->request->is('post')) {
358
			$this->StoreProduct->create();
359
			if ($this->StoreProduct->save($this->request->data)) {
360
				$this->Session->setFlash(__('The store product has been saved.'));
361
				return $this->redirect(array('action' => 'index'));
362
			} else {
363
				$this->Session->setFlash(__('The store product could not be saved. Please, try again.'));
364
			}
365
		}
366
		$stores = $this->StoreProduct->Store->find('list');
367
		$products = $this->StoreProduct->Product->find('list');
368
		$this->set(compact('stores', 'products'));
369
	}
370
 
371
/**
372
 * edit method
373
 *
374
 * @throws NotFoundException
375
 * @param string $id
376
 * @return void
377
 */
378
	public function edit($id = null) {
379
		if (!$this->StoreProduct->exists($id)) {
380
			throw new NotFoundException(__('Invalid store product'));
381
		}
382
		if ($this->request->is(array('post', 'put'))) {
383
			if ($this->StoreProduct->save($this->request->data)) {
384
				$this->Session->setFlash(__('The store product has been saved.'));
385
				return $this->redirect(array('action' => 'index'));
386
			} else {
387
				$this->Session->setFlash(__('The store product could not be saved. Please, try again.'));
388
			}
389
		} else {
390
			$options = array('conditions' => array('StoreProduct.' . $this->StoreProduct->primaryKey => $id));
391
			$this->request->data = $this->StoreProduct->find('first', $options);
392
		}
393
		$stores = $this->StoreProduct->Store->find('list');
394
		$products = $this->StoreProduct->Product->find('list');
395
		$this->set(compact('stores', 'products'));
396
	}
397
 
398
/**
399
 * delete method
400
 *
401
 * @throws NotFoundException
402
 * @param string $id
403
 * @return void
404
 */
405
	public function delete($id = null) {
406
		$this->StoreProduct->id = $id;
407
		if (!$this->StoreProduct->exists()) {
408
			throw new NotFoundException(__('Invalid store product'));
409
		}
410
		$this->request->onlyAllow('post', 'delete');
411
		if ($this->StoreProduct->delete()) {
412
			$this->Session->setFlash(__('The store product has been deleted.'));
413
		} else {
414
			$this->Session->setFlash(__('The store product could not be deleted. Please, try again.'));
415
		}
416
		return $this->redirect(array('action' => 'index'));
417
	}
418
 
419
/**
420
 * admin_index method
421
 *
422
 * @return void
423
 */
424
	public function admin_index() {
425
		$this->StoreProduct->recursive = 0;
426
		$this->set('storeProducts', $this->Paginator->paginate());
427
	}
428
 
429
/**
430
 * admin_view method
431
 *
432
 * @throws NotFoundException
433
 * @param string $id
434
 * @return void
435
 */
436
	public function admin_view($id = null) {
437
		if (!$this->StoreProduct->exists($id)) {
438
			throw new NotFoundException(__('Invalid store product'));
439
		}
440
		$options = array('conditions' => array('StoreProduct.' . $this->StoreProduct->primaryKey => $id));
441
		$this->set('storeProduct', $this->StoreProduct->find('first', $options));
442
	}
443
 
444
/**
445
 * admin_add method
446
 *
447
 * @return void
448
 */
449
	public function admin_add() {
450
		if ($this->request->is('post')) {
451
			$this->StoreProduct->create();
452
			if ($this->StoreProduct->save($this->request->data)) {
453
				$this->Session->setFlash(__('The store product has been saved.'));
454
				return $this->redirect(array('action' => 'index'));
455
			} else {
456
				$this->Session->setFlash(__('The store product could not be saved. Please, try again.'));
457
			}
458
		}
459
		$stores = $this->StoreProduct->Store->find('list');
460
		$products = $this->StoreProduct->Product->find('list');
461
		$this->set(compact('stores', 'products'));
462
	}
463
 
464
/**
465
 * admin_edit method
466
 *
467
 * @throws NotFoundException
468
 * @param string $id
469
 * @return void
470
 */
471
	public function admin_edit($id = null) {
472
		if (!$this->StoreProduct->exists($id)) {
473
			throw new NotFoundException(__('Invalid store product'));
474
		}
475
		if ($this->request->is(array('post', 'put'))) {
476
			if ($this->StoreProduct->save($this->request->data)) {
477
				$this->Session->setFlash(__('The store product has been saved.'));
478
				return $this->redirect(array('action' => 'index'));
479
			} else {
480
				$this->Session->setFlash(__('The store product could not be saved. Please, try again.'));
481
			}
482
		} else {
483
			$options = array('conditions' => array('StoreProduct.' . $this->StoreProduct->primaryKey => $id));
484
			$this->request->data = $this->StoreProduct->find('first', $options);
485
		}
486
		$stores = $this->StoreProduct->Store->find('list');
487
		$products = $this->StoreProduct->Product->find('list');
488
		$this->set(compact('stores', 'products'));
489
	}
490
 
491
/**
492
 * admin_delete method
493
 *
494
 * @throws NotFoundException
495
 * @param string $id
496
 * @return void
497
 */
498
	public function admin_delete($id = null) {
499
		$this->StoreProduct->id = $id;
500
		if (!$this->StoreProduct->exists()) {
501
			throw new NotFoundException(__('Invalid store product'));
502
		}
503
		$this->request->onlyAllow('post', 'delete');
504
		if ($this->StoreProduct->delete()) {
505
			$this->Session->setFlash(__('The store product has been deleted.'));
506
		} else {
507
			$this->Session->setFlash(__('The store product could not be deleted. Please, try again.'));
508
		}
509
		return $this->redirect(array('action' => 'index'));
16363 anikendra 510
	}
511
 
512
	public function admin_genurl() {
16368 anikendra 513
 
16363 anikendra 514
	}
16368 anikendra 515
 
516
	public function skus($bundleIds) {
20139 naman 517
// 		$userId = $this->request->query('user_id');
518
// 		if(isset($userId) && !empty($userId)) {
519
// 			$this->loadModel('User');
520
// 			$this->User->recursive = -1;
521
// 			$dbuser = $this->User->findById($userId);
522
// 			$this->Auth->login($dbuser['User']);
523
// 		}
16368 anikendra 524
		//Fetch list of bundleIds from api
525
		$url = $this->apihost.'getDealsForNotification/'.$bundleIds;
526
		$response = $this->make_request($url,null);
527
		$deals = array();
528
		if(!empty($response)){
529
			foreach ($response as $key => $value) {
530
				if(!empty($value)){
531
					$deals[] = $value;
532
				}
533
			}
534
		}
535
		$noscrolling = true;
536
		$this->set(compact('deals','id','noscrolling'));
537
	}
20237 naman 538
 
539
 
540
	public function autosuggest($ser){
541
		$ser = $this->request->query('term');
542
 
543
// 		$res= '[{ "value": "Afghan afghani", "id" : "hello"},{ "value": "Albanian lek","id" : "hello" },{ "value": "Algerian dinar" ,"id" : "hello"}]';
544
		$this->autoRender = false;
545
		$this->request->onlyAllow('ajax');
546
 
547
		$url ="http://shop2020.in:8080/dtr/solr-search!getSuggestions?search_text=".urlencode($ser);
548
		$res = $this->make_request($url, null);
549
		return json_encode($res);
550
 
551
	}
552
 
553
	public function newsearch(){
554
		$q = $this->request->query('q');
555
		$this->layout = 'innerpages';
556
		$page =2;
557
// 		$noti='[{"title": "Riviera Series J Battery For Micromax A240","id": "28750"}]';
558
// 		$result = json_decode($noti,1);
559
 
20243 naman 560
		$url = $this->pythonapihost."dtr/solr-search!getSearchResults?search_text=".urlencode($q)."&offset=0";
20237 naman 561
		$result = $this->make_request($url, null);
562
		$nexturl = "/store_products/nextsearch?page=".$page."&search_text=".urlencode($q);
563
		$this->set(compact('result','nexturl','q'));
564
	}
565
 
566
	public function nextsearch(){
567
		$this->layout = 'ajax';
568
		$page = $this->request->query('page');
569
		$ser = $this->request->query('search_text');
570
		if(!isset($page)){
571
			$page = 1;
572
		}
573
		$offset = ($page - 1)*20;
574
// 		$noti='[{"title": "Riviera Series J Battery For Micromax A240","id": "28750"}]';
575
// 		$result = json_decode($noti,1);
576
 
20243 naman 577
		$url = $this->pythonapihost."dtr/solr-search!getSearchResults?search_text=".urlencode($ser)."&offset=".$offset;
20237 naman 578
		$result = $this->make_request($url, null);
579
 
580
		$nexturl = "/store_products/nextsearch?page=".($page+1)."&search_text=".urlencode($ser);
581
		$this->set(compact('result','nexturl'));
582
		$this->render('/Elements/newsearchresult');
583
	}
16363 anikendra 584
}