Subversion Repositories SmartDukaan

Rev

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