Subversion Repositories SmartDukaan

Rev

Rev 20018 | 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'){
20022 naman 419
			$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=20&offset=0&filterData=priceFilter:0^1000|sourceFilter:4&sort=available_price&direction=1";
20010 naman 420
		}elseif($filtertype == 'exclusive'){
20022 naman 421
// 			$url = $this->apihost."getDealsByType?categoryId=".$id."&offset=0&limit=20&type=".$filtertype;
422
			$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=20&offset=0&filterData=sourceFilter:4";
20010 naman 423
		}
424
 
19904 naman 425
		$response = $this->make_request($url,null);
426
		$deals = array();
427
 
428
		$response_count =1;
429
		if($response == '')
430
		{
431
			$response_count = 0;
432
		}
18063 naman 433
 
19904 naman 434
		if(!empty($response)){
435
			foreach ($response as $key => $value) {
20018 naman 436
// 				debug($value);
20022 naman 437
				if(!empty($value)){
19904 naman 438
					$deals[] = $value;
439
				}
440
			}
441
		}
442
 
443
		$this->loadModel('Api');
444
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
445
		if(!empty($myactions)) {
446
			foreach ($myactions['actions'] as $key => $value) {
447
				if($value['UserAction']['action'] == 'like'){
448
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
449
				}else{
450
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
451
				}
452
			}
453
		}
454
 
455
 
456
		$nexturl = "/categories/getlinkdeals/".$id."?page=".($page+1)."&filtertype=".$filtertype;			
457
		$offerresponse = $this->getuseroffer();
458
 
20012 naman 459
		$this->set(compact('filtertype','offerresponse','response_count','deals','id','likedDeals','disLikedDeals','page','nexturl'));
19904 naman 460
	}
461
 
462
 
463
	public function getlinkdeals($id = null) {
464
 
465
		$likedDeals = $disLikedDeals = array();
466
		$this->layout = 'ajax';
467
		$page = $this->request->query('page');
468
		$filtertype = $this->request->query('filtertype');
20010 naman 469
		$user_id = $this->Auth->User('id');
19904 naman 470
		if(!isset($page)){
471
			$page = 1;
472
		}
473
		$limit = 20;
474
		$offset = ($page - 1)*$limit;
475
 
476
		$likedDeals = $disLikedDeals = array();
20010 naman 477
		if($filtertype == 'below1000'){
20022 naman 478
// 			$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=".$limit."&offset=".$offset."&filterData=priceFilter:0^1000&sort=available_price&direction=1";
479
			$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=".$limit."&offset=".$offset."&filterData=priceFilter:0^1000|sourceFilter:4&sort=available_price&direction=1";
20010 naman 480
		}elseif($filtertype == 'exclusive'){
20022 naman 481
// 			$url = $this->apihost."getDealsByType?categoryId=".$id."&type=".$filtertype."&limit=".$limit."&offset=".$offset;
482
			$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=".$limit."&offset=".$offset."&filterData=sourceFilter:4";
20010 naman 483
		}
484
// 		$url = $this->apihost."getDealsByType?categoryId=".$id."&type=".$filtertype."&limit=".$limit."&offset=".$offset;
19904 naman 485
		$response = $this->make_request($url,null);
486
		$deals = array();
487
		if(!empty($response)){
488
			foreach ($response as $key => $value) {
20022 naman 489
				if(!empty($value)){
19904 naman 490
					$deals[] = $value;
491
				}
492
			}
493
		}
494
 
495
		$this->loadModel('Api');
496
 
497
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
498
		if(!empty($myactions)) {
499
			foreach ($myactions['actions'] as $key => $value) {
500
				if($value['UserAction']['action'] == 'like'){
501
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
502
				}else{
503
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
504
				}
505
			}
506
		}
507
 
508
		$nexturl = "/categories/getlinkdeals/".$id."/?page=".($page+1)."&filtertype=".$filtertype;
509
 
510
		$offerresponse = $this->getuseroffer();
511
 
512
		$this->set(compact('offerresponse','nexturl','deals','id','page','likedDeals','disLikedDeals'));
513
		if(!empty($deals) && !empty($deals[0])){
514
			$this->render('/Elements/deals');
515
		}else{
516
			$this->render('/Elements/nodeals');
517
		}
518
	}
519
 
520
 
18212 naman 521
	public function dealdetail($item_id = null){
19244 amit.gupta 522
		setcookie("fresh", '0', null, '/');
18212 naman 523
		$this->layout = "innerpages";
18223 naman 524
		$dealinfo = $deal = array();
525
		$likedDeals = $disLikedDeals = array();
526
		$url = $this->mobileapi.'entity/'.$item_id;
527
		$dealinfo = $this->make_request($url,null);
528
		$this->loadModel('Api');
529
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
530
		if(!empty($myactions)) {
531
			foreach ($myactions['actions'] as $key => $value) {
532
				if($value['UserAction']['action'] == 'like'){
533
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
534
				}else{
535
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
536
				}
537
			}
538
		}
539
		$this->set(compact('deal','dealinfo','likedDeals','disLikedDeals'));
18212 naman 540
	}
