Subversion Repositories SmartDukaan

Rev

Rev 19834 | Rev 19923 | 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
 * Categories Controller
5
 *
6
 * @property Category $Category
7
 * @property PaginatorComponent $Paginator
8
 */
9
class CategoriesController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
13794 anikendra 17
	public $apihost;
18
	public $limit;
13532 anikendra 19
 
13596 anikendra 20
	public function beforeFilter() {
21
		parent::beforeFilter();
22
		$this->Auth->allow('deals');
13794 anikendra 23
		$this->apihost = Configure::read('pythonapihost');
24
		$this->limit = Configure::read('dealsperpage');
18223 naman 25
		$this->mobileapi = Configure::read('saholicapihost');
19244 amit.gupta 26
		setcookie("fresh", '1', null, '/');
18223 naman 27
 
13596 anikendra 28
	}
29
 
13532 anikendra 30
/**
31
 * index method
32
 *
33
 * @return void
34
 */
35
	public function index() {
36
		// $this->Category->recursive = 0;
37
		// $this->set('categories', $this->Paginator->paginate());
13541 anikendra 38
		$userId = $this->request->query('user_id');
39
		$this->loadModel('UserCategory');
13689 anikendra 40
		$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);
13541 anikendra 41
		$userCategories = $this->UserCategory->find('all',$options);		
13532 anikendra 42
		$this->response->type('json');
43
		$this->layout = 'ajax';
13541 anikendra 44
		$conditions = array(array('Category.parent_id !='=>0));
45
		if(!empty($userCategories)){
46
			foreach ($userCategories as $key => $value) {
47
				$categoryIds[] = $value['UserCategory']['category_id'];
48
			}
49
			array_push($conditions,array('Category.id'=>$categoryIds));
50
		}
51
		$this->Category->recursive = -1;		
13532 anikendra 52
		$categories = $this->Paginator->paginate(null,$conditions);
53
		$callback = $this->request->query('callback');
54
		$result = array('categories' => $categories);
55
		$this->set(array(
56
		    'result' => $result,
57
		    'callback' => $callback,
58
		    '_serialize' => array('result')
59
		));
60
		$this->render('/Elements/jsonp');
61
	}
62
 
13567 anikendra 63
	public function deals(){
13591 anikendra 64
		$userId = $this->request->query('user_id');
17962 manish.sha 65
		$error = $this->request->query('error');
13591 anikendra 66
		if(isset($userId) && !empty($userId)){
13597 anikendra 67
			$this->loadModel('User');
68
			$dbuser = $this->User->findById($userId);
69
			$this->Auth->login($dbuser['User']);	
13591 anikendra 70
		}
13583 anikendra 71
		$likedDeals = $disLikedDeals = array();
13794 anikendra 72
		// $this->loadModel('Api');
73
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
74
		// $categorydeals = $apideals['products'];
75
		$page = $this->request->query('page');
76
		if(!isset($page)){
77
			$page = 1;
78
		}
79
		$offset = ($page - 1) * $this->limit;
80
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
17683 naman 81
		//debug($url);
13794 anikendra 82
		$deals = $this->make_request($url,null);		
13583 anikendra 83
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
84
		if(!empty($myactions)) {
85
			foreach ($myactions['actions'] as $key => $value) {
86
				if($value['UserAction']['action'] == 'like'){
87
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
88
				}else{
89
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
90
				}
91
			}
92
		}
17962 manish.sha 93
 
94
		$errorstr = '';
95
 
96
		if(isset($error)){
97
			$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
98
		}
13567 anikendra 99
		$rows = sizeof($categorydeals);
100
		if($rows>=1){
101
			$this->set('deals',$categorydeals);
13583 anikendra 102
			$this->set('likedDeals',$likedDeals);
103
			$this->set('disLikedDeals',$disLikedDeals);
17962 manish.sha 104
			$this->set('errorstr',$errorstr);
13567 anikendra 105
			$this->render('categorydeals');
106
		}else{
107
			foreach ($categorydeals as $key => $dealarr) {
108
				foreach ($dealarr as $key => $deal) {
109
					$deals[] = $deal[0];
110
				}				
111
			}
17962 manish.sha 112
			$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));
