Subversion Repositories SmartDukaan

Rev

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