Subversion Repositories SmartDukaan

Rev

Rev 18212 | Rev 18288 | 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');
26
 
13596 anikendra 27
	}
28
 
13532 anikendra 29
/**
30
 * index method
31
 *
32
 * @return void
33
 */
34
	public function index() {
35
		// $this->Category->recursive = 0;
36
		// $this->set('categories', $this->Paginator->paginate());
13541 anikendra 37
		$userId = $this->request->query('user_id');
38
		$this->loadModel('UserCategory');
13689 anikendra 39
		$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);
13541 anikendra 40
		$userCategories = $this->UserCategory->find('all',$options);		
13532 anikendra 41
		$this->response->type('json');
42
		$this->layout = 'ajax';
13541 anikendra 43
		$conditions = array(array('Category.parent_id !='=>0));
44
		if(!empty($userCategories)){
45
			foreach ($userCategories as $key => $value) {
46
				$categoryIds[] = $value['UserCategory']['category_id'];
47
			}
48
			array_push($conditions,array('Category.id'=>$categoryIds));
49
		}
50
		$this->Category->recursive = -1;		
13532 anikendra 51
		$categories = $this->Paginator->paginate(null,$conditions);
52
		$callback = $this->request->query('callback');
53
		$result = array('categories' => $categories);
54
		$this->set(array(
55
		    'result' => $result,
56
		    'callback' => $callback,
57
		    '_serialize' => array('result')
58
		));
59
		$this->render('/Elements/jsonp');
60
	}
61
 
13567 anikendra 62
	public function deals(){
13591 anikendra 63
		$userId = $this->request->query('user_id');
17962 manish.sha 64
		$error = $this->request->query('error');
13591 anikendra 65
		if(isset($userId) && !empty($userId)){
13597 anikendra 66
			$this->loadModel('User');
67
			$dbuser = $this->User->findById($userId);
68
			$this->Auth->login($dbuser['User']);	
13591 anikendra 69
		}
13583 anikendra 70
		$likedDeals = $disLikedDeals = array();
13794 anikendra 71
		// $this->loadModel('Api');
72
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
73
		// $categorydeals = $apideals['products'];
74
		$page = $this->request->query('page');
75
		if(!isset($page)){
76
			$page = 1;
77
		}
78
		$offset = ($page - 1) * $this->limit;
79
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
17683 naman 80
		//debug($url);
13794 anikendra 81
		$deals = $this->make_request($url,null);		
13583 anikendra 82
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
83
		if(!empty($myactions)) {
84
			foreach ($myactions['actions'] as $key => $value) {
85
				if($value['UserAction']['action'] == 'like'){
86
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
87
				}else{
88
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
89
				}
90
			}
91
		}
17962 manish.sha 92
 
93
		$errorstr = '';
94
 
95
		if(isset($error)){
96
			$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
97
		}
13567 anikendra 98
		$rows = sizeof($categorydeals);
99
		if($rows>=1){
100
			$this->set('deals',$categorydeals);
13583 anikendra 101
			$this->set('likedDeals',$likedDeals);
102
			$this->set('disLikedDeals',$disLikedDeals);
17962 manish.sha 103
			$this->set('errorstr',$errorstr);
13567 anikendra 104
			$this->render('categorydeals');
105
		}else{
106
			foreach ($categorydeals as $key => $dealarr) {
107
				foreach ($dealarr as $key => $deal) {
108
					$deals[] = $deal[0];
109
				}				
110
			}
17962 manish.sha 111
			$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));
13567 anikendra 112
		}		
113
	}
114
/*
115
	*
13532 anikendra 116
 * view method
117
 *
118
 * @throws NotFoundException
119
 * @param string $id
120
 * @return void
121
 */