13567 anikendra 113
		}		
114
	}
115
/*
116
	*
13532 anikendra 117
 * view method
118
 *
119
 * @throws NotFoundException
120
 * @param string $id
121
 * @return void
122
 */
123
	public function view($id = null) {
19609 naman 124
		$arrSubCategory = Configure::read('arrSubCategory');
18393 amit.gupta 125
		$userId = $this->request->query('user_id');
15378 anikendra 126
		if(isset($userId) && !empty($userId)) {
14930 anikendra 127
			$this->loadModel('User');
128
			$dbuser = $this->User->findById($userId);
129
			$this->Auth->login($dbuser['User']);
19829 naman 130
		}
131
		$color = array('0'=>'#458ccc','1'=>'#44cbbc','2'=>'#a77189', '3'=>'#f9b931' ,'4' =>'#44cbbc', '5' => '#f48f3f' , '6'=>'#a77189');
19345 naman 132
 
18390 naman 133
		//Sort - type, ordering
134
		$sort = $this->request->query('sort');
135
		$direction = $this->request->query('direction');
136
 
137
		//Filter - brand/subcategory		
138
		$brands = $this->request->query('brands');
139
		$subcategories = $this->request->query('subcategories');
140
 
19543 amit.gupta 141
		$searchableSubCategories = array('20'=>'Screen Guard', '27'=>'Back Cover', '29'=>'Batteries', '33'=>'Flip Cover', '28'=>'Tempered Glass');
18390 naman 142
 
19609 naman 143
		$subcatlist = Configure::read('arrSubCategory');
144
 
145
		$whatfirst = $this->request->query('whatfirst');
19640 naman 146
 
19622 naman 147
		if($id == 6)
148
		{
19644 naman 149
 
150
			if(isset($brands) && !empty($brands) && !isset($subcategories) && !isset($whatfirst)){
151
				$whatfirst = "brand";
152
			}
153
			else if(isset($subcategories) && !empty($subcategories) && !isset($brands) && !isset($whatfirst)){
154
				$whatfirst = "subCategory";
155
			}else if(isset($subcategories) && !empty($subcategories) && isset($brands) && !empty($brands) && !isset($whatfirst)){
156
				$whatfirst = "subCategory";
157
			}
158
 
19622 naman 159
			$cachekey = 'subcat-6';
160
			$getdet = Cache::read($cachekey,'subcatdetail');
161
			if(empty($getdet) || $getdet === false){
19657 naman 162
				$url = $this->apihost."getHeaderLinks/?category_id=6";
19622 naman 163
				$getdet = $this->make_request($url,null);
164
				Cache::write($cachekey , $getdet ,'subcatdetail');
165
			}
166
			$this->set(compact('getdet'));
167
		}
168
 
19609 naman 169
		$whatsecond = "";
170
		$whatsecondid = "";
171
		$whatfirstid = "";
172
		$secondloop = "";
173
		if(isset($whatfirst)){
174
			$brandprourl = "";
175
			if($whatfirst == "subCategory"){
176
				$secondloop = explode("^",$brands);
177
				$whatsecond = "brand";
178
				$whatsecondid = "brand_id";
179
				$whatfirstid = "subCategoryId";
180
				$brandprourl = $this->apihost."getBrandSubCategoryInfo/?category_id=6&type=subCategoryInfo&id_list=".$subcategories;
181
			}
182
			else if($whatfirst == "brand"){
183
 
184
				$secondloop = explode("^",$subcategories);
185
				$whatsecond = "subCategory";
186
				$whatsecondid = "subCategoryId";
187
				$whatfirstid = "brand_id";
188
				$brandprourl = $this->apihost."getBrandSubCategoryInfo/?category_id=6&type=brandInfo&id_list=".$brands;
189
			}
190
			$allbrandsubcat = $this->make_request($brandprourl, null);
191
			$this->set(compact('secondloop','whatfirstid','whatsecondid','subcatlist','whatfirst','whatsecond','allbrandsubcat'));
192
		}
193
 
194
 
13583 anikendra 195
		$page = $this->request->query('page');
18063 naman 196
		$searchfor = $this->request->query('searchFor');
197
		// echo "page=>",$page;
17810 manish.sha 198
		$error = $this->request->query('error');
13583 anikendra 199
		if(!isset($page)){
200
			$page = 1;
16549 anikendra 201
		}
202
 
18207 amit.gupta 203
		//$filter = $this->request->query('filter');
15044 anikendra 204
		// $brands = $this->request->query('brands');
16549 anikendra 205
		if($id != 2) {
19829 naman 206
			if($id != 6){
19834 naman 207
				$url = $this->apihost.'deals/brands/?category_id='.$id;
19829 naman 208
				$brandres = $this->make_request($url,null);
209
				$brandlist = array();
210
				foreach ($brandres as $bkey => $bvalue){
211
					$brandlist[$bvalue['brand_id']] = $bvalue['brand'];
212
				}
213
				$this->set(compact('brandlist'));
214
			}
16549 anikendra 215
			//Fetch deals
216
			$likedDeals = $disLikedDeals = array();
18390 naman 217
			if(!empty($brands) && !empty($subcategories)){
218
				$filter = 'brand|subcategory';
219
			}			
220
			else if(!empty($brands)){
221
				$filter = 'brand';
222
			}
223
			else if(!empty($subcategories)){
224
				$filter = 'subcategory';
225
			}
17759 naman 226
 
18390 naman 227
			$sortlabel = 'recommended';
228
			if	($sort=='bestSellerPoints'){
229
				$sortlabel  = 'bestseller';
18063 naman 230
			}
18390 naman 231
			else if ($sort=='available_price' && $direction==-1){
232
				$sortlabel  = 'pricehigh';
16549 anikendra 233
			}
18390 naman 234
			else if ($sort=='available_price' && $direction==1){
235
				$sortlabel  = 'pricelow';
236
			}
17683 naman 237
 
238
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16549 anikendra 239
			$response = $this->make_request($url,null);
240
			$deals = array();
17683 naman 241
 
242
			$response_count =1;
243
			if($response == '')
244
			{
245
				$response_count = 0;
246
			}
247
			// debug($response_count);
16549 anikendra 248
			if(!empty($response)){
249
				foreach ($response as $key => $value) {
250
					if(!empty($value)){
251
						$deals[] = $value;
252
					}
16098 anikendra 253
				}
254
			}
17683 naman 255
			#print_r($deals);
16549 anikendra 256
			$this->loadModel('Api');
257
			$myactions = $this->Api->getMyActions($this->Auth->User('id'));
258
			if(!empty($myactions)) {
259
				foreach ($myactions['actions'] as $key => $value) {
260
					if($value['UserAction']['action'] == 'like'){
261
						$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
262
					}else{
263
						$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
264
					}
13583 anikendra 265
				}
266
			}
16549 anikendra 267
			$this->loadModel('NotificationRule');
268
			$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));	
