Subversion Repositories SmartDukaan

Rev

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