122
	public function view($id = null) {
18206 amit.gupta 123
		$searchableSubCategories = array('20'=>'Tempered Glasses', '19^27'=>'Mobile Covers');
14930 anikendra 124
		$userId = $this->request->query('user_id');
17683 naman 125
 
15378 anikendra 126
		if(isset($userId) && !empty($userId)) {
14930 anikendra 127
			$this->loadModel('User');
128
			$dbuser = $this->User->findById($userId);
129
			$this->Auth->login($dbuser['User']);
16549 anikendra 130
		}				
13583 anikendra 131
		$page = $this->request->query('page');
18063 naman 132
		$searchfor = $this->request->query('searchFor');
133
		// echo "page=>",$page;
17810 manish.sha 134
		$error = $this->request->query('error');
13583 anikendra 135
		if(!isset($page)){
136
			$page = 1;
16549 anikendra 137
		}
138
 
13808 anikendra 139
		$sort = $this->request->query('sort');
140
		$direction = $this->request->query('direction');
18207 amit.gupta 141
		//$filter = $this->request->query('filter');
15044 anikendra 142
		// $brands = $this->request->query('brands');
16549 anikendra 143
		if($id != 2) {
144
			//Fetch deals
145
			$likedDeals = $disLikedDeals = array();
17174 naman 146
			$brandschosen = $_COOKIE['brandschosen'];
17683 naman 147
			$subcategorieschosen = $_COOKIE['subcategorieschosen'];			
17759 naman 148
 
149
			// echo "Cookie val", $_COOKIE['old_id'];
150
			// echo "id val", $id;
17683 naman 151
 
18063 naman 152
			if(!empty($searchfor) || $searchfor != null)
153
			{
154
				unset($brandschosen);
155
				setcookie('brandschosen', null, -1, '/');
156
				unset($subcategorieschosen);
157
				setcookie('subcategorieschosen', null, -1, '/');
158
			}
17759 naman 159
 
18004 naman 160
			if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 161
 
162
 
17174 naman 163
				unset($brandschosen);
17683 naman 164
				// setcookie('brandschosen', 1, time()-1, '/');
165
				// unset($_COOKIE['brandschosen']);
166
    			setcookie('brandschosen', null, -1, '/');
167
				unset($subcategorieschosen);
168
				setcookie('subcategorieschosen', 1, time()-1, '/');
169
 
170
			}		
171
 
18004 naman 172
			if((isset($_COOKIE['brandschosen'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 173
 
174
				unset($brandschosen);
175
				// setcookie('brandschosen', 1, time()-10, '/');
176
				// unset($_COOKIE['brandschosen']);
177
    			setcookie('brandschosen', null, -1, '/');
178
				unset($subcategorieschosen);
179
				setcookie('subcategorieschosen', 1, time()-1, '/');
180
 
16549 anikendra 181
			}
17683 naman 182
 
18004 naman 183
			setcookie('old_cid', $id, -1, '/');
17683 naman 184
 
185
 
186
				if(!empty($brandschosen) && !empty($subcategorieschosen)){
187
					$filter = 'brand|subcategory';
188
				}			
189
				else if(!empty($brandschosen) && empty($subcategorieschosen)){
190
					$filter = 'brand';
191
				}
192
				if(!empty($subcategorieschosen) && empty($brandschosen)){
193
					$filter = 'subcategory';
194
				}
195
 
16549 anikendra 196
			$brands = str_replace(',', '^', $brandschosen);
17683 naman 197
			$subcategories = str_replace(',', '^', $subcategorieschosen);
198
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16549 anikendra 199
			// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
200
			$response = $this->make_request($url,null);
201
			$deals = array();
17683 naman 202
 
203
			$response_count =1;
204
			if($response == '')
205
			{
206
				$response_count = 0;
207
			}
208
			// debug($response_count);
16549 anikendra 209
			if(!empty($response)){
210
				foreach ($response as $key => $value) {
211
					if(!empty($value)){
212
						$deals[] = $value;
213
					}
16098 anikendra 214
				}
215
			}
17683 naman 216
			#print_r($deals);
16549 anikendra 217
			$this->loadModel('Api');
218
			$myactions = $this->Api->getMyActions($this->Auth->User('id'));
219
			if(!empty($myactions)) {
220
				foreach ($myactions['actions'] as $key => $value) {
221
					if($value['UserAction']['action'] == 'like'){
222
						$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
223
					}else{
224
						$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
225
					}
13583 anikendra 226
				}
227
			}
16549 anikendra 228
			$this->loadModel('NotificationRule');
229
			$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));	
230
		    $filterstr = '';
231
			if(isset($filter) && !empty($filter)){
17759 naman 232
 
17683 naman 233
			    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
17695 naman 234
		  	} 
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
 
18212 naman 407
	public function dealdetail($item_id = null){
408
		$this->layout = "innerpages";
18223 naman 409
		$dealinfo = $deal = array();
410
		$likedDeals = $disLikedDeals = array();
411
		$url = $this->mobileapi.'entity/'.$item_id;
412
		$dealinfo = $this->make_request($url,null);
413
		$this->loadModel('Api');
414
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
415
		if(!empty($myactions)) {
416
			foreach ($myactions['actions'] as $key => $value) {
417
				if($value['UserAction']['action'] == 'like'){
418
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
419
				}else{
420
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
421
				}
422
			}
423
		}
424
		$this->set(compact('deal','dealinfo','likedDeals','disLikedDeals'));
18212 naman 425
	}
426
 
18063 naman 427
	public function getdealsforsearchterm($searchterm,$page = null){
428
		$likedDeals = $disLikedDeals = array();
429
		$this->layout = 'ajax';
430
		$page = $this->request->query('page');
431
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 
432
		if(!isset($page)){
433
			$page = 1;
434
			$offset = 0;
435
			$limit=10;
436
		}
437
		else{
438
			$offset = ($page*20) - 30;
439
			$limit = 20;
440
		}
441
		$sort = $this->request->query('sort');
442
		$direction = $this->request->query('direction');
443
 
18115 amit.gupta 444
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategorieschosen;
18063 naman 445
		$response = $this->make_request($url,null);
446
		$deals = array();
447
		if(!empty($response)){
448
			foreach ($response as $key => $value) {
449
				if(!empty($value)){
450
					$deals[] = $value;
451
				}
452
			}
453
		}
18115 amit.gupta 454
 
18063 naman 455
		$this->loadModel('Api');
18115 amit.gupta 456
 
18063 naman 457
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
458
		if(!empty($myactions)) {
459
			foreach ($myactions['actions'] as $key => $value) {
460
				if($value['UserAction']['action'] == 'like'){
461
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
462
				}else{
463
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
464
				}
465
			}
466
		}
467
 
468
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1);
469
 
470
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
471
		if(!empty($deals) && !empty($deals[0])){
472
			$this->render('/Elements/deals');
473
		}else{
474
			$this->render('/Elements/nodeals');
475
		}
476
 
477
 
478
	}
13532 anikendra 479
/**
480
 * add method
481
 *
482
 * @return void
483
 */
484
	public function add() {
485
		if ($this->request->is('post')) {
486
			$this->Category->create();
487
			if ($this->Category->save($this->request->data)) {
488
				$this->Session->setFlash(__('The category has been saved.'));
489
				return $this->redirect(array('action' => 'index'));
490
			} else {
491
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
492
			}
493
		}
494
	}
495
 
496
/**
497
 * edit method
498
 *
499
 * @throws NotFoundException
500
 * @param string $id
501
 * @return void
502
 */
503
	public function edit($id = null) {
504
		if (!$this->Category->exists($id)) {
505
			throw new NotFoundException(__('Invalid category'));
506
		}
507
		if ($this->request->is(array('post', 'put'))) {
508
			if ($this->Category->save($this->request->data)) {
509
				$this->Session->setFlash(__('The category has been saved.'));
510
				return $this->redirect(array('action' => 'index'));
511
			} else {
512
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
513
			}
514
		} else {
515
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
516
			$this->request->data = $this->Category->find('first', $options);
517
		}
518
	}
519
 
520
/**
521
 * delete method
522
 *
523
 * @throws NotFoundException
524
 * @param string $id
525
 * @return void
526
 */
527
	public function delete($id = null) {
528
		$this->Category->id = $id;
529
		if (!$this->Category->exists()) {
530
			throw new NotFoundException(__('Invalid category'));
531
		}
532
		$this->request->onlyAllow('post', 'delete');
533
		if ($this->Category->delete()) {
534
			$this->Session->setFlash(__('The category has been deleted.'));
535
		} else {
536
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
537
		}
538
		return $this->redirect(array('action' => 'index'));
539
	}
540
 
541
/**
542
 * admin_index method
543
 *
544
 * @return void
545
 */
546
	public function admin_index() {
547
		$this->Category->recursive = 0;
548
		$this->set('categories', $this->Paginator->paginate());
549
	}
550
 
551
/**
552
 * admin_view method
553
 *
554
 * @throws NotFoundException
555
 * @param string $id
556
 * @return void
557
 */
558
	public function admin_view($id = null) {
559
		if (!$this->Category->exists($id)) {
560
			throw new NotFoundException(__('Invalid category'));
561
		}
562
		$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
563
		$this->set('category', $this->Category->find('first', $options));
564
	}
565
 
566
/**
567
 * admin_add method
568
 *
569
 * @return void
570
 */
571
	public function admin_add() {
572
		if ($this->request->is('post')) {
573
			// print_r($this->request->data);die;
574
			$this->Category->create();
575
			if ($this->Category->save($this->request->data)) {
576
				$this->Session->setFlash(__('The category has been saved.'));
577
				return $this->redirect(array('action' => 'index'));
578
			} else {
579
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
580
			}
581
		}
582
		$this->set('parent_id',$this->Category->find('list'));
583
	}
584
 
585
/**
586
 * admin_edit method
587
 *
588
 * @throws NotFoundException
589
 * @param string $id
590
 * @return void
591
 */
592
	public function admin_edit($id = null) {
593
		if (!$this->Category->exists($id)) {
594
			throw new NotFoundException(__('Invalid category'));
595
		}
596
		if ($this->request->is(array('post', 'put'))) {
597
			if ($this->Category->save($this->request->data)) {
598
				$this->Session->setFlash(__('The category has been saved.'));
599
				return $this->redirect(array('action' => 'index'));
600
			} else {
601
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
602
			}
603
		} else {
604
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
605
			$this->request->data = $this->Category->find('first', $options);
606
		}
607
	}
608
 
609
/**
610
 * admin_delete method
611
 *
612
 * @throws NotFoundException
613
 * @param string $id
614
 * @return void
615
 */
616
	public function admin_delete($id = null) {
617
		$this->Category->id = $id;
618
		if (!$this->Category->exists()) {
619
			throw new NotFoundException(__('Invalid category'));
620
		}
621
		$this->request->onlyAllow('post', 'delete');
622
		if ($this->Category->delete()) {
623
			$this->Session->setFlash(__('The category has been deleted.'));
624
		} else {
625
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
626
		}
627
		return $this->redirect(array('action' => 'index'));
628
	}}