Subversion Repositories SmartDukaan

Rev

Rev 14098 | Rev 14561 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13646 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalskudiscounts Controller
5
 *
6
 * @property Exceptionalskudiscount $Exceptionalskudiscount
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ExceptionalskudiscountsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public $apihost;
19
 
20
	public function beforeFilter() {
21
		parent::beforeFilter();
13946 anikendra 22
		//Configure::load('live');
13646 anikendra 23
		$this->apihost = Configure::read('pythonapihost');
24
	}
25
/**
26
 * admin_index method
27
 *
28
 * @return void
29
 */
30
	public function admin_index() {
14098 anikendra 31
		$page = $this->request->query('page');
32
		if(!isset($page)){
33
			$page = 1;
34
		}
35
		$limit = Configure::read('admindashboardlimit');
36
		$offset = ($page - 1)*$limit;
37
		$url = $this->apihost."discountInfo/getAllExceptionalSkuDiscount/?limit=$limit&offset=$offset";
13646 anikendra 38
		$response = $this->make_request($url,null);
39
		$this->set('exceptionalskudiscounts', $response);
14098 anikendra 40
		$this->set('page',$page);
13646 anikendra 41
	}
42
 
43
/**
44
 * admin_view method
45
 *
46
 * @throws NotFoundException
47
 * @param string $id
48
 * @return void
49
 */
14517 anikendra 50
	public function admin_search() {
51
		$type = $this->request->query('type');
52
		$search = $this->request->query('search');				
53
		$url = $this->apihost."Catalog/searchProducts/?class=SkuDiscountInfo&$type=$search";
54
		$response = $this->make_request($url,null);
55
		$this->set('exceptionalskudiscounts', $response);
56
		$this->set('page',1);
57
		$this->render('admin_index');
13646 anikendra 58
	}
59
 
60
/**
61
 * admin_add method
62
 *
63
 * @return void
64
 */
65
	public function admin_add() {
66
		if ($this->request->is('post')) {
67
			$url = $this->apihost."discountInfo/addExceptionalSkuDiscount";
68
			$jsonVar = json_encode($this->request->data['Exceptionalskudiscount'], JSON_NUMERIC_CHECK );
69
			$response = $this->make_request($url,$jsonVar);
70
			if (key($response)) {
71
				$this->Session->setFlash(current($response));
72
				return $this->redirect(array('action' => 'index'));
73
			} else {
74
				$this->Session->setFlash(current($response));
75
			}	
76
		}
77
	}
78
 
79
/**
80
 * admin_edit method
81
 *
82
 * @throws NotFoundException
83
 * @param string $id
84
 * @return void
85
 */
86
	public function admin_edit($id = null) {
87
		if (!$this->Exceptionalskudiscount->exists($id)) {
88
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
89
		}
90
		if ($this->request->is(array('post', 'put'))) {
91
			if ($this->Exceptionalskudiscount->save($this->request->data)) {
92
				$this->Session->setFlash(__('The exceptionalskudiscount has been saved.'));
93
				return $this->redirect(array('action' => 'index'));
94
			} else {
95
				$this->Session->setFlash(__('The exceptionalskudiscount could not be saved. Please, try again.'));
96
			}
97
		} else {
98
			$options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
99
			$this->request->data = $this->Exceptionalskudiscount->find('first', $options);
100
		}
101
	}
102
 
103
/**
104
 * admin_delete method
105
 *
106
 * @throws NotFoundException
107
 * @param string $id
108
 * @return void
109
 */
14517 anikendra 110
	public function admin_delete($id = null) {		
111
		// $this->request->onlyAllow('post', 'delete');
112
		if ($this->remove($id,'SkuDiscountInfo')) {
113
			$this->Session->setFlash(__('The negative deal has been deleted.'));
13646 anikendra 114
		} else {
14517 anikendra 115
			$this->Session->setFlash(__('The negative could not be deleted. Please, try again.'));
13646 anikendra 116
		}
117
		return $this->redirect(array('action' => 'index'));
14517 anikendra 118
	}
119
}