Subversion Repositories SmartDukaan

Rev

Rev 18184 | Rev 18206 | 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');
13596 anikendra 25
	}
26
 
13532 anikendra 27
/**
28
 * index method
29
 *
30
 * @return void
31
 */
32
	public function index() {
33
		// $this->Category->recursive = 0;
34
		// $this->set('categories', $this->Paginator->paginate());
13541 anikendra 35
		$userId = $this->request->query('user_id');
36
		$this->loadModel('UserCategory');
13689 anikendra 37
		$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);
13541 anikendra 38
		$userCategories = $this->UserCategory->find('all',$options);		
13532 anikendra 39
		$this->response->type('json');
40
		$this->layout = 'ajax';
13541 anikendra 41
		$conditions = array(array('Category.parent_id !='=>0));
42
		if(!empty($userCategories)){
43
			foreach ($userCategories as $key => $value) {
44
				$categoryIds[] = $value['UserCategory']['category_id'];
45
			}
46
			array_push($conditions,array('Category.id'=>$categoryIds));
47
		}
48
		$this->Category->recursive = -1;		
13532 anikendra 49
		$categories = $this->Paginator->paginate(null,$conditions);
50
		$callback = $this->request->query('callback');
51
		$result = array('categories' => $categories);
52
		$this->set(array(
53
		    'result' => $result,
54
		    'callback' => $callback,
55
		    '_serialize' => array('result')
56
		));
57
		$this->render('/Elements/jsonp');
58
	}
59
 
13567 anikendra 60
	public function deals(){
13591 anikendra 61
		$userId = $this->request->query('user_id');
17962 manish.sha 62
		$error = $this->request->query('error');
13591 anikendra 63
		if(isset($userId) && !empty($userId)){
13597 anikendra 64
			$this->loadModel('User');
65
			$dbuser = $this->User->findById($userId);
66
			$this->Auth->login($dbuser['User']);	
13591 anikendra 67
		}
13583 anikendra 68
		$likedDeals = $disLikedDeals = array();
13794 anikendra 69
		// $this->loadModel('Api');
70
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
71
		// $categorydeals = $apideals['products'];
72
		$page = $this->request->query('page');
73
		if(!isset($page)){
74
			$page = 1;
75
		}
76
		$offset = ($page - 1) * $this->limit;
77
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
17683 naman 78
		//debug($url);
13794 anikendra 79
		$deals = $this->make_request($url,null);		
13583 anikendra 80
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
81
		if(!empty($myactions)) {
82
			foreach ($myactions['actions'] as $key => $value) {
83
				if($value['UserAction']['action'] == 'like'){
84
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
85
				}else{
86
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
87
				}
88
			}
89
		}
17962 manish.sha 90
 
91
		$errorstr = '';
92
 
93
		if(isset($error)){
94
			$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
95
		}
13567 anikendra 96
		$rows = sizeof($categorydeals);
97
		if($rows>=1){
98
			$this->set('deals',$categorydeals);
13583 anikendra 99
			$this->set('likedDeals',$likedDeals);
100
			$this->set('disLikedDeals',$disLikedDeals);
17962 manish.sha 101
			$this->set('errorstr',$errorstr);
13567 anikendra 102
			$this->render('categorydeals');
103
		}else{
104
			foreach ($categorydeals as $key => $dealarr) {
105
				foreach ($dealarr as $key => $deal) {
106
					$deals[] = $deal[0];
107
				}				
108
			}
17962 manish.sha 109
			$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));
13567 anikendra 110
		}		
111
	}
112
/*
113
	*
13532 anikendra 114
 * view method
115
 *
116
 * @throws NotFoundException
117
 * @param string $id
118
 * @return void
119
 */