541
 
18288 naman 542
	public function saholicdeal($proid = null){
543
		$likedDeals = $disLikedDeals = array();
544
		$this->layout = 'ajax';
545
		$deal = array();
546
		$url = $this->apihost."getDealById/".$proid;
547
		$deal = $this->make_request($url,null);
548
		$this->loadModel('Api');
549
 
550
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
551
		if(!empty($myactions)) {
552
			foreach ($myactions['actions'] as $key => $value) {
553
				if($value['UserAction']['action'] == 'like'){
554
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
555
				}else{
556
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
557
				}
558
			}
559
		}
560
 
19609 naman 561
		$offerresponse = $this->getuseroffer();
18288 naman 562
 
19609 naman 563
		$this->set(compact('offerresponse','deal','likedDeals','disLikedDeals'));
19327 naman 564
 
18288 naman 565
		$this->render('/Elements/saholicdeal');
566
 
567
 
568
	}
569
 
18063 naman 570
	public function getdealsforsearchterm($searchterm,$page = null){
571
		$likedDeals = $disLikedDeals = array();
572
		$this->layout = 'ajax';
573
		$page = $this->request->query('page');
18390 naman 574
		$subcategories = $this->request->query('subcategories'); 
18063 naman 575
		if(!isset($page)){
576
			$page = 1;
577
			$offset = 0;
578
			$limit=10;
579
		}
580
		else{
581
			$offset = ($page*20) - 30;
582
			$limit = 20;
583
		}
584
		$sort = $this->request->query('sort');
585
		$direction = $this->request->query('direction');
586
 
18390 naman 587
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategories;
18063 naman 588
		$response = $this->make_request($url,null);
589
		$deals = array();
590
		if(!empty($response)){
591
			foreach ($response as $key => $value) {
592
				if(!empty($value)){
593
					$deals[] = $value;
594
				}
595
			}
596
		}
18115 amit.gupta 597
 
18063 naman 598
		$this->loadModel('Api');
18115 amit.gupta 599
 
18063 naman 600
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
601
		if(!empty($myactions)) {
602
			foreach ($myactions['actions'] as $key => $value) {
603
				if($value['UserAction']['action'] == 'like'){
604
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
605
				}else{
606
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
607
				}
608
			}
609
		}
610
 
18390 naman 611
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1).'&subcategories='.$subcategories;
19327 naman 612
 
19609 naman 613
		$offerresponse = $this->getuseroffer(); 
19327 naman 614
 
