Subversion Repositories SmartDukaan

Rev

Rev 13685 | Rev 13752 | 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
 * Orders Controller
5
 *
6
 * @property Order $Order
7
 * @property PaginatorComponent $Paginator
8
 */
9
class OrdersController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13672 anikendra 18
	public function beforeFilter() {		
13591 anikendra 19
		parent::beforeFilter();
13685 anikendra 20
		$this->Auth->allow('add','mine');
13672 anikendra 21
		$this->apihost = Configure::read('pythonapihost');
13591 anikendra 22
	}
23
 
13672 anikendra 24
	public function mine() {
13682 anikendra 25
		$userId = $this->request->query('user_id');
26
		if(isset($userId) && !empty($userId)){
27
			$this->loadModel('User');
28
			$dbuser = $this->User->findById($userId);
29
			$this->Auth->login($dbuser['User']);	
30
		}
13672 anikendra 31
		$this->layout = "innerpages";
32
		$url = $this->apihost."storeorder/user/".$this->Auth->User('id')."?page=1&window=10";
33
		$response = $this->make_request($url,null);
34
		if(!empty($response['data'])){
35
			$this->set('orders',$response['data']);
36
		}
13750 anikendra 37
		$ignoredFields = array('status','productTitle','estimatedDeliveryDate','productCode','merchantSubOrderId','productUrl','closed','tracingkUrl','detailedStatus');
38
		$this->set('ignoredFields',$ignoredFields);
13672 anikendra 39
	}
40
 
13532 anikendra 41
/**
42
 * index method
43
 *
44
 * @return void
45
 */
46
	public function index() {
13591 anikendra 47
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 48
		$this->Order->recursive = 0;
49
		$this->set('orders', $this->Paginator->paginate());
50
	}
51
 
52
/**
53
 * view method
54
 *
55
 * @throws NotFoundException
56
 * @param string $id
57
 * @return void
58
 */
59
	public function view($id = null) {
13591 anikendra 60
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 61
		if (!$this->Order->exists($id)) {
62
			throw new NotFoundException(__('Invalid order'));
63
		}
64
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
65
		$this->set('order', $this->Order->find('first', $options));
66
	}
67
 
68
/**
69
 * add method
70
 *
71
 * @return void
72
 */
73
	public function add() {
13633 anikendra 74
		$this->log(print_r($this->request->data,1),'orders');
13532 anikendra 75
		if ($this->request->is('post')) {
76
			$this->Order->create();
13633 anikendra 77
			if(!empty($this->request->data['sub_tag'])){
78
				$this->request->data['status'] = 'mapped';
79
			}
13532 anikendra 80
			if ($this->Order->save($this->request->data)) {
13591 anikendra 81
				$result =array('success'=>true,'message'=>__('The order has been saved.'));
13633 anikendra 82
/*
83
				$options = array('conditions'=>array('status'=>'mapped'),'recursive'=>-1);
84
				$order = $this->Order->find('first',$options);
85
				if(!empty($orders)) {
86
					foreach($orders AS $order) {
87
						$response = $this->PythonApi->postOrders($order);
88
						if(!empty($response) && $response['result']) {
89
							$sql = "UPDATE orders SET status = 'processed' WHERE id = ".$order['Order']['id'];
90
							$this->Order->query($sql);
91
						}
92
					}
93
				}
94
*/
13532 anikendra 95
			} else {
13591 anikendra 96
				$result = array('success'=>false,'message'=>__('The order could not be saved. Please, try again.'));
13532 anikendra 97
			}
13591 anikendra 98
			$this->response->type('json');
99
			$this->layout = 'ajax';
100
			$this->set(array(
101
			    'result' => $result,
102
			    // 'callback' => $callback,
103
			    '_serialize' => array('result')
104
			));
105
			$this->render('/Elements/json');		
106
		}			
13532 anikendra 107
	}
108
 
109
/**
110
 * edit method
111
 *
112
 * @throws NotFoundException
113
 * @param string $id
114
 * @return void
115
 */
