Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13579 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * CategoryDiscounts Controller
5
 *
6
 * @property CategoryDiscount $CategoryDiscount
7
 * @property PaginatorComponent $Paginator
8
 */
9
class CategoryDiscountsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
13633 anikendra 17
	public $apihost;
13579 anikendra 18
 
13633 anikendra 19
	public function beforeFilter() {
20
		parent::beforeFilter();
21
		$this->loadModel('Pythonapi');
22
		Configure::load('live');
23
		$this->apihost = Configure::read('pythonapihost');
24
	}
13579 anikendra 25
/**
26
 * index method
27
 *
28
 * @return void
29
 */
30
	public function index() {
31
		$this->CategoryDiscount->recursive = 0;
32
		$this->set('categoryDiscounts', $this->Paginator->paginate());
33
	}
34
 
35
/**
36
 * view method
37
 *
38
 * @throws NotFoundException
39
 * @param string $id
40
 * @return void
41
 */
42
	public function view($id = null) {
43
		if (!$this->CategoryDiscount->exists($id)) {
44
			throw new NotFoundException(__('Invalid category discount'));
45
		}
46
		$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));
47
		$this->set('categoryDiscount', $this->CategoryDiscount->find('first', $options));
48
	}
49
 
50
/**
51
 * add method
52
 *
53
 * @return void
54
 */
55
	public function add() {
56
		if ($this->request->is('post')) {
57
			$this->CategoryDiscount->create();
58
			if ($this->CategoryDiscount->save($this->request->data)) {
59
				$this->Session->setFlash(__('The category discount has been saved.'));
60
				return $this->redirect(array('action' => 'index'));
61
			} else {
62
				$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));
63
			}
64
		}
65
		$categories = $this->CategoryDiscount->Category->find('list');
66
		$this->set(compact('categories'));
67
	}
68
 
69
/**
70
 * edit method
71
 *
72
 * @throws NotFoundException
73
 * @param string $id
74
 * @return void
75
 */
76
	public function edit($id = null) {
77
		if (!$this->CategoryDiscount->exists($id)) {
78
			throw new NotFoundException(__('Invalid category discount'));
79
		}
80
		if ($this->request->is(array('post', 'put'))) {
81
			if ($this->CategoryDiscount->save($this->request->data)) {
82
				$this->Session->setFlash(__('The category discount has been saved.'));
83
				return $this->redirect(array('action' => 'index'));
84
			} else {
85
				$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));
86
			}
87
		} else {
88
			$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));
89
			$this->request->data = $this->CategoryDiscount->find('first', $options);
90
		}
91
		$categories = $this->CategoryDiscount->Category->find('list');
92
		$this->set(compact('categories'));
93
	}
94
 
95
/**
96
 * delete method
97
 *
98
 * @throws NotFoundException
99
 * @param string $id
100
 * @return void
101
 */
102
	public function delete($id = null) {
103
		$this->CategoryDiscount->id = $id;
104
		if (!$this->CategoryDiscount->exists()) {
105
			throw new NotFoundException(__('Invalid category discount'));
106
		}
107
		$this->request->onlyAllow('post', 'delete');
108
		if ($this->CategoryDiscount->delete()) {
109
			$this->Session->setFlash(__('The category discount has been deleted.'));
110
		} else {
111
			$this->Session->setFlash(__('The category discount could not be deleted. Please, try again.'));
112
		}
113
		return $this->redirect(array('action' => 'index'));
114
	}
115
 
116
/**
117
 * admin_index method
118
 *
119
 * @return void
120
 */
121
	public function admin_index() {
13633 anikendra 122
		$url = $this->apihost."discountInfo/getAllCategoryDiscount";
123
		$response = $this->make_request($url,$jsonVar);
124
		$this->set('categoryDiscounts',$response);
125
		$this->loadModel('Category');
126
		$categories = $this->Category->find('list');
127
		$this->set('categories',$categories);
13579 anikendra 128
	}
129
 
130
/**
131
 * admin_view method
132
 *
133
 * @throws NotFoundException
134
 * @param string $id
135
 * @return void
136
 */
137
	public function admin_view($id = null) {
138
		if (!$this->CategoryDiscount->exists($id)) {
139
			throw new NotFoundException(__('Invalid category discount'));
140
		}
141
		$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));
142
		$this->set('categoryDiscount', $this->CategoryDiscount->find('first', $options));
143
	}
144
 
145
/**
146
 * admin_add method
147
 *
148
 * @return void
149
 */
13633 anikendra 150
	public function admin_new() {		
13579 anikendra 151
		if ($this->request->is('post')) {
13633 anikendra 152
			$url = $this->apihost."discountInfo/addCategoryDiscount";
153
			$jsonVar = json_encode($this->request->data['CategoryDiscount'], JSON_NUMERIC_CHECK );
154
			$response = $this->make_request($url,$jsonVar);
155
			if (key($response)) {
156
				$this->Session->setFlash(current($response));
157
				return $this->redirect(array('action' => 'index'));
158
			} else {
159
				$this->Session->setFlash(current($response));
13579 anikendra 160
			}
161
		}
162
		$this->loadModel('Brand');
163
		$allbrands = $this->Brand->find('list');
164
		foreach ($allbrands as $key => $value) {
165
			$brands[$value] = $value;
166
		}
13633 anikendra 167
		$this->loadModel('Category');
168
		$categories = $this->Category->find('list',array('conditions'=>array('parent_id !='=>0)));
13579 anikendra 169
		$this->set(compact('categories','brands'));
170
	}
171
 
172
/**
173
 * admin_edit method
174
 *
175
 * @throws NotFoundException
176
 * @param string $id
177
 * @return void
178
 */
179
	public function admin_edit($id = null) {
180
		if (!$this->CategoryDiscount->exists($id)) {
181
			throw new NotFoundException(__('Invalid category discount'));
182
		}
183
		if ($this->request->is(array('post', 'put'))) {
184
			if ($this->CategoryDiscount->save($this->request->data)) {
185
				$this->Session->setFlash(__('The category discount has been saved.'));
186
				return $this->redirect(array('action' => 'index'));
187
			} else {
188
				$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));
189
			}
190
		} else {
191
			$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));
192
			$this->request->data = $this->CategoryDiscount->find('first', $options);
193
		}
194
		$categories = $this->CategoryDiscount->Category->find('list');
195
		$this->set(compact('categories'));
196
	}
197
 
198
/**
199
 * admin_delete method
200
 *
201
 * @throws NotFoundException
202
 * @param string $id
203
 * @return void
204
 */
205
	public function admin_delete($id = null) {
206
		$this->CategoryDiscount->id = $id;
207
		if (!$this->CategoryDiscount->exists()) {
208
			throw new NotFoundException(__('Invalid category discount'));
209
		}
210
		$this->request->onlyAllow('post', 'delete');
211
		if ($this->CategoryDiscount->delete()) {
212
			$this->Session->setFlash(__('The category discount has been deleted.'));
213
		} else {
214
			$this->Session->setFlash(__('The category discount could not be deleted. Please, try again.'));
215
		}
216
		return $this->redirect(array('action' => 'index'));
217
	}}