| 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();
|
| 15093 |
anikendra |
20 |
$this->Auth->allow('add','mine','pendingcashbacks','all');
|
| 13672 |
anikendra |
21 |
$this->apihost = Configure::read('pythonapihost');
|
| 13591 |
anikendra |
22 |
}
|
|
|
23 |
|
| 13816 |
anikendra |
24 |
public function mine() {
|
| 15824 |
anikendra |
25 |
$type = $this->request->query('type');
|
| 13816 |
anikendra |
26 |
$page = $this->request->query('page');
|
|
|
27 |
$page = isset($page)?$page:1;
|
| 13682 |
anikendra |
28 |
$userId = $this->request->query('user_id');
|
|
|
29 |
if(isset($userId) && !empty($userId)){
|
|
|
30 |
$this->loadModel('User');
|
|
|
31 |
$dbuser = $this->User->findById($userId);
|
|
|
32 |
$this->Auth->login($dbuser['User']);
|
|
|
33 |
}
|
| 13672 |
anikendra |
34 |
$this->layout = "innerpages";
|
| 13815 |
anikendra |
35 |
$url = $this->apihost."storeorder/user/".$this->Auth->User('id')."?page=$page&window=10";
|
| 15824 |
anikendra |
36 |
if(isset($type) && !empty($type)) {
|
|
|
37 |
$url .= '&type='.$type;
|
|
|
38 |
}
|
| 13672 |
anikendra |
39 |
$response = $this->make_request($url,null);
|
| 13815 |
anikendra |
40 |
$totalPages = $response['totalPages'];
|
| 13672 |
anikendra |
41 |
if(!empty($response['data'])){
|
|
|
42 |
$this->set('orders',$response['data']);
|
|
|
43 |
}
|
| 13752 |
anikendra |
44 |
$ignoredFields = array('imgUrl','status','productTitle','estimatedDeliveryDate','productCode','merchantSubOrderId','productUrl','closed','tracingkUrl','detailedStatus');
|
| 13944 |
anikendra |
45 |
$storemapping = Configure::read('storemapping');
|
|
|
46 |
$activestores = Configure::read('activestores');
|
| 14224 |
anikendra |
47 |
$amazonorderurl = Configure::read('amazonorderurl');
|
|
|
48 |
$this->set(compact('ignoredFields','page','totalPages','userId','activestores','storemapping','amazonorderurl'));
|
| 13672 |
anikendra |
49 |
}
|
|
|
50 |
|
| 15217 |
anikendra |
51 |
public function by($userId) {
|
|
|
52 |
$page = $this->request->query('page');
|
|
|
53 |
$page = isset($page)?$page:1;
|
|
|
54 |
$this->layout = "innerpages";
|
|
|
55 |
$url = $this->apihost."storeorder/user/".$userId."?page=$page&window=10";
|
|
|
56 |
$response = $this->make_request($url,null);
|
|
|
57 |
$totalPages = $response['totalPages'];
|
|
|
58 |
if(!empty($response['data'])){
|
|
|
59 |
$this->set('orders',$response['data']);
|
|
|
60 |
}
|
|
|
61 |
$ignoredFields = array('imgUrl','status','productTitle','estimatedDeliveryDate','productCode','merchantSubOrderId','productUrl','closed','tracingkUrl','detailedStatus');
|
|
|
62 |
$storemapping = Configure::read('storemapping');
|
|
|
63 |
$activestores = Configure::read('activestores');
|
|
|
64 |
$amazonorderurl = Configure::read('amazonorderurl');
|
|
|
65 |
$this->set(compact('ignoredFields','page','totalPages','userId','activestores','storemapping','amazonorderurl'));
|
|
|
66 |
}
|
|
|
67 |
|
| 13762 |
anikendra |
68 |
public function pendingcashbacks() {
|
|
|
69 |
$userId = $this->request->query('user_id');
|
|
|
70 |
if(isset($userId) && !empty($userId)){
|
|
|
71 |
$this->loadModel('User');
|
|
|
72 |
$dbuser = $this->User->findById($userId);
|
|
|
73 |
$this->Auth->login($dbuser['User']);
|
|
|
74 |
}
|
|
|
75 |
$this->layout = "innerpages";
|
| 13993 |
anikendra |
76 |
$url = $this->apihost."storeorder/user/".$this->Auth->User('id')."?page=1&window=50";
|
| 13762 |
anikendra |
77 |
$response = $this->make_request($url,null);
|
| 13993 |
anikendra |
78 |
// debug($response);
|
|
|
79 |
$creditedOrders = $pendingOrders = $approvedOrders = array();
|
|
|
80 |
$creditedAmount = $pendingAmount = $approvedAmount = 0;
|
| 13762 |
anikendra |
81 |
if(!empty($response['data'])){
|
| 13993 |
anikendra |
82 |
foreach ($response['data'] as $key => $order) {
|
| 14111 |
anikendra |
83 |
if(!empty($order['subOrders'])){
|
|
|
84 |
foreach ($order['subOrders'] as $key => $suborder) {
|
|
|
85 |
$suborder['storeId'] = $order['storeId'];
|
| 15035 |
amit.gupta |
86 |
if($order['storeId']!=4){
|
| 15036 |
amit.gupta |
87 |
$suborder['merchantOrderId'] = $order['merchantOrderId'];
|
|
|
88 |
} else {
|
| 15035 |
amit.gupta |
89 |
$suborder['merchantOrderId'] = $suborder['merchantSubOrderId'];
|
|
|
90 |
}
|
| 14700 |
anikendra |
91 |
if(!empty($order['orderTrackingUrl'])){
|
|
|
92 |
$suborder['orderSuccessUrl'] = $order['orderTrackingUrl'];
|
|
|
93 |
}
|
| 14111 |
anikendra |
94 |
switch($suborder['cashBackStatus']){
|
|
|
95 |
// case 'Credited to wallet'://Credited
|
|
|
96 |
// $creditedOrders[] = $suborder;
|
|
|
97 |
// break;
|
|
|
98 |
case 'Approved':
|
|
|
99 |
$approvedOrders[] = $suborder;
|
|
|
100 |
$approvedAmount += $suborder['cashBackAmount'];
|
|
|
101 |
break;
|
|
|
102 |
case 'Pending':
|
|
|
103 |
$pendingOrders[] = $suborder;
|
| 14673 |
anikendra |
104 |
// $pendingAmount += $suborder['cashBackAmount'];
|
| 14111 |
anikendra |
105 |
}
|
| 13993 |
anikendra |
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
| 13762 |
anikendra |
109 |
}
|
| 14673 |
anikendra |
110 |
$url = $this->apihost.'pending-cashbacks/user/'.$userId;
|
|
|
111 |
$result = $this->make_request($url,null);
|
|
|
112 |
$pendingAmount = $result['amount'];
|
| 13993 |
anikendra |
113 |
//Get pending cashbacks
|
|
|
114 |
$url = $this->apihost.'pending-refunds/user/'.$userId;
|
|
|
115 |
$pendingCashbacks = $this->make_request($url,null);
|
|
|
116 |
//Get credited cashbacks
|
|
|
117 |
$url = $this->apihost.'refund/user/'.$userId;
|
| 14068 |
anikendra |
118 |
$creditedCashbacks = $this->make_request($url,null);
|
|
|
119 |
|
| 14026 |
anikendra |
120 |
if(!empty($creditedCashbacks)){
|
| 13993 |
anikendra |
121 |
foreach ($creditedCashbacks['data'] as $key => $value) {
|
| 14068 |
anikendra |
122 |
$creditedAmount += $value['userAmount'];
|
|
|
123 |
$data = array('subOrders.batchId'=>$value['batch']);
|
|
|
124 |
$jsonVar = json_encode($data);
|
|
|
125 |
$url = $this->apihost."storeorder/user/".$this->Auth->User('id')."?page=1&window=50&searchMap=$jsonVar";
|
|
|
126 |
$creditedOrders[$value['batch']] = $this->make_request($url,null);
|
|
|
127 |
// debug($creditedOrders);
|
| 13993 |
anikendra |
128 |
}
|
|
|
129 |
}
|
| 14026 |
anikendra |
130 |
$storemapping = Configure::read('storemapping');
|
|
|
131 |
$activestores = Configure::read('activestores');
|
| 13993 |
anikendra |
132 |
if(!empty($response['data'])){
|
| 14026 |
anikendra |
133 |
$this->set(compact('storemapping','activestores','pendingOrders','approvedOrders','creditedOrders','pendingCashbacks','creditedCashbacks','pendingAmount','approvedAmount','creditedAmount'));
|
| 13993 |
anikendra |
134 |
}
|
| 13762 |
anikendra |
135 |
}
|
|
|
136 |
|
| 15217 |
anikendra |
137 |
public function usercashbacks($userId) {
|
|
|
138 |
$this->layout = "innerpages";
|
|
|
139 |
$url = $this->apihost."storeorder/user/".$userId."?page=1&window=50";
|
|
|
140 |
$response = $this->make_request($url,null);
|
|
|
141 |
// debug($response);
|
|
|
142 |
$creditedOrders = $pendingOrders = $approvedOrders = array();
|
|
|
143 |
$creditedAmount = $pendingAmount = $approvedAmount = 0;
|
|
|
144 |
if(!empty($response['data'])){
|
|
|
145 |
foreach ($response['data'] as $key => $order) {
|
|
|
146 |
if(!empty($order['subOrders'])){
|
|
|
147 |
foreach ($order['subOrders'] as $key => $suborder) {
|
|
|
148 |
$suborder['storeId'] = $order['storeId'];
|
|
|
149 |
if($order['storeId']!=4){
|
|
|
150 |
$suborder['merchantOrderId'] = $order['merchantOrderId'];
|
|
|
151 |
} else {
|
|
|
152 |
$suborder['merchantOrderId'] = $suborder['merchantSubOrderId'];
|
|
|
153 |
}
|
|
|
154 |
if(!empty($order['orderTrackingUrl'])){
|
|
|
155 |
$suborder['orderSuccessUrl'] = $order['orderTrackingUrl'];
|
|
|
156 |
}
|
|
|
157 |
switch($suborder['cashBackStatus']){
|
|
|
158 |
// case 'Credited to wallet'://Credited
|
|
|
159 |
// $creditedOrders[] = $suborder;
|
|
|
160 |
// break;
|
|
|
161 |
case 'Approved':
|
|
|
162 |
$approvedOrders[] = $suborder;
|
|
|
163 |
$approvedAmount += $suborder['cashBackAmount'];
|
|
|
164 |
break;
|
|
|
165 |
case 'Pending':
|
|
|
166 |
$pendingOrders[] = $suborder;
|
|
|
167 |
// $pendingAmount += $suborder['cashBackAmount'];
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
$url = $this->apihost.'pending-cashbacks/user/'.$userId;
|
|
|
174 |
$result = $this->make_request($url,null);
|
|
|
175 |
$pendingAmount = $result['amount'];
|
|
|
176 |
//Get pending cashbacks
|
|
|
177 |
$url = $this->apihost.'pending-refunds/user/'.$userId;
|
|
|
178 |
$pendingCashbacks = $this->make_request($url,null);
|
|
|
179 |
//Get credited cashbacks
|
|
|
180 |
$url = $this->apihost.'refund/user/'.$userId;
|
|
|
181 |
$creditedCashbacks = $this->make_request($url,null);
|
|
|
182 |
|
|
|
183 |
if(!empty($creditedCashbacks)){
|
|
|
184 |
foreach ($creditedCashbacks['data'] as $key => $value) {
|
|
|
185 |
$creditedAmount += $value['userAmount'];
|
|
|
186 |
$data = array('subOrders.batchId'=>$value['batch']);
|
|
|
187 |
$jsonVar = json_encode($data);
|
|
|
188 |
$url = $this->apihost."storeorder/user/".$userId."?page=1&window=50&searchMap=$jsonVar";
|
|
|
189 |
$creditedOrders[$value['batch']] = $this->make_request($url,null);
|
|
|
190 |
// debug($creditedOrders);
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
$storemapping = Configure::read('storemapping');
|
|
|
194 |
$activestores = Configure::read('activestores');
|
|
|
195 |
if(!empty($response['data'])){
|
|
|
196 |
$this->set(compact('storemapping','activestores','pendingOrders','approvedOrders','creditedOrders','pendingCashbacks','creditedCashbacks','pendingAmount','approvedAmount','creditedAmount'));
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
|
| 15227 |
anikendra |
200 |
/*
|
| 13532 |
anikendra |
201 |
public function index() {
|
| 13591 |
anikendra |
202 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
203 |
$this->Order->recursive = 0;
|
|
|
204 |
$this->set('orders', $this->Paginator->paginate());
|
|
|
205 |
}
|
|
|
206 |
|
| 15227 |
anikendra |
207 |
|
| 13532 |
anikendra |
208 |
public function view($id = null) {
|
| 13591 |
anikendra |
209 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
210 |
if (!$this->Order->exists($id)) {
|
|
|
211 |
throw new NotFoundException(__('Invalid order'));
|
|
|
212 |
}
|
|
|
213 |
$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
|
|
|
214 |
$this->set('order', $this->Order->find('first', $options));
|
|
|
215 |
}
|
| 15227 |
anikendra |
216 |
*/
|
|
|
217 |
|
| 13532 |
anikendra |
218 |
/**
|
|
|
219 |
* add method
|
|
|
220 |
*
|
|
|
221 |
* @return void
|
|
|
222 |
*/
|
| 13814 |
anikendra |
223 |
|
|
|
224 |
public function postOrders($order=null) {
|
| 13994 |
anikendra |
225 |
// Configure::load('live');
|
| 13814 |
anikendra |
226 |
$apihost = Configure::read('pythonapihost');
|
|
|
227 |
$url = $apihost."storeorder";
|
|
|
228 |
if(!empty($order)) {
|
|
|
229 |
$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
|
|
|
230 |
$jsonVar = json_encode($params);
|
|
|
231 |
return $this->make_request($url,$jsonVar);
|
|
|
232 |
}else{
|
|
|
233 |
$result = array('success'=>false,'message'=>'Empty order array');
|
|
|
234 |
return $result;
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
|
| 13532 |
anikendra |
238 |
public function add() {
|
| 14933 |
amit.gupta |
239 |
$this->log(print_r($this->request->data,1),'orders');
|
| 13532 |
anikendra |
240 |
if ($this->request->is('post')) {
|
| 14886 |
amit.gupta |
241 |
if($this->request->data['zip']){
|
| 14933 |
amit.gupta |
242 |
$this->request->data['rawhtml'] = gzuncompress(base64_decode($this->request->data['rawhtml']));
|
| 14886 |
amit.gupta |
243 |
}
|
|
|
244 |
$this->log(print_r($this->request->data,1),'orders');
|
| 14315 |
anikendra |
245 |
if(empty($this->request->data['id'])) {
|
|
|
246 |
$this->Order->create();
|
| 13633 |
anikendra |
247 |
}
|
| 15093 |
anikendra |
248 |
$this->request->data['ip'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
| 13532 |
anikendra |
249 |
if ($this->Order->save($this->request->data)) {
|
| 14315 |
anikendra |
250 |
//$this->loadModel('PythonApi');
|
|
|
251 |
if(empty($this->request->data['id'])) {
|
|
|
252 |
$id = $this->Order->getLastInsertID();
|
|
|
253 |
}else{
|
|
|
254 |
$id = $this->request->data['id'];
|
|
|
255 |
}
|
|
|
256 |
$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
|
| 13814 |
anikendra |
257 |
$response = $this->postOrders($order);
|
|
|
258 |
$this->log(print_r($response,1),'orders');
|
|
|
259 |
if(!empty($response) && $response['result']) {
|
| 14315 |
anikendra |
260 |
//if($response['result'] == 'HTML_REQUIRED' || $response['result'] == 'requireHtml') {
|
|
|
261 |
if($response['htmlRequired'] == 1) {
|
| 13814 |
anikendra |
262 |
$this->loadModel('Rawhtml');
|
|
|
263 |
$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
|
|
|
264 |
$this->Rawhtml->create();
|
|
|
265 |
$this->Rawhtml->save($data);
|
| 14315 |
anikendra |
266 |
//$result =array('success'=>true,'message'=>__('requireHtml'),'url' => $response['url'],'orderId' => $response['orderId']);
|
|
|
267 |
$result = $response;
|
|
|
268 |
$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
|
|
|
269 |
}/* elseif($response['result'] == 'IGNORED') {
|
| 13814 |
anikendra |
270 |
$result =array('success'=>true,'message'=>__('IGNORED'));
|
|
|
271 |
$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
|
|
|
272 |
} elseif($response['result'] == 'PARSE_ERROR') {
|
|
|
273 |
$result =array('success'=>true,'message'=>__('PARSE_ERROR'));
|
|
|
274 |
$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
|
| 14315 |
anikendra |
275 |
} */
|
|
|
276 |
else {
|
|
|
277 |
$result =array('success'=>true,'message'=> $response['result']);
|
|
|
278 |
$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
|
| 13814 |
anikendra |
279 |
}
|
|
|
280 |
$this->Order->query($sql);
|
|
|
281 |
}
|
|
|
282 |
//$result = array('success'=>true,'message'=>__('HTML_REQUIRED'),'url'=>'https://www.amazon.in/gp/css/summary/edit.html?orderID=404-7369214-6566739');
|
| 13633 |
anikendra |
283 |
/*
|
|
|
284 |
$options = array('conditions'=>array('status'=>'mapped'),'recursive'=>-1);
|
|
|
285 |
$order = $this->Order->find('first',$options);
|
|
|
286 |
if(!empty($orders)) {
|
|
|
287 |
foreach($orders AS $order) {
|
|
|
288 |
$response = $this->PythonApi->postOrders($order);
|
|
|
289 |
if(!empty($response) && $response['result']) {
|
|
|
290 |
$sql = "UPDATE orders SET status = 'processed' WHERE id = ".$order['Order']['id'];
|
|
|
291 |
$this->Order->query($sql);
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
}
|
|
|
295 |
*/
|
| 13532 |
anikendra |
296 |
} else {
|
| 14315 |
anikendra |
297 |
$this->log(print_r($this->Order->validationErrors,1),'orders');
|
| 13591 |
anikendra |
298 |
$result = array('success'=>false,'message'=>__('The order could not be saved. Please, try again.'));
|
| 13532 |
anikendra |
299 |
}
|
| 13591 |
anikendra |
300 |
$this->response->type('json');
|
|
|
301 |
$this->layout = 'ajax';
|
|
|
302 |
$this->set(array(
|
| 14315 |
anikendra |
303 |
'result' => $response,
|
| 13591 |
anikendra |
304 |
// 'callback' => $callback,
|
|
|
305 |
'_serialize' => array('result')
|
|
|
306 |
));
|
|
|
307 |
$this->render('/Elements/json');
|
|
|
308 |
}
|
| 13532 |
anikendra |
309 |
}
|
|
|
310 |
|
| 15227 |
anikendra |
311 |
/*
|
|
|
312 |
|
| 13532 |
anikendra |
313 |
public function edit($id = null) {
|
| 13591 |
anikendra |
314 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
315 |
if (!$this->Order->exists($id)) {
|
|
|
316 |
throw new NotFoundException(__('Invalid order'));
|
|
|
317 |
}
|
|
|
318 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
319 |
if ($this->Order->save($this->request->data)) {
|
|
|
320 |
$this->Session->setFlash(__('The order has been saved.'));
|
|
|
321 |
return $this->redirect(array('action' => 'index'));
|
|
|
322 |
} else {
|
|
|
323 |
$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
|
|
|
324 |
}
|
|
|
325 |
} else {
|
|
|
326 |
$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
|
|
|
327 |
$this->request->data = $this->Order->find('first', $options);
|
|
|
328 |
}
|
|
|
329 |
$users = $this->Order->User->find('list');
|
|
|
330 |
$stores = $this->Order->Store->find('list');
|
|
|
331 |
$storeOrders = $this->Order->StoreOrder->find('list');
|
|
|
332 |
$this->set(compact('users', 'stores', 'storeOrders'));
|
|
|
333 |
}
|
|
|
334 |
|
| 15227 |
anikendra |
335 |
|
| 13532 |
anikendra |
336 |
public function delete($id = null) {
|
| 13591 |
anikendra |
337 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
338 |
$this->Order->id = $id;
|
|
|
339 |
if (!$this->Order->exists()) {
|
|
|
340 |
throw new NotFoundException(__('Invalid order'));
|
|
|
341 |
}
|
|
|
342 |
$this->request->onlyAllow('post', 'delete');
|
|
|
343 |
if ($this->Order->delete()) {
|
|
|
344 |
$this->Session->setFlash(__('The order has been deleted.'));
|
|
|
345 |
} else {
|
|
|
346 |
$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
|
|
|
347 |
}
|
|
|
348 |
return $this->redirect(array('action' => 'index'));
|
|
|
349 |
}
|
| 15227 |
anikendra |
350 |
*/
|
| 13532 |
anikendra |
351 |
|
|
|
352 |
/**
|
|
|
353 |
* admin_index method
|
|
|
354 |
*
|
|
|
355 |
* @return void
|
|
|
356 |
*/
|
|
|
357 |
public function admin_index() {
|
| 15227 |
anikendra |
358 |
$this->checkAcl();
|
| 13532 |
anikendra |
359 |
$this->Order->recursive = 0;
|
|
|
360 |
$this->set('orders', $this->Paginator->paginate());
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
/**
|
|
|
364 |
* admin_view method
|
|
|
365 |
*
|
|
|
366 |
* @throws NotFoundException
|
|
|
367 |
* @param string $id
|
|
|
368 |
* @return void
|
|
|
369 |
*/
|
|
|
370 |
public function admin_view($id = null) {
|
| 15227 |
anikendra |
371 |
$this->checkAcl();
|
| 13532 |
anikendra |
372 |
if (!$this->Order->exists($id)) {
|
|
|
373 |
throw new NotFoundException(__('Invalid order'));
|
|
|
374 |
}
|
|
|
375 |
$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
|
|
|
376 |
$this->set('order', $this->Order->find('first', $options));
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
/**
|
|
|
380 |
* admin_add method
|
|
|
381 |
*
|
|
|
382 |
* @return void
|
|
|
383 |
*/
|
|
|
384 |
public function admin_add() {
|
| 15227 |
anikendra |
385 |
$this->checkAcl();
|
| 13532 |
anikendra |
386 |
if ($this->request->is('post')) {
|
|
|
387 |
$this->Order->create();
|
|
|
388 |
if ($this->Order->save($this->request->data)) {
|
|
|
389 |
$this->Session->setFlash(__('The order has been saved.'));
|
|
|
390 |
return $this->redirect(array('action' => 'index'));
|
|
|
391 |
} else {
|
|
|
392 |
$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
|
|
|
393 |
}
|
|
|
394 |
}
|
|
|
395 |
$users = $this->Order->User->find('list');
|
|
|
396 |
$stores = $this->Order->Store->find('list');
|
|
|
397 |
$storeOrders = $this->Order->StoreOrder->find('list');
|
|
|
398 |
$this->set(compact('users', 'stores', 'storeOrders'));
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
/**
|
|
|
402 |
* admin_edit method
|
|
|
403 |
*
|
|
|
404 |
* @throws NotFoundException
|
|
|
405 |
* @param string $id
|
|
|
406 |
* @return void
|
|
|
407 |
*/
|
|
|
408 |
public function admin_edit($id = null) {
|
| 15227 |
anikendra |
409 |
$this->checkAcl();
|
| 13532 |
anikendra |
410 |
if (!$this->Order->exists($id)) {
|
|
|
411 |
throw new NotFoundException(__('Invalid order'));
|
|
|
412 |
}
|
|
|
413 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
414 |
if ($this->Order->save($this->request->data)) {
|
|
|
415 |
$this->Session->setFlash(__('The order has been saved.'));
|
|
|
416 |
return $this->redirect(array('action' => 'index'));
|
|
|
417 |
} else {
|
|
|
418 |
$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
|
|
|
419 |
}
|
|
|
420 |
} else {
|
|
|
421 |
$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
|
|
|
422 |
$this->request->data = $this->Order->find('first', $options);
|
|
|
423 |
}
|
|
|
424 |
$users = $this->Order->User->find('list');
|
|
|
425 |
$stores = $this->Order->Store->find('list');
|
|
|
426 |
$storeOrders = $this->Order->StoreOrder->find('list');
|
|
|
427 |
$this->set(compact('users', 'stores', 'storeOrders'));
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
/**
|
|
|
431 |
* admin_delete method
|
|
|
432 |
*
|
|
|
433 |
* @throws NotFoundException
|
|
|
434 |
* @param string $id
|
|
|
435 |
* @return void
|
|
|
436 |
*/
|
|
|
437 |
public function admin_delete($id = null) {
|
| 15227 |
anikendra |
438 |
$this->checkAcl();
|
| 13532 |
anikendra |
439 |
$this->Order->id = $id;
|
|
|
440 |
if (!$this->Order->exists()) {
|
|
|
441 |
throw new NotFoundException(__('Invalid order'));
|
|
|
442 |
}
|
|
|
443 |
$this->request->onlyAllow('post', 'delete');
|
|
|
444 |
if ($this->Order->delete()) {
|
|
|
445 |
$this->Session->setFlash(__('The order has been deleted.'));
|
|
|
446 |
} else {
|
|
|
447 |
$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
|
|
|
448 |
}
|
|
|
449 |
return $this->redirect(array('action' => 'index'));
|
| 14354 |
anikendra |
450 |
}
|
|
|
451 |
|
|
|
452 |
public function all() {
|
|
|
453 |
$page = $this->request->query('page');
|
|
|
454 |
$page = isset($page)?$page:1;
|
| 14509 |
anikendra |
455 |
// $userId = $this->request->query('user_id');
|
|
|
456 |
// if(isset($userId) && !empty($userId)){
|
|
|
457 |
// $this->loadModel('User');
|
|
|
458 |
// $dbuser = $this->User->findById($userId);
|
|
|
459 |
// $this->Auth->login($dbuser['User']);
|
|
|
460 |
// }
|
| 14354 |
anikendra |
461 |
$this->layout = "innerpages";
|
|
|
462 |
$url = $this->apihost."orders/?page=$page&window=10";
|
|
|
463 |
$response = $this->make_request($url,null);
|
| 14509 |
anikendra |
464 |
$totalPages = $response['totalPages'];
|
| 14354 |
anikendra |
465 |
if(!empty($response['data'])){
|
|
|
466 |
$this->set('orders',$response['data']);
|
|
|
467 |
}
|
|
|
468 |
$ignoredFields = array('imgUrl','status','productTitle','estimatedDeliveryDate','productCode','merchantSubOrderId','productUrl','closed','tracingkUrl','detailedStatus');
|
|
|
469 |
$storemapping = Configure::read('storemapping');
|
|
|
470 |
$activestores = Configure::read('activestores');
|
|
|
471 |
$amazonorderurl = Configure::read('amazonorderurl');
|
|
|
472 |
$allusers = $this->Order->User->find('all',array('fields'=>array('first_name','id'),'recursive'=>-1));
|
|
|
473 |
foreach($allusers AS $user){
|
|
|
474 |
$users[$user['User']['id']] = $user['User']['first_name'];
|
|
|
475 |
}
|
| 15188 |
anikendra |
476 |
$this->layout = 'admin';
|
| 14354 |
anikendra |
477 |
$this->set(compact('ignoredFields','page','totalPages','userId','activestores','storemapping','amazonorderurl','users'));
|
|
|
478 |
}
|
|
|
479 |
}
|