269
		    $filterstr = '';
270
			if(isset($filter) && !empty($filter)){
17759 naman 271
 
17683 naman 272
			    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
17695 naman 273
		  	} 
274
		  	$get_url = "'".$_SERVER['REQUEST_URI']."'";
275
		  	$urlArray = explode('=',$_SERVER['REQUEST_URI']);
276
		  	$last = $urlArray[sizeof($urlArray)-1];
277
 
17810 manish.sha 278
			$errorstr = '';
279
 
280
			if(isset($error)){
281
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
282
			}
17759 naman 283
 
18390 naman 284
			$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;
285
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
18063 naman 286
 
19609 naman 287
			$offerresponse = $this->getuseroffer();
19829 naman 288
 
19609 naman 289
			$this->set(compact('color','arrSubCategory','offerresponse','response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','subcategories','errorstr','nexturl','searchfor', 'searchableSubCategories', 'sortlabel'));
16549 anikendra 290
		}else{
16583 anikendra 291
			//Check for apk support of sharing
292
			$sharable = 0;
293
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
294
				$sharable = 1;
17183 anikendra 295
			}			
16704 anikendra 296
			$url = $this->apihost."appOffers/1";
297
			$appOffers = $this->make_request($url,null);
298
			$this->set(compact('page','id','sharable','appOffers'));
16549 anikendra 299
			$this->render('viewapps');
13583 anikendra 300
		}
