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