Subversion Repositories SmartDukaan

Rev

Rev 14098 | 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');
13946 anikendra 22
//		Configure::load('live');
13633 anikendra 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";
13637 anikendra 123
		$response = $this->make_request($url,null);
13633 anikendra 124
		$this->set('categoryDiscounts',$response);
125
		$this->loadModel('Category');
14098 anikendra 126
		// $categories = $this->Category->find('list');
127
		$categories = Configure::read('Categories');
13633 anikendra 128
		$this->set('categories',$categories);
13579 anikendra 129
	}
130
 
131
/**
132
 * admin_view method
133
 *
134
 * @throws NotFoundException
135
 * @param string $id
136
 * @return void
137
 */
138
	public function admin_view($id = null) {
139
		if (!$this->CategoryDiscount->exists($id)) {
140
			throw new NotFoundException(__('Invalid category discount'));
141
		}
142
		$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));
143
		$this->set('categoryDiscount', $this->CategoryDiscount->find('first', $options));
144
	}
145
 
146
/**
147
 * admin_add method
148
 *
149
 * @return void
150
 */
13633 anikendra 151
	public function admin_new() {		
13579 anikendra 152
		if ($this->request->is('post')) {
13633 anikendra 153
			$url = $this->apihost."discountInfo/addCategoryDiscount";
154
			$jsonVar = json_encode($this->request->data['CategoryDiscount'], JSON_NUMERIC_CHECK );
155
			$response = $this->make_request($url,$jsonVar);
156
			if (key($response)) {
157
				$this->Session->setFlash(current($response));
158
				return $this->redirect(array('action' => 'index'));
159
			} else {
160
				$this->Session->setFlash(current($response));
13579 anikendra 161
			}
162
		}
163
		$this->loadModel('Brand');
164
		$allbrands = $this->Brand->find('list');
165
		foreach ($allbrands as $key => $value) {
166
			$brands[$value] = $value;
167
		}
13633 anikendra 168
		$this->loadModel('Category');
169
		$categories = $this->Category->find('list',array('conditions'=>array('parent_id !='=>0)));
13579 anikendra 170
		$this->set(compact('categories','brands'));
171
	}
172
 
173
/**
174
 * admin_edit method
175
 *
176
 * @throws NotFoundException
177
 * @param string $id
178
 * @return void
179
 */
180
	public function admin_edit($id = null) {
14098 anikendra 181
		// if (!$this->CategoryDiscount->exists($id)) {
182
		// 	throw new NotFoundException(__('Invalid category discount'));
183
		// }
13579 anikendra 184
		if ($this->request->is(array('post', 'put'))) {
185
			if ($this->CategoryDiscount->save($this->request->data)) {
186
				$this->Session->setFlash(__('The category discount has been saved.'));
187
				return $this->redirect(array('action' => 'index'));
188
			} else {
189
				$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));
190
			}
191
		} else {
192
			$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));
193
			$this->request->data = $this->CategoryDiscount->find('first', $options);
194
		}
195
		$categories = $this->CategoryDiscount->Category->find('list');
196
		$this->set(compact('categories'));
197
	}
198
 
199
/**
200
 * admin_delete method
201
 *
202
 * @throws NotFoundException
203
 * @param string $id
204
 * @return void
205
 */
206
	public function admin_delete($id = null) {
15848 anikendra 207
		if ($this->remove($id,'CategoryDiscount')) {
208
			$this->Session->setFlash(__('The sku scheme deal has been deleted.'));
13579 anikendra 209
		} else {
15848 anikendra 210
			$this->Session->setFlash(__('The sku scheme could not be deleted. Please, try again.'));
13579 anikendra 211
		}
212
		return $this->redirect(array('action' => 'index'));
15848 anikendra 213
	}
214
}