13532 anikendra 301
	}
302
 
16549 anikendra 303
	public function getapps($id=null){
304
		$this->layout = 'ajax';
305
		$page = $this->request->query('page');
306
		if(!isset($page)){
307
			$page = 1;
308
		}
309
		$this->loadModel('AppOffer');
310
		$this->AppOffer->recursive = -1;
311
		$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
312
		$this->Paginator->settings = $options;
313
		try{
314
			$appOffers = $this->Paginator->paginate('AppOffer');
315
		} catch (NotFoundException $e) {
316
	        //get current page
317
	        $page = $this->request->params['named']['page'];
318
	     	$appOffers = array();   
319
		}
320
		debug($appOffers);		
321
		if(!empty($appOffers)){
322
			$this->set(compact('page','id','appOffers'));
323
			$this->render('/Elements/appoffers');
324
		}else{
325
			$this->render('/Elements/nooffers');
326
		}		
327
	}
328
 
13579 anikendra 329
	public function getdeals($id = null) {
17695 naman 330
 
13808 anikendra 331
		$this->log('getdeal id '.$id,'api');
13583 anikendra 332
		$likedDeals = $disLikedDeals = array();
13579 anikendra 333
		$this->layout = 'ajax';
334
		$page = $this->request->query('page');
335
		if(!isset($page)){
336
			$page = 1;
337
		}
13808 anikendra 338
		$sort = $this->request->query('sort');
339
		$direction = $this->request->query('direction');
15044 anikendra 340
		// $filter = $this->request->query('filter');
341
		// $brands = $this->request->query('brands');
18390 naman 342
		$brands = $this->request->query('brands');
343
		$subcategories = $this->request->query('subcategories'); 	
17759 naman 344
 
18390 naman 345
		$likedDeals = $disLikedDeals = array();
346
		if(!empty($brands) && !empty($subcategories)){
17759 naman 347
			$filter = 'brand|subcategory';
18390 naman 348
		}
349
		else if(!empty($brands)){
15044 anikendra 350
			$filter = 'brand';
351
		}
18390 naman 352
		else if(!empty($subcategories)){
17759 naman 353
			$filter = 'subcategory';
354
		}
18390 naman 355
 
17759 naman 356
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16098 anikendra 357
		$response = $this->make_request($url,null);
358
		$deals = array();
359
		if(!empty($response)){
360
			foreach ($response as $key => $value) {
361
				if(!empty($value)){
362
					$deals[] = $value;
363
				}
364
			}
365
		}
13794 anikendra 366
		// if (!$this->Category->exists($id)) {
367
			// throw new NotFoundException(__('Invalid category'));
368
		// }
13579 anikendra 369
		$this->loadModel('Api');
13794 anikendra 370
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
371
		// $deals = $apideals['products'];
13583 anikendra 372
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
373
		if(!empty($myactions)) {
374
			foreach ($myactions['actions'] as $key => $value) {
375
				if($value['UserAction']['action'] == 'like'){
376
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
377
				}else{
378
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
379
				}
380
			}
381
		}
18390 naman 382
 
383
		$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;
384
		$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
19306 naman 385
 
19609 naman 386
		$offerresponse = $this->getuseroffer();
19306 naman 387
 
19609 naman 388
		$this->set(compact('offerresponse','nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
16098 anikendra 389
		if(!empty($deals) && !empty($deals[0])){
15026 anikendra 390
			$this->render('/Elements/deals');
391
		}else{
392
			$this->render('/Elements/nodeals');
393
		}
17695 naman 394
 
395
 
396
 
13579 anikendra 397
	}
19904 naman 398
 
399
	public function linkdeal($id = null) {
400
		$filtertype = $this->request->query('filtertype');
401
		$page = $this->request->query('page');
402
		if(!isset($page)){
403
			$page = 1;
404
		}
405
		$url = $this->apihost."getDealsByType?categoryId=".$id."&offset=0&limit=20&type=".$filtertype;
406
		$response = $this->make_request($url,null);
407
		$deals = array();
408
 
409
		$response_count =1;
410
		if($response == '')
411
		{
412
			$response_count = 0;
413
		}
18063 naman 414
 
19904 naman 415
		if(!empty($response)){
416
			foreach ($response as $key => $value) {
417
				if(!empty($value)){
418
					$deals[] = $value;
419
				}
420
			}
421
		}
422
 
423
		$this->loadModel('Api');
424
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
425
		if(!empty($myactions)) {
426
			foreach ($myactions['actions'] as $key => $value) {
427
				if($value['UserAction']['action'] == 'like'){
428
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
429
				}else{
430
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
431
				}
432
			}
433
		}
434
 
435
 
436
		$nexturl = "/categories/getlinkdeals/".$id."?page=".($page+1)."&filtertype=".$filtertype;			
437
		$offerresponse = $this->getuseroffer();
438
 
439
		$this->set(compact('offerresponse','response_count','deals','id','likedDeals','disLikedDeals','page','nexturl'));
440
	}
441
 
442
 
443
	public function getlinkdeals($id = null) {
444
 
445
		$likedDeals = $disLikedDeals = array();
446
		$this->layout = 'ajax';
447
		$page = $this->request->query('page');
448
		$filtertype = $this->request->query('filtertype');
449
		if(!isset($page)){
450
			$page = 1;
451
		}
452
		$limit = 20;
453
		$offset = ($page - 1)*$limit;
454
 
455
		$likedDeals = $disLikedDeals = array();
456
		$url = $this->apihost."getDealsByType?categoryId=".$id."&type=".$filtertype."&limit=".$limit."&offset=".$offset;
457
		$response = $this->make_request($url,null);
458
		$deals = array();
459
		if(!empty($response)){
460
			foreach ($response as $key => $value) {
461
				if(!empty($value)){
462
					$deals[] = $value;
463
				}
464
			}
465
		}
466
 
467
		$this->loadModel('Api');
468
 
469
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
470
		if(!empty($myactions)) {
471
			foreach ($myactions['actions'] as $key => $value) {
472
				if($value['UserAction']['action'] == 'like'){
473
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
474
				}else{
475
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
476
				}
477
			}
478
		}
479
 
480
		$nexturl = "/categories/getlinkdeals/".$id."/?page=".($page+1)."&filtertype=".$filtertype;
481
 
482
		$offerresponse = $this->getuseroffer();
483
 
484
		$this->set(compact('offerresponse','nexturl','deals','id','page','likedDeals','disLikedDeals'));
485
		if(!empty($deals) && !empty($deals[0])){
486
			$this->render('/Elements/deals');
487
		}else{
488
			$this->render('/Elements/nodeals');
489
		}
490
	}
491
 
492
 
18212 naman 493
	public function dealdetail($item_id = null){
19244 amit.gupta 494
		setcookie("fresh", '0', null, '/');
18212 naman 495
		$this->layout = "innerpages";
18223 naman 496
		$dealinfo = $deal = array();
497
		$likedDeals = $disLikedDeals = array();
498
		$url = $this->mobileapi.'entity/'.$item_id;
499
		$dealinfo = $this->make_request($url,null);
500
		$this->loadModel('Api');
501
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
502
		if(!empty($myactions)) {
503
			foreach ($myactions['actions'] as $key => $value) {
504
				if($value['UserAction']['action'] == 'like'){
505
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
506
				}else{
507
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
508
				}
509
			}
510
		}
511
		$this->set(compact('deal','dealinfo','likedDeals','disLikedDeals'));
18212 naman 512
	}
513
 
18288 naman 514
	public function saholicdeal($proid = null){
515
		$likedDeals = $disLikedDeals = array();
516
		$this->layout = 'ajax';
517
		$deal = array();
518
		$url = $this->apihost."getDealById/".$proid;
519
		$deal = $this->make_request($url,null);
520
		$this->loadModel('Api');
521
 
522
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
523
		if(!empty($myactions)) {
524
			foreach ($myactions['actions'] as $key => $value) {
525
				if($value['UserAction']['action'] == 'like'){
526
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
527
				}else{
528
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
529
				}
530
			}
531
		}
532
 
19609 naman 533
		$offerresponse = $this->getuseroffer();
18288 naman 534
 
19609 naman 535
		$this->set(compact('offerresponse','deal','likedDeals','disLikedDeals'));
19327 naman 536
 
18288 naman 537
		$this->render('/Elements/saholicdeal');
538
 
539
 
540
	}
541
 
18063 naman 542
	public function getdealsforsearchterm($searchterm,$page = null){
543
		$likedDeals = $disLikedDeals = array();
544
		$this->layout = 'ajax';
545
		$page = $this->request->query('page');
18390 naman 546
		$subcategories = $this->request->query('subcategories'); 
18063 naman 547
		if(!isset($page)){
548
			$page = 1;
549
			$offset = 0;
550
			$limit=10;
551
		}
552
		else{
553
			$offset = ($page*20) - 30;
554
			$limit = 20;
555
		}
556
		$sort = $this->request->query('sort');
557
		$direction = $this->request->query('direction');
558
 
18390 naman 559
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategories;
18063 naman 560
		$response = $this->make_request($url,null);
561
		$deals = array();
562
		if(!empty($response)){
563
			foreach ($response as $key => $value) {
564
				if(!empty($value)){
565
					$deals[] = $value;
566
				}
567
			}
568
		}
18115 amit.gupta 569
 
18063 naman 570
		$this->loadModel('Api');
18115 amit.gupta 571
 
18063 naman 572
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
573
		if(!empty($myactions)) {
574
			foreach ($myactions['actions'] as $key => $value) {
575
				if($value['UserAction']['action'] == 'like'){
576
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
577
				}else{
578
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
579
				}
580
			}
581
		}
582
 
18390 naman 583
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1).'&subcategories='.$subcategories;
19327 naman 584
 
19609 naman 585
		$offerresponse = $this->getuseroffer(); 
19327 naman 586
 
19609 naman 587
		$this->set(compact('offerresponse','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
18063 naman 588
		if(!empty($deals) && !empty($deals[0])){
589
			$this->render('/Elements/deals');
590
		}else{
591
			$this->render('/Elements/nodeals');
592
		}
593
 
594
 
595
	}
19306 naman 596
 
19345 naman 597
	public function target(){
19306 naman 598
		$this->layout = "innerpages";
19374 naman 599
		$user_id = $this->Auth->user('id');
19357 naman 600
 
19306 naman 601
		$cachekey = 'target-'.$user_id;
602
		$getoffer = Cache::read($cachekey,'target');
19333 naman 603
		$current_time = time();
19306 naman 604
		$response = "";
605
		if($getoffer === false){
19357 naman 606
			$offerurl = $this->apihost."getOfferForUser/?user_id=".$user_id;
19306 naman 607
			$response = $this->make_request($offerurl,null);
608
			Cache::write($cachekey , $response ,'target');
609
			if(!empty($response)){
19333 naman 610
 
19670 naman 611
// 								if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){
19306 naman 612
 
19670 naman 613
// 								}
614
// 								else{
615
// 									$response = "";
616
// 									}
19306 naman 617
				}
618
				else{
19333 naman 619
					$response = "";
19306 naman 620
				}
621
		}else{
19333 naman 622
			if(!empty($getoffer)){
623
					$response = $getoffer;
19670 naman 624
// 					if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){
19333 naman 625
 
19670 naman 626
// 					}
627
// 					else{
628
// 						$response = "";
629
// 					}
19333 naman 630
				}
19306 naman 631
		}
632
 
633
		$maxpercentage = 0;
19357 naman 634
 
19306 naman 635
		if(isset($response['target2_cash_back_percetage']) && !empty($response['target2_cash_back_percetage'])){
636
			$maxpercentage = $response['target2_cash_back_percetage'];
637
		}
638
		else{
639
			if(isset($response['target1_cash_back_percetage']) && !empty($response['target1_cash_back_percetage'])){
640
				$maxpercentage = $response['target1_cash_back_percetage'];
641
			}
642
		}
643
 
19357 naman 644
 
645
		$this->loadModel('User');
646
		$user_email = "";
19345 naman 647
 
19374 naman 648
		$user_email = $this->Auth->user('email');
19357 naman 649
		$this->set(compact('response','maxpercentage','user_email'));
19306 naman 650
	}
13532 anikendra 651
/**
652
 * add method
653
 *
654
 * @return void
655
 */
656
	public function add() {
657
		if ($this->request->is('post')) {
658
			$this->Category->create();
659
			if ($this->Category->save($this->request->data)) {
660
				$this->Session->setFlash(__('The category has been saved.'));
661
				return $this->redirect(array('action' => 'index'));
662
			} else {
663
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
664
			}
665
		}
666
	}
667
 
668
/**
669
 * edit method
670
 *
671
 * @throws NotFoundException
672
 * @param string $id
673
 * @return void
674
 */
675
	public function edit($id = null) {
676
		if (!$this->Category->exists($id)) {
677
			throw new NotFoundException(__('Invalid category'));
678
		}
679
		if ($this->request->is(array('post', 'put'))) {
680
			if ($this->Category->save($this->request->data)) {
681
				$this->Session->setFlash(__('The category has been saved.'));
682
				return $this->redirect(array('action' => 'index'));
683
			} else {
684
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
685
			}
686
		} else {
687
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
688
			$this->request->data = $this->Category->find('first', $options);
689
		}
690
	}
691
 
692
/**
693
 * delete method
694
 *
695
 * @throws NotFoundException
696
 * @param string $id
697
 * @return void
698
 */
699
	public function delete($id = null) {
700
		$this->Category->id = $id;
701
		if (!$this->Category->exists()) {
702
			throw new NotFoundException(__('Invalid category'));
703
		}
704
		$this->request->onlyAllow('post', 'delete');
705
		if ($this->Category->delete()) {
706
			$this->Session->setFlash(__('The category has been deleted.'));
707
		} else {
708
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
709
		}
710
		return $this->redirect(array('action' => 'index'));
711
	}
712
 
713
/**
714
 * admin_index method
715
 *
716
 * @return void
717
 */
718
	public function admin_index() {
719
		$this->Category->recursive = 0;
720
		$this->set('categories', $this->Paginator->paginate());
721
	}
722
 
723
/**
724
 * admin_view method
725
 *
726
 * @throws NotFoundException
727
 * @param string $id
728
 * @return void
729
 */
730
	public function admin_view($id = null) {
731
		if (!$this->Category->exists($id)) {
732
			throw new NotFoundException(__('Invalid category'));
733
		}
734
		$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
735
		$this->set('category', $this->Category->find('first', $options));
736
	}
737
 
738
/**
739
 * admin_add method
740
 *
741
 * @return void
742
 */
743
	public function admin_add() {
744
		if ($this->request->is('post')) {
745
			// print_r($this->request->data);die;
746
			$this->Category->create();
747
			if ($this->Category->save($this->request->data)) {
748
				$this->Session->setFlash(__('The category has been saved.'));
749
				return $this->redirect(array('action' => 'index'));
750
			} else {
751
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
752
			}
753
		}
754
		$this->set('parent_id',$this->Category->find('list'));
755
	}
756
 
757
/**
758
 * admin_edit method
759
 *
760
 * @throws NotFoundException
761
 * @param string $id
762
 * @return void
763
 */
764
	public function admin_edit($id = null) {
765
		if (!$this->Category->exists($id)) {
766
			throw new NotFoundException(__('Invalid category'));
767
		}
768
		if ($this->request->is(array('post', 'put'))) {
769
			if ($this->Category->save($this->request->data)) {
770
				$this->Session->setFlash(__('The category has been saved.'));
771
				return $this->redirect(array('action' => 'index'));
772
			} else {
773
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
774
			}
775
		} else {
776
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
777
			$this->request->data = $this->Category->find('first', $options);
778
		}
779
	}
780
 
781
/**
782
 * admin_delete method
783
 *
784
 * @throws NotFoundException
785
 * @param string $id
786
 * @return void
787
 */
788
	public function admin_delete($id = null) {
789
		$this->Category->id = $id;
790
		if (!$this->Category->exists()) {
791
			throw new NotFoundException(__('Invalid category'));
792
		}
793
		$this->request->onlyAllow('post', 'delete');
794
		if ($this->Category->delete()) {
795
			$this->Session->setFlash(__('The category has been deleted.'));
796
		} else {
797
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
798
		}
799
		return $this->redirect(array('action' => 'index'));
19613 naman 800
	}}