19609 naman 615
		$this->set(compact('offerresponse','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
18063 naman 616
		if(!empty($deals) && !empty($deals[0])){
617
			$this->render('/Elements/deals');
618
		}else{
619
			$this->render('/Elements/nodeals');
620
		}
621
 
622
 
623
	}
19306 naman 624
 
19345 naman 625
	public function target(){
19306 naman 626
		$this->layout = "innerpages";
19374 naman 627
		$user_id = $this->Auth->user('id');
19357 naman 628
 
19306 naman 629
		$cachekey = 'target-'.$user_id;
630
		$getoffer = Cache::read($cachekey,'target');
19333 naman 631
		$current_time = time();
19306 naman 632
		$response = "";
633
		if($getoffer === false){
19357 naman 634
			$offerurl = $this->apihost."getOfferForUser/?user_id=".$user_id;
19306 naman 635
			$response = $this->make_request($offerurl,null);
636
			Cache::write($cachekey , $response ,'target');
637
			if(!empty($response)){
19333 naman 638
 
19670 naman 639
// 								if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){
19306 naman 640
 
19670 naman 641
// 								}
642
// 								else{
643
// 									$response = "";
644
// 									}
19306 naman 645
				}
646
				else{
19333 naman 647
					$response = "";
19306 naman 648
				}
649
		}else{
19333 naman 650
			if(!empty($getoffer)){
651
					$response = $getoffer;
19670 naman 652
// 					if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){
19333 naman 653
 
19670 naman 654
// 					}
655
// 					else{
656
// 						$response = "";
657
// 					}
19333 naman 658
				}
19306 naman 659
		}
660
 
661
		$maxpercentage = 0;
19357 naman 662
 
19306 naman 663
		if(isset($response['target2_cash_back_percetage']) && !empty($response['target2_cash_back_percetage'])){
664
			$maxpercentage = $response['target2_cash_back_percetage'];
665
		}
666
		else{
667
			if(isset($response['target1_cash_back_percetage']) && !empty($response['target1_cash_back_percetage'])){
668
				$maxpercentage = $response['target1_cash_back_percetage'];
669
			}
670
		}
671
 
19357 naman 672
 
673
		$this->loadModel('User');
674
		$user_email = "";
19345 naman 675
 
19374 naman 676
		$user_email = $this->Auth->user('email');
19357 naman 677
		$this->set(compact('response','maxpercentage','user_email'));
19306 naman 678
	}
13532 anikendra 679
/**
680
 * add method
681
 *
682
 * @return void
683
 */
684
	public function add() {
685
		if ($this->request->is('post')) {
686
			$this->Category->create();
687
			if ($this->Category->save($this->request->data)) {
688
				$this->Session->setFlash(__('The category has been saved.'));
689
				return $this->redirect(array('action' => 'index'));
690
			} else {
691
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
692
			}
693
		}
694
	}
695
 
696
/**
697
 * edit method
698
 *
699
 * @throws NotFoundException
700
 * @param string $id
701
 * @return void
702
 */
703
	public function edit($id = null) {
704
		if (!$this->Category->exists($id)) {
705
			throw new NotFoundException(__('Invalid category'));
706
		}
707
		if ($this->request->is(array('post', 'put'))) {
708
			if ($this->Category->save($this->request->data)) {
709
				$this->Session->setFlash(__('The category has been saved.'));
710
				return $this->redirect(array('action' => 'index'));
711
			} else {
712
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
713
			}
714
		} else {
715
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
716
			$this->request->data = $this->Category->find('first', $options);
717
		}
718
	}
719
 
720
/**
721
 * delete method
722
 *
723
 * @throws NotFoundException
724
 * @param string $id
725
 * @return void
726
 */
727
	public function delete($id = null) {
728
		$this->Category->id = $id;
729
		if (!$this->Category->exists()) {
730
			throw new NotFoundException(__('Invalid category'));
731
		}
732
		$this->request->onlyAllow('post', 'delete');
733
		if ($this->Category->delete()) {
734
			$this->Session->setFlash(__('The category has been deleted.'));
735
		} else {
736
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
737
		}
738
		return $this->redirect(array('action' => 'index'));
739
	}
740
 
741
/**
742
 * admin_index method
743
 *
744
 * @return void
745
 */
746
	public function admin_index() {
747
		$this->Category->recursive = 0;
748
		$this->set('categories', $this->Paginator->paginate());
749
	}
750
 
751
/**
752
 * admin_view method
753
 *
754
 * @throws NotFoundException
755
 * @param string $id
756
 * @return void
757
 */
758
	public function admin_view($id = null) {
759
		if (!$this->Category->exists($id)) {
760
			throw new NotFoundException(__('Invalid category'));
761
		}
762
		$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
763
		$this->set('category', $this->Category->find('first', $options));
764
	}
765
 
766
/**
767
 * admin_add method
768
 *
769
 * @return void
770
 */
771
	public function admin_add() {
772
		if ($this->request->is('post')) {
773
			// print_r($this->request->data);die;
774
			$this->Category->create();
775
			if ($this->Category->save($this->request->data)) {
776
				$this->Session->setFlash(__('The category has been saved.'));
777
				return $this->redirect(array('action' => 'index'));
778
			} else {
779
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
780
			}
781
		}
782
		$this->set('parent_id',$this->Category->find('list'));
783
	}
784
 
785
/**
786
 * admin_edit method
787
 *
788
 * @throws NotFoundException
789
 * @param string $id
790
 * @return void
791
 */
792
	public function admin_edit($id = null) {
793
		if (!$this->Category->exists($id)) {
794
			throw new NotFoundException(__('Invalid category'));
795
		}
796
		if ($this->request->is(array('post', 'put'))) {
797
			if ($this->Category->save($this->request->data)) {
798
				$this->Session->setFlash(__('The category has been saved.'));
799
				return $this->redirect(array('action' => 'index'));
800
			} else {
801
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
802
			}
803
		} else {
804
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
805
			$this->request->data = $this->Category->find('first', $options);
806
		}
807
	}
808
 
809
/**
810
 * admin_delete method
811
 *
812
 * @throws NotFoundException
813
 * @param string $id
814
 * @return void
815
 */
816
	public function admin_delete($id = null) {
817
		$this->Category->id = $id;
818
		if (!$this->Category->exists()) {
819
			throw new NotFoundException(__('Invalid category'));
820
		}
821
		$this->request->onlyAllow('post', 'delete');
822
		if ($this->Category->delete()) {
823
			$this->Session->setFlash(__('The category has been deleted.'));
824
		} else {
825
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
826
		}
827
		return $this->redirect(array('action' => 'index'));
19613 naman 828
	}}