120
	public function view($id = null) {
18191 amit.gupta 121
		$searchableSubCategories = array('20'=>'Tempered Glass', '19^27'=>'Mobile Covers');
14930 anikendra 122
		$userId = $this->request->query('user_id');
17683 naman 123
 
15378 anikendra 124
		if(isset($userId) && !empty($userId)) {
14930 anikendra 125
			$this->loadModel('User');
126
			$dbuser = $this->User->findById($userId);
127
			$this->Auth->login($dbuser['User']);
16549 anikendra 128
		}				
13583 anikendra 129
		$page = $this->request->query('page');
18063 naman 130
		$searchfor = $this->request->query('searchFor');
131
		// echo "page=>",$page;
17810 manish.sha 132
		$error = $this->request->query('error');
13583 anikendra 133
		if(!isset($page)){
134
			$page = 1;
16549 anikendra 135
		}
136
 
13808 anikendra 137
		$sort = $this->request->query('sort');
138
		$direction = $this->request->query('direction');
18191 amit.gupta 139
		$filter = $this->request->query('filter');
15044 anikendra 140
		// $brands = $this->request->query('brands');
16549 anikendra 141
		if($id != 2) {
142
			//Fetch deals
143
			$likedDeals = $disLikedDeals = array();
17174 naman 144
			$brandschosen = $_COOKIE['brandschosen'];
17683 naman 145
			$subcategorieschosen = $_COOKIE['subcategorieschosen'];			
17759 naman 146
 
147
			// echo "Cookie val", $_COOKIE['old_id'];
148
			// echo "id val", $id;
17683 naman 149
 
18063 naman 150
			if(!empty($searchfor) || $searchfor != null)
151
			{
152
				unset($brandschosen);
153
				setcookie('brandschosen', null, -1, '/');
154
				unset($subcategorieschosen);
155
				setcookie('subcategorieschosen', null, -1, '/');
156
			}
17759 naman 157
 
18004 naman 158
			if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 159
 
160
 
17174 naman 161
				unset($brandschosen);
17683 naman 162
				// setcookie('brandschosen', 1, time()-1, '/');
163
				// unset($_COOKIE['brandschosen']);
164
    			setcookie('brandschosen', null, -1, '/');
165
				unset($subcategorieschosen);
166
				setcookie('subcategorieschosen', 1, time()-1, '/');
167
 
168
			}		
169
 
18004 naman 170
			if((isset($_COOKIE['brandschosen'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 171
 
172
				unset($brandschosen);
173
				// setcookie('brandschosen', 1, time()-10, '/');
174
				// unset($_COOKIE['brandschosen']);
175
    			setcookie('brandschosen', null, -1, '/');
176
				unset($subcategorieschosen);
177
				setcookie('subcategorieschosen', 1, time()-1, '/');
178
 
16549 anikendra 179
			}
17683 naman 180
 
18004 naman 181
			setcookie('old_cid', $id, -1, '/');
17683 naman 182
 
183
 
184
				if(!empty($brandschosen) && !empty($subcategorieschosen)){
185
					$filter = 'brand|subcategory';
186
				}			
187
				else if(!empty($brandschosen) && empty($subcategorieschosen)){
188
					$filter = 'brand';
189
				}
190
				if(!empty($subcategorieschosen) && empty($brandschosen)){
191
					$filter = 'subcategory';
192
				}
193
 
16549 anikendra 194
			$brands = str_replace(',', '^', $brandschosen);
17683 naman 195
			$subcategories = str_replace(',', '^', $subcategorieschosen);
196
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16549 anikendra 197
			// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
198
			$response = $this->make_request($url,null);
199
			$deals = array();
17683 naman 200
 
201
			$response_count =1;
202
			if($response == '')
203
			{
204
				$response_count = 0;
205
			}
206
			// debug($response_count);
16549 anikendra 207
			if(!empty($response)){
208
				foreach ($response as $key => $value) {
209
					if(!empty($value)){
210
						$deals[] = $value;
211
					}
16098 anikendra 212
				}
213
			}
17683 naman 214
			#print_r($deals);
16549 anikendra 215
			$this->loadModel('Api');
216
			$myactions = $this->Api->getMyActions($this->Auth->User('id'));
217
			if(!empty($myactions)) {
218
				foreach ($myactions['actions'] as $key => $value) {
219
					if($value['UserAction']['action'] == 'like'){
220
						$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
221
					}else{
222
						$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
223
					}
13583 anikendra 224
				}
225
			}
16549 anikendra 226
			$this->loadModel('NotificationRule');
227
			$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));	
228
		    $filterstr = '';
229
			if(isset($filter) && !empty($filter)){
17759 naman 230
 
17683 naman 231
			    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
17695 naman 232
		  	} 
233
 
17759 naman 234
 
17695 naman 235
		  	$get_url = "'".$_SERVER['REQUEST_URI']."'";
236
		  	$urlArray = explode('=',$_SERVER['REQUEST_URI']);
237
		  	$last = $urlArray[sizeof($urlArray)-1];
238
 
17759 naman 239
		  	// <Code for url used after scrolling...>
17695 naman 240
		  	if(!isset($filter) && empty($filter)){
241
		  		if (strpos($get_url,'filter=brand&brands') !== false)
242
		  		{
243
		  			$filterstr= "&filter=brand&brands=".$last;
244
		  		}
245
		  		if (strpos($get_url,'filter=subcategory&subcategories') !== false)
246
		  		{
247
		  			$filterstr= "&filter=subcategory&subcategories=".$last;
248
		  		}
249
 
17759 naman 250
		  	}
251
 
252
 
253
			if(!empty($subcategorieschosen) && isset($subcategorieschosen) && empty($brandschosen) && !isset($brandschosen)){	
254
					$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;				
255
			}
17810 manish.sha 256
 
257
			$errorstr = '';
258
 
259
			if(isset($error)){
260
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
261
			}
17759 naman 262
 
18063 naman 263
 
264
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
18115 amit.gupta 265
			$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen','subcategories','subcategorieschosen','errorstr','nexturl','searchfor', 'searchableSubCategories'));
16549 anikendra 266
		}else{
16583 anikendra 267
			//Check for apk support of sharing
268
			$sharable = 0;
269
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
270
				$sharable = 1;
17183 anikendra 271
			}			
16704 anikendra 272
			$url = $this->apihost."appOffers/1";
273
			$appOffers = $this->make_request($url,null);
274
			$this->set(compact('page','id','sharable','appOffers'));
16549 anikendra 275
			$this->render('viewapps');
13583 anikendra 276
		}