116
	public function edit($id = null) {
13591 anikendra 117
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 118
		if (!$this->Order->exists($id)) {
119
			throw new NotFoundException(__('Invalid order'));
120
		}
121
		if ($this->request->is(array('post', 'put'))) {
122
			if ($this->Order->save($this->request->data)) {
123
				$this->Session->setFlash(__('The order has been saved.'));
124
				return $this->redirect(array('action' => 'index'));
125
			} else {
126
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
127
			}
128
		} else {
129
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
130
			$this->request->data = $this->Order->find('first', $options);
131
		}
132
		$users = $this->Order->User->find('list');
133
		$stores = $this->Order->Store->find('list');
134
		$storeOrders = $this->Order->StoreOrder->find('list');
135
		$this->set(compact('users', 'stores', 'storeOrders'));
136
	}
137
 
138
/**
139
 * delete method
140
 *
141
 * @throws NotFoundException
142
 * @param string $id
143
 * @return void
144
 */
145
	public function delete($id = null) {
13591 anikendra 146
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 147
		$this->Order->id = $id;
148
		if (!$this->Order->exists()) {
149
			throw new NotFoundException(__('Invalid order'));
150
		}
151
		$this->request->onlyAllow('post', 'delete');
152
		if ($this->Order->delete()) {
153
			$this->Session->setFlash(__('The order has been deleted.'));
154
		} else {
155
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
156
		}
157
		return $this->redirect(array('action' => 'index'));
158
	}
159
 
160
/**
161
 * admin_index method
162
 *
163
 * @return void
164
 */
165
	public function admin_index() {
166
		$this->Order->recursive = 0;
167
		$this->set('orders', $this->Paginator->paginate());
168
	}
169
 
170
/**
171
 * admin_view method
172
 *
173
 * @throws NotFoundException
174
 * @param string $id
175
 * @return void
176
 */
177
	public function admin_view($id = null) {
178
		if (!$this->Order->exists($id)) {
179
			throw new NotFoundException(__('Invalid order'));
180
		}
181
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
182
		$this->set('order', $this->Order->find('first', $options));
183
	}
184
 
185
/**
186
 * admin_add method
187
 *
188
 * @return void
189
 */
190
	public function admin_add() {
191
		if ($this->request->is('post')) {
192
			$this->Order->create();
193
			if ($this->Order->save($this->request->data)) {
194
				$this->Session->setFlash(__('The order has been saved.'));
195
				return $this->redirect(array('action' => 'index'));
196
			} else {
197
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
198
			}
199
		}
200
		$users = $this->Order->User->find('list');
201
		$stores = $this->Order->Store->find('list');
202
		$storeOrders = $this->Order->StoreOrder->find('list');
203
		$this->set(compact('users', 'stores', 'storeOrders'));
204
	}
205
 
206
/**
207
 * admin_edit method
208
 *
209
 * @throws NotFoundException
210
 * @param string $id
211
 * @return void
212
 */
213
	public function admin_edit($id = null) {
214
		if (!$this->Order->exists($id)) {
215
			throw new NotFoundException(__('Invalid order'));
216
		}
217
		if ($this->request->is(array('post', 'put'))) {
218
			if ($this->Order->save($this->request->data)) {
219
				$this->Session->setFlash(__('The order has been saved.'));
220
				return $this->redirect(array('action' => 'index'));
221
			} else {
222
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
223
			}
224
		} else {
225
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
226
			$this->request->data = $this->Order->find('first', $options);
227
		}
228
		$users = $this->Order->User->find('list');
229
		$stores = $this->Order->Store->find('list');
230
		$storeOrders = $this->Order->StoreOrder->find('list');
231
		$this->set(compact('users', 'stores', 'storeOrders'));
232
	}
233
 
234
/**
235
 * admin_delete method
236
 *
237
 * @throws NotFoundException
238
 * @param string $id
239
 * @return void
240
 */
241
	public function admin_delete($id = null) {
242
		$this->Order->id = $id;
243
		if (!$this->Order->exists()) {
244
			throw new NotFoundException(__('Invalid order'));
245
		}
246
		$this->request->onlyAllow('post', 'delete');
247
		if ($this->Order->delete()) {
248
			$this->Session->setFlash(__('The order has been deleted.'));
249
		} else {
250
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
251
		}
252
		return $this->redirect(array('action' => 'index'));
253
	}}