Subversion Repositories SmartDukaan

Rev

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