13532 anikendra 277
	}
278
 
16549 anikendra 279
	public function getapps($id=null){
280
		$this->layout = 'ajax';
281
		$page = $this->request->query('page');
282
		if(!isset($page)){
283
			$page = 1;
284
		}
285
		$this->loadModel('AppOffer');
286
		$this->AppOffer->recursive = -1;
287
		$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
288
		$this->Paginator->settings = $options;
289
		try{
290
			$appOffers = $this->Paginator->paginate('AppOffer');
291
		} catch (NotFoundException $e) {
292
	        //get current page
293
	        $page = $this->request->params['named']['page'];
294
	     	$appOffers = array();   
295
		}
296
		debug($appOffers);		
297
		if(!empty($appOffers)){
298
			$this->set(compact('page','id','appOffers'));
299
			$this->render('/Elements/appoffers');
300
		}else{
301
			$this->render('/Elements/nooffers');
302
		}		
303
	}
304
 
13579 anikendra 305
	public function getdeals($id = null) {
17695 naman 306
 
13808 anikendra 307
		$this->log('getdeal id '.$id,'api');
13583 anikendra 308
		$likedDeals = $disLikedDeals = array();
13579 anikendra 309
		$this->layout = 'ajax';
310
		$page = $this->request->query('page');
311
		if(!isset($page)){
312
			$page = 1;
313
		}
13808 anikendra 314
		$sort = $this->request->query('sort');
315
		$direction = $this->request->query('direction');
15044 anikendra 316
		// $filter = $this->request->query('filter');
317
		// $brands = $this->request->query('brands');
17759 naman 318
		$brandschosen = $_COOKIE['brandschosen'];	 
319
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 	
320
 
321
		// Replace with the below content
322
		// if(!empty($brandschosen)){
323
		// 	$filter = 'brand';
324
		// }
325
 
326
		//I have replaced the above content
327
		if(!empty($brandschosen) && !empty($subcategorieschosen)){
328
			$filter = 'brand|subcategory';
329
		}			
330
		else if(!empty($brandschosen) && empty($subcategorieschosen)){
15044 anikendra 331
			$filter = 'brand';
332
		}
17759 naman 333
		if(!empty($subcategorieschosen) && empty($brandschosen)){
334
			$filter = 'subcategory';
335
		}
336
		//Replaced end
337
 
15044 anikendra 338
		$brands = str_replace(',', '^', $brandschosen);
17759 naman 339
		$subcategories = str_replace(',', '^', $subcategorieschosen);
340
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16098 anikendra 341
		$response = $this->make_request($url,null);
342
		$deals = array();
343
		if(!empty($response)){
344
			foreach ($response as $key => $value) {
345
				if(!empty($value)){
346
					$deals[] = $value;
347
				}
348
			}
349
		}
13794 anikendra 350
		// if (!$this->Category->exists($id)) {
351
			// throw new NotFoundException(__('Invalid category'));
352
		// }
13579 anikendra 353
		$this->loadModel('Api');
13794 anikendra 354
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
355
		// $deals = $apideals['products'];
13583 anikendra 356
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
357
		if(!empty($myactions)) {
358
			foreach ($myactions['actions'] as $key => $value) {
359
				if($value['UserAction']['action'] == 'like'){
360
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
361
				}else{
362
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
363
				}
364
			}
365
		}
15026 anikendra 366
		$filterstr = '';
17695 naman 367
 
368
		$get_url = "'".$_SERVER['REQUEST_URI']."'";
369
		$urlArray = explode('=',$_SERVER['REQUEST_URI']);
370
		$last = $urlArray[sizeof($urlArray)-1];
371
 
372
		if(!isset($filter) && empty($filter)){
373
			if (strpos($get_url,'filter=brand&brands') !== false)
374
			{
375
				$filterstr= "&filter=brand&brands=".$last;
376
			}
377
			if (strpos($get_url,'filter=subcategory&subcategories') !== false)
378
			{
379
				$filterstr= "&filter=subcategory&subcategories=".$last;
380
			}
381
 
382
		} 	  	
383
 
15026 anikendra 384
		if(isset($filter) && !empty($filter)){
17759 naman 385
		    // $filterstr = '&filter='.$filter.'&brands='.$brands;
386
		    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
15026 anikendra 387
	  	} 
17759 naman 388
 
389
	  	if(!empty($subcategorieschosen) && isset($subcategorieschosen)&& empty($brandschosen) && !isset($brandschosen)){
390
 
391
	  			$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
392
	  	}
393
 
18063 naman 394
	  	$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
17759 naman 395
 
18063 naman 396
		$this->set(compact('nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
16098 anikendra 397
		if(!empty($deals) && !empty($deals[0])){
15026 anikendra 398
			$this->render('/Elements/deals');
399
		}else{
400
			$this->render('/Elements/nodeals');
401
		}
17695 naman 402
 
403
 
404
 
13579 anikendra 405
	}
18063 naman 406
 
407
 
408
	public function getdealsforsearchterm($searchterm,$page = null){
409
		$likedDeals = $disLikedDeals = array();
410
		$this->layout = 'ajax';
411
		$page = $this->request->query('page');
412
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 
413
		if(!isset($page)){
414
			$page = 1;
415
			$offset = 0;
416
			$limit=10;
417
		}
418
		else{
419
			$offset = ($page*20) - 30;
420
			$limit = 20;
421
		}
422
		$sort = $this->request->query('sort');
423
		$direction = $this->request->query('direction');
424
 
18115 amit.gupta 425
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategorieschosen;
18063 naman 426
		$response = $this->make_request($url,null);
427
		$deals = array();
428
		if(!empty($response)){
429
			foreach ($response as $key => $value) {
430
				if(!empty($value)){
431
					$deals[] = $value;
432
				}
433
			}
434
		}
18115 amit.gupta 435
 
18063 naman 436
		$this->loadModel('Api');
18115 amit.gupta 437
 
18063 naman 438
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
439
		if(!empty($myactions)) {
440
			foreach ($myactions['actions'] as $key => $value) {
441
				if($value['UserAction']['action'] == 'like'){
442
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
443
				}else{
444
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
445
				}
446
			}
447
		}
448
 
449
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1);
450
 
451
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
452
		if(!empty($deals) && !empty($deals[0])){
453
			$this->render('/Elements/deals');
454
		}else{
455
			$this->render('/Elements/nodeals');
456
		}
457
 
458
 
459
	}
13532 anikendra 460
/**
461
 * add method
462
 *
463
 * @return void
464
 */
465
	public function add() {
466
		if ($this->request->is('post')) {
467
			$this->Category->create();
468
			if ($this->Category->save($this->request->data)) {
469
				$this->Session->setFlash(__('The category has been saved.'));
470
				return $this->redirect(array('action' => 'index'));
471
			} else {
472
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
473
			}
474
		}
475
	}
476
 
477
/**
478
 * edit method
479
 *
480
 * @throws NotFoundException
481
 * @param string $id
482
 * @return void
483
 */
484
	public function edit($id = null) {
485
		if (!$this->Category->exists($id)) {
486
			throw new NotFoundException(__('Invalid category'));
487
		}
488
		if ($this->request->is(array('post', 'put'))) {
489
			if ($this->Category->save($this->request->data)) {
490
				$this->Session->setFlash(__('The category has been saved.'));
491
				return $this->redirect(array('action' => 'index'));
492
			} else {
493
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
494
			}
495
		} else {
496
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
497
			$this->request->data = $this->Category->find('first', $options);
498
		}
499
	}
500
 
501
/**
502
 * delete method
503
 *
504
 * @throws NotFoundException
505
 * @param string $id
506
 * @return void
507
 */
508
	public function delete($id = null) {
509
		$this->Category->id = $id;
510
		if (!$this->Category->exists()) {
511
			throw new NotFoundException(__('Invalid category'));
512
		}
513
		$this->request->onlyAllow('post', 'delete');
514
		if ($this->Category->delete()) {
515
			$this->Session->setFlash(__('The category has been deleted.'));
516
		} else {
517
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
518
		}
519
		return $this->redirect(array('action' => 'index'));
520
	}
521
 
522
/**
523
 * admin_index method
524
 *
525
 * @return void
526
 */
527
	public function admin_index() {
528
		$this->Category->recursive = 0;
529
		$this->set('categories', $this->Paginator->paginate());
530
	}
531
 
532
/**
533
 * admin_view method
534
 *
535
 * @throws NotFoundException
536
 * @param string $id
537
 * @return void
538
 */
539
	public function admin_view($id = null) {
540
		if (!$this->Category->exists($id)) {
541
			throw new NotFoundException(__('Invalid category'));
542
		}
543
		$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
544
		$this->set('category', $this->Category->find('first', $options));
545
	}
546
 
547
/**
548
 * admin_add method
549
 *
550
 * @return void
551
 */
552
	public function admin_add() {
553
		if ($this->request->is('post')) {
554
			// print_r($this->request->data);die;
555
			$this->Category->create();
556
			if ($this->Category->save($this->request->data)) {
557
				$this->Session->setFlash(__('The category has been saved.'));
558
				return $this->redirect(array('action' => 'index'));
559
			} else {
560
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
561
			}
562
		}
563
		$this->set('parent_id',$this->Category->find('list'));
564
	}
565
 
566
/**
567
 * admin_edit method
568
 *
569
 * @throws NotFoundException
570
 * @param string $id
571
 * @return void
572
 */
573
	public function admin_edit($id = null) {
574
		if (!$this->Category->exists($id)) {
575
			throw new NotFoundException(__('Invalid category'));
576
		}
577
		if ($this->request->is(array('post', 'put'))) {
578
			if ($this->Category->save($this->request->data)) {
579
				$this->Session->setFlash(__('The category has been saved.'));
580
				return $this->redirect(array('action' => 'index'));
581
			} else {
582
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
583
			}
584
		} else {
585
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
586
			$this->request->data = $this->Category->find('first', $options);
587
		}
588
	}
589
 
590
/**
591
 * admin_delete method
592
 *
593
 * @throws NotFoundException
594
 * @param string $id
595
 * @return void
596
 */
597
	public function admin_delete($id = null) {
598
		$this->Category->id = $id;
599
		if (!$this->Category->exists()) {
600
			throw new NotFoundException(__('Invalid category'));
601
		}
602
		$this->request->onlyAllow('post', 'delete');
603
		if ($this->Category->delete()) {
604
			$this->Session->setFlash(__('The category has been deleted.'));
605
		} else {
606
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
607
		}
608
		return $this->redirect(array('action' => 'index'));
609
	}}