Subversion Repositories SmartDukaan

Rev

Rev 13532 | Rev 14455 | 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
 * Stores Controller
5
 *
6
 * @property Store $Store
7
 * @property PaginatorComponent $Paginator
8
 */
9
class StoresController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
/**
19
 * index method
20
 *
21
 * @return void
22
 */
23
	public function index() {
24
		$this->Store->recursive = 0;
25
		$this->set('stores', $this->Paginator->paginate());
26
	}
27
 
28
/**
29
 * view method
30
 *
31
 * @throws NotFoundException
32
 * @param string $id
33
 * @return void
34
 */
35
	public function view($id = null) {
36
		if (!$this->Store->exists($id)) {
37
			throw new NotFoundException(__('Invalid store'));
38
		}
39
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
40
		$this->set('store', $this->Store->find('first', $options));
41
	}
42
 
43
/**
44
 * add method
45
 *
46
 * @return void
47
 */
48
	public function add() {
49
		if ($this->request->is('post')) {
50
			$this->Store->create();
51
			if ($this->Store->save($this->request->data)) {
52
				$this->Session->setFlash(__('The store has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
56
			}
57
		}
58
		$affiliates = $this->Store->Affiliate->find('list');
59
		$this->set(compact('affiliates'));
60
	}
61
 
62
/**
63
 * edit method
64
 *
65
 * @throws NotFoundException
66
 * @param string $id
67
 * @return void
68
 */
69
	public function edit($id = null) {
70
		if (!$this->Store->exists($id)) {
71
			throw new NotFoundException(__('Invalid store'));
72
		}
73
		if ($this->request->is(array('post', 'put'))) {
74
			if ($this->Store->save($this->request->data)) {
75
				$this->Session->setFlash(__('The store has been saved.'));
76
				return $this->redirect(array('action' => 'index'));
77
			} else {
78
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
79
			}
80
		} else {
81
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
82
			$this->request->data = $this->Store->find('first', $options);
83
		}
84
		$affiliates = $this->Store->Affiliate->find('list');
85
		$this->set(compact('affiliates'));
86
	}
87
 
88
/**
89
 * delete method
90
 *
91
 * @throws NotFoundException
92
 * @param string $id
93
 * @return void
94
 */
95
	public function delete($id = null) {
96
		$this->Store->id = $id;
97
		if (!$this->Store->exists()) {
98
			throw new NotFoundException(__('Invalid store'));
99
		}
100
		$this->request->onlyAllow('post', 'delete');
101
		if ($this->Store->delete()) {
102
			$this->Session->setFlash(__('The store has been deleted.'));
103
		} else {
104
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
105
		}
106
		return $this->redirect(array('action' => 'index'));
107
	}
108
 
109
/**
110
 * admin_index method
111
 *
112
 * @return void
113
 */
114
	public function admin_index() {
115
		$this->Store->recursive = 0;
116
		$this->set('stores', $this->Paginator->paginate());
117
	}
118
 
119
/**
120
 * admin_view method
121
 *
122
 * @throws NotFoundException
123
 * @param string $id
124
 * @return void
125
 */
126
	public function admin_view($id = null) {
127
		if (!$this->Store->exists($id)) {
128
			throw new NotFoundException(__('Invalid store'));
129
		}
130
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
131
		$this->set('store', $this->Store->find('first', $options));
132
	}
133
 
134
/**
135
 * admin_add method
136
 *
137
 * @return void
138
 */
139
	public function admin_add() {
140
		if ($this->request->is('post')) {
141
			$this->Store->create();
142
			if ($this->Store->save($this->request->data)) {
143
				$this->Session->setFlash(__('The store has been saved.'));
144
				return $this->redirect(array('action' => 'index'));
145
			} else {
146
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
147
			}
148
		}
149
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 150
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
151
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 152
	}
153
 
154
/**
155
 * admin_edit method
156
 *
157
 * @throws NotFoundException
158
 * @param string $id
159
 * @return void
160
 */
161
	public function admin_edit($id = null) {
162
		if (!$this->Store->exists($id)) {
163
			throw new NotFoundException(__('Invalid store'));
164
		}
165
		if ($this->request->is(array('post', 'put'))) {
166
			if ($this->Store->save($this->request->data)) {
167
				$this->Session->setFlash(__('The store has been saved.'));
168
				return $this->redirect(array('action' => 'index'));
169
			} else {
170
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
171
			}
172
		} else {
173
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
174
			$this->request->data = $this->Store->find('first', $options);
175
		}
176
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 177
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
178
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 179
	}
180
 
181
/**
182
 * admin_delete method
183
 *
184
 * @throws NotFoundException
185
 * @param string $id
186
 * @return void
187
 */
188
	public function admin_delete($id = null) {
189
		$this->Store->id = $id;
190
		if (!$this->Store->exists()) {
191
			throw new NotFoundException(__('Invalid store'));
192
		}
193
		$this->request->onlyAllow('post', 'delete');
194
		if ($this->Store->delete()) {
195
			$this->Session->setFlash(__('The store has been deleted.'));
196
		} else {
197
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
198
		}
199
		return $this->redirect(array('action' => 'index'));
200
	}}