Subversion Repositories SmartDukaan

Rev

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