Subversion Repositories SmartDukaan

Rev

Rev 13541 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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