Subversion Repositories SmartDukaan

Rev

Rev 18832 | Rev 18834 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17793 naman 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ShippingsController 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
		$this->apihost = Configure::read('pythonapihost');
21
		$this->mobileapihost = Configure::read('saholicapihost');
17838 manish.sha 22
		$this->Auth->allow('isServicable');
17793 naman 23
	}
24
 
25
 
26
	public function index(){
27
		$userId = $this->Auth->User('id');
17838 manish.sha 28
		$dataGiven = json_decode($this->request->data['cart_details']);
17793 naman 29
		if ($this->request->is('post')) {
30
			$data = $this->request->data;
31
		}
17871 manish.sha 32
 
17838 manish.sha 33
		$suserId = base64_decode($_COOKIE['s_id']);
17871 manish.sha 34
		$scartId = base64_decode($_COOKIE['s_cart']);
35
		$semailId = base64_decode($_COOKIE['s_email']);
36
 
37
		$pincode = 0;
38
 
39
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
40
			$pincode = base64_decode($_COOKIE['s_pincode']);
17793 naman 41
		}
17838 manish.sha 42
 
17871 manish.sha 43
		$cartItems = array();
44
 
45
		foreach ($dataGiven->cartItems as $key=>$obj) {
46
		    $itemobj = array(
47
					'itemId'   => $key,
48
		    		'quantity' => $obj->quantity);
49
			array_push($cartItems, $itemobj);
17838 manish.sha 50
		}
17871 manish.sha 51
		$postData = array(
52
					'cartItems'	=>	$cartItems
53
					);
54
 
55
		$params = array(
56
				'cartMap' => urlencode(json_encode($postData)));
17838 manish.sha 57
 
17871 manish.sha 58
		$this->layout = 'cartinnerpages';
59
		$url = Configure::read('saholicapihost').'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId;
60
		if($pincode!='0'){
61
			$url = $url.'&pinCode='.$pincode;
62
		}
63
		$cartskus = $this->post_cartinfo_request($url,$params);
64
		if(isset($cartskus['response']) && $cartskus['response']=='error'){
65
			$this->set(compact('cartskus'));
66
			$this->render('/Users/cartdetails');
67
 
68
		}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
69
			setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
70
			$this->set(compact('cartskus'));
71
			$this->render('/Users/cartdetails');
72
		}else{
73
			$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
74
			$this->Session->write('totalPayable', $totalPayable);
75
			$this->layout = 'innerpages';
17882 naman 76
			$url = Configure::read ( 'saholicapihost' ) . 'address?isLoggedIn=true&privateDealUser=true&userId=' . $suserId;
77
			$response = $this->make_request ( $url, null );
78
			$user_name = "";
79
			$user_contact = "";
17871 manish.sha 80
 
17947 manish.sha 81
			$codAvailable = $cartskus['cod'];
82
			$this->Session->write('cod', $codAvailable);
18699 manish.sha 83
			$creditTicketSize = 0;
17947 manish.sha 84
 
18633 manish.sha 85
			$creditorAssociated = $response ['creditorAssociated'];
18718 manish.sha 86
			if(!isset($response ['userSanctions'])){
18633 manish.sha 87
				$creditLimit = 0;
88
			}else{
89
				$creditLimit = 0;
18699 manish.sha 90
				$creditTicketSize = intval($response ['userSanctions'][0]['ticket_size']);
18633 manish.sha 91
				foreach ( $response ['userSanctions'] as $key => $value ) {
18699 manish.sha 92
					$creditLimit = $creditLimit + intval($value ['credit_limit']) - (intval($value['credit_blocked'])+intval($value['loan']));
18633 manish.sha 93
				}
94
			}
95
			$this->Session->write('creditorAssociated', $creditorAssociated);
96
			$this->Session->write('creditLimit', $creditLimit);
18699 manish.sha 97
			$this->Session->write('creditTicketSize', $creditTicketSize);
18734 manish.sha 98
			$taxInvoiceEnabledUser = $response ['taxInvoiceEnabledUser'];
99
			$this->Session->write('taxInvoiceEnabledUser', $taxInvoiceEnabledUser);
18633 manish.sha 100
 
17882 naman 101
			if(empty($response ['addresses'])){
102
				$this->redirect ( array (
103
						'action' => 'add' 
104
				));
17793 naman 105
			}
17871 manish.sha 106
 
17882 naman 107
			$firstshowaddress = array ();
108
			$findedaddress = array ();
109
			$moreshowaddress = array ();
110
			$current_address_id = - 1;
111
			$defaultpin = - 1;
112
			$defaultcookiepin = - 1;
113
			$defaultcheckedaddress = - 1;
114
			$defaultpinaddress = - 1;
18633 manish.sha 115
 
17882 naman 116
			foreach ( $response ['addresses'] as $key => $value ) {
117
 
118
				if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
119
					$defaultcookiepin = $key;
120
					$user_name = $value ['name'];
121
					$user_contact = $value ['phone'];
122
					if ($defaultcheckedaddress == - 1) {
123
						$defaultcheckedaddress = $value ['id'];
124
					}
125
				} else if (intval ( $value ['pin'] ) == $pincode) {
126
					$current_address_id = $key;
127
					array_push ( $findedaddress, $key );
128
					if ($defaultpinaddress == - 1) {
129
						$defaultpinaddress = $value ['id'];
130
					}
131
				} else if ($value ['id'] == intval ( $response ['defaultAddress'] )) {
132
					$defaultpin = $key;
133
					$user_name = $value ['name'];
134
					$user_contact = $value ['phone'];
135
				} else {
136
					array_push ( $moreshowaddress, $key );
17871 manish.sha 137
				}
138
			}
17882 naman 139
 
140
			$defaultselectedaddress = - 1;
141
			if ($defaultpinaddress != - 1) {
142
				$defaultselectedaddress = $defaultpinaddress;
17793 naman 143
			}
17882 naman 144
			if ($defaultcheckedaddress != - 1) {
145
				$defaultselectedaddress = $defaultcheckedaddress;
17871 manish.sha 146
			}
17882 naman 147
 
148
			if ($defaultcookiepin != - 1) {
149
				array_push ( $firstshowaddress, $defaultcookiepin );
17871 manish.sha 150
			}
17882 naman 151
 
152
			for($i = 0; $i < count ( $findedaddress ); $i ++) {
153
				array_push ( $firstshowaddress, $findedaddress [$i] );
17871 manish.sha 154
			}
155
 
17882 naman 156
			if ($defaultpin != - 1) {
157
				array_push ( $firstshowaddress, $defaultpin );
158
			}
159
 
160
			for($i = 0; $i < count ( $moreshowaddress ); $i ++) {
161
				array_push ( $firstshowaddress, $moreshowaddress [$i] );
162
			}
163
 
164
			$this->set ( 'address', $response );
165
 
18734 manish.sha 166
			$this->set ( compact ( 'firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'taxInvoiceEnabledUser', 'creditorAssociated', 'creditLimit', 'creditTicketSize') );
17793 naman 167
		}
17882 naman 168
	}
169
	public function add($user_name = null, $user_contact = null) {
170
		$this->layout = 'cartinnerpages';
17793 naman 171
 
17882 naman 172
		$totalPayable = $_SESSION ['totalPayable'];
17947 manish.sha 173
		$codAvailable = $_SESSION ['cod'];
18633 manish.sha 174
		$creditLimit = $_SESSION ['creditLimit'];
175
		$creditorAssociated = $_SESSION ['creditorAssociated'];
18699 manish.sha 176
		$creditTicketSize = $_SESSION ['creditTicketSize'];
18734 manish.sha 177
		$taxInvoiceEnabledUser = $_SESSION['taxInvoiceEnabledUser'];
18039 amit.gupta 178
		//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
179
		$pinval='';
17882 naman 180
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
181
		$scart = base64_decode ( $_COOKIE ['s_cart'] );
182
 
183
		if ($this->request->is ( 'post' )) {
17793 naman 184
			$data = $this->request->data;
17882 naman 185
 
186
			$senddata ['name'] = $data ['name'];
187
			$senddata ['line1'] = $data ['line1'];
188
			$senddata ['line2'] = "";
189
			$senddata ['city'] = $data ['city'];
190
			$senddata ['state'] = $data ['state'];
191
			$senddata ['pin'] = $data ['pin'];
192
			$senddata ['phone'] = $data ['phone'];
193
			$senddata ['country'] = 'India';
194
			$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";
195
 
196
			$response = $this->post_request ( $url, $senddata );
197
 
198
			$scartId = base64_decode ( $_COOKIE ['s_cart'] );
199
			$semailId = base64_decode ( $_COOKIE ['s_email'] );
200
			$blank = array ();
201
			$postData = array (
202
					'cartItems' => $blank 
203
			);
204
 
205
			$params = array (
206
					'cartMap' => urlencode ( json_encode ( $postData ) ) 
207
			);
208
			$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
209
			// if($pin!='0'){
210
			$url = $url . '&pinCode=' . $data ['pin'];
211
			// }
212
			$cartskus = $this->post_cartinfo_request ( $url, $params );
213
			$checkestimate = 'true';
214
			if ($cartskus ['maxEstimate'] == - 1) {
215
				$checkestimate = 'false';
216
			} else {
217
				for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 218
					if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
219
						continue;
220
					}
221
					$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
222
					if ($estimate==-1) {
17882 naman 223
						$checkestimate = 'false';
224
						break;
225
					}
226
				}
17793 naman 227
			}
228
 
17882 naman 229
			if ($checkestimate == 'false') {
230
				// debug("I am here");
231
				$this->Session->setFlash ( "Address is not serviceable", 'default', array (
232
						'class' => 'alert alert-danger custom_class' 
233
				) );
234
				// $this->Session->setFlash('Address is not serviceable');
235
				return $this->redirect ( array (
236
						'action' => 'index' 
237
				) );
238
			} else {
239
				$this->Session->setFlash ( "Address is  serviceable" );
17793 naman 240
			}
241
		}
242
 
17882 naman 243
		$url = $this->apihost . "pincodeValidation/" . $pinval;
244
		$getstate = $this->make_request ( $url, null );
17844 naman 245
		// debug($getstate);
17793 naman 246
		$getstateval = "";
17882 naman 247
		if ($getstate != "{}") {
248
			$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
17793 naman 249
		}
18734 manish.sha 250
		$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable', 'creditorAssociated', 'creditLimit', 'creditTicketSize', 'taxInvoiceEnabledUser'));
17793 naman 251
	}
17882 naman 252
	public function submitcheck() {
253
		$this->autoRender = false;
254
		$this->request->onlyAllow ( 'ajax' );
255
 
17899 amit.gupta 256
		$suserId = base64_decode($_COOKIE['s_id']);
257
		$scartId = base64_decode($_COOKIE['s_cart']);
258
		$semailId = base64_decode($_COOKIE['s_email']);
259
 
17882 naman 260
		$data = $this->request->data;
261
 
262
		$senddata ['name'] = $data ['name'];
263
		$senddata ['line1'] = $data ['line1'];
264
		$senddata ['line2'] = "";
265
		$senddata ['city'] = $data ['city'];
266
		$senddata ['state'] = $data ['state'];
267
		$senddata ['pin'] = $data ['pin'];
268
		$senddata ['phone'] = $data ['phone'];
269
		$senddata ['country'] = 'India';
17899 amit.gupta 270
		$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scartId . "&isPrivateDealUser=true";
17882 naman 271
 
17899 amit.gupta 272
		$response = $this->post_cartinfo_request($url,$senddata);
17882 naman 273
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
274
 
275
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
276
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
277
		$blank = array ();
278
		$postData = array (
279
				'cartItems' => $blank 
280
		);
281
 
282
		$params = array (
283
				'cartMap' => urlencode ( json_encode ( $postData ) ) 
284
		);
285
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
286
		// if($pin!='0'){
287
		$url = $url . '&pinCode=' . $data ['pin'];
288
		// }
289
		$cartskus = $this->post_cartinfo_request ( $url, $params );
17893 amit.gupta 290
		$checkestimate = $response ['defaultAddress'];
17882 naman 291
		if ($cartskus ['maxEstimate'] == - 1) {
17893 amit.gupta 292
			$checkestimate = '';
17882 naman 293
		} else {
294
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 295
				if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
296
					continue;
297
				}
298
				$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
299
				if ($estimate==-1) {
17893 amit.gupta 300
					$checkestimate = '';
17882 naman 301
					break;
302
				}
303
			}
304
		}
305
 
306
		return $checkestimate;
307
	}
308
	public function getstate($pin_val) {
309
		$this->autoRender = false;
310
		$this->request->onlyAllow ( 'ajax' );
311
		$url = $this->apihost . "pincodeValidation/" . $pin_val;
312
		$getstate = $this->make_request ( $url, null );
313
		// $getstate['state'] = ucwords(strtolower($getstate['state']));
17844 naman 314
		$nothing = "nothing";
17882 naman 315
		if ($getstate != "{}") {
316
			$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );
17844 naman 317
		}
17882 naman 318
		return json_encode ( $getstate );
319
	}
320
	public function isServicable($pin) {
321
		$this->autoRender = false;
322
		$this->request->onlyAllow ( 'ajax' );
17793 naman 323
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
324
		// $response = $this->make_request($url,null);
17882 naman 325
 
326
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
327
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
328
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
329
		$blank = array ();
330
		$postData = array (
331
				'cartItems' => $blank 
332
		);
333
 
334
		$params = array (
335
				'cartMap' => urlencode ( json_encode ( $postData ) ) 
336
		);
337
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
338
		$url = $url . '&pinCode=' . $pin;
339
		$cartskus = $this->post_cartinfo_request ( $url, $params );
340
		$checkestimate = 'true';
341
		if ($cartskus ['maxEstimate'] == - 1) {
342
			$checkestimate = 'false';
343
		} else {
344
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 345
				if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
346
					continue;
347
				}
348
				$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
349
				if ($estimate==-1) {
17882 naman 350
					$checkestimate = 'false';
351
					break;
352
				}
353
			}
354
		}
355
 
356
		return $checkestimate;
357
	}
358
 
17871 manish.sha 359
	 public function checkout(){
18662 manish.sha 360
	 	$addressid = $this->request->data['addressid'];
17846 manish.sha 361
	 	$pincode = 0;
17871 manish.sha 362
		$cod = $this->request->query('cod');
17846 manish.sha 363
		$userId = $this->request->query('user_id');
364
 
18619 amit.gupta 365
		//Added token validation to ensure only user 
18832 manish.sha 366
		$testCheck = !Configure::read('requireusercheck');
367
		$tokenValidated = 0;
368
		if($testCheck){
369
			$tokenValidated =  1;
370
		}else{
371
			$tokenValidated = $this->checkToken($userId);
372
		}
373
 
18831 manish.sha 374
		if(!empty($userId) && $tokenValidated){			
18619 amit.gupta 375
			$url = $this->getAutoLoginUrl($userId,$url);
376
 
377
			if(isset($this->request->data->pincode)){
378
				$pincode = $this->request->data->pincode;
17871 manish.sha 379
			}
18619 amit.gupta 380
			if($pincode==0 && isset($_COOKIE['s_pincode'])){
381
				$pincode = base64_decode($_COOKIE['s_pincode']);
382
			}
383
 
384
			$suserId = base64_decode($_COOKIE['s_id']);
385
			$scartId = base64_decode($_COOKIE['s_cart']);
386
			$semailId = base64_decode($_COOKIE['s_email']);
387
 
388
			if(isset($_COOKIE['txn_comp'])) {
389
				unset($_COOKIE['txn_comp']);
390
			}
391
 
392
			if($cod==1){
393
				$url = Configure::read('saholicapihost').'order?payment_option=3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
394
			 	if($pincode!='0'){
395
					$url = $url.'&pinCode='.$pincode;
396
				}
397
				$orderCreationResponse = $this->post_cartinfo_request($url, null);
398
				//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
399
				$redirecturl = $orderCreationResponse['response']['redirectUrl'];
400
				if (strpos($redirecturl,'pay-success') === false) {
401
				    setcookie('txn_comp', 'no', -1, '/');
402
				} else {
403
					$order_det = array();
404
					$this->loadModel('Order');
405
					$order_det['user_id'] = $this->Auth->User('id');
406
					$order_det['store_id'] = 4;
407
					$str = Configure::read('saholicauthurl');
18633 manish.sha 408
					$orderDetailsArgs = explode('/autologin/',$str);
409
					$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
18619 amit.gupta 410
					$this->log(print_r($order_det,1),'ordersdet');
411
					$this->Order->create();
18613 naman 412
 
18619 amit.gupta 413
					if ($this->Order->save($order_det)) {
414
						$id = $this->Order->getLastInsertID();
415
						$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
416
						$apihost = Configure::read('pythonapihost');
417
						$url = $apihost."storeorder";
418
 
419
						$this->log(print_r($url,1),'ordersdet');
420
 
421
						$this->log(print_r($order,1),'ordersdet');
422
						$response = array();
423
	// 					$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']);
424
						if(!empty($order)) {
425
							$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']);
426
							$jsonVar = json_encode($params);
427
							$response =  $this->make_request($url,$jsonVar);
428
						}else{
429
							$result = array('success'=>false,'message'=>'Empty order array');
430
							$response = $result;
431
						}
432
						$this->log(print_r('response',1),'ordersdet');
433
						$this->log(print_r($response,1),'ordersdet');
434
						if(!empty($response) && $response['result']) {
435
							if($response['htmlRequired'] == 1) {
436
								$this->loadModel('Rawhtml');
437
								$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
438
								$this->Rawhtml->create();
439
								$this->Rawhtml->save($data);
440
								$this->log(print_r('insideif',1),'ordersdet');
441
								$result =  $response;
442
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
443
							}
444
							else {
445
								$result =array('success'=>true,'message'=> $response['result']);
446
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
447
								$this->log(print_r('insideelse',1),'ordersdet');
448
							}
449
							$this->log(print_r($sql,1),'ordersdet');
450
							$this->Order->query($sql);
451
 
452
						}					
18613 naman 453
					}
454
				}
18619 amit.gupta 455
				$this->layout = 'innerpages';
456
				$next = $redirecturl;					
457
				$redirectUrl = $this->getAutoLoginUrl($userId,$next);
458
				$this->log($redirectUrl,'headers');
459
				$this->set(compact('redirectUrl','next'));
460
			}else{
461
				$dataGiven = json_decode($this->request->data['cart_details']);
18662 manish.sha 462
				$payMethod = $this->request->data['paymethod'];
18633 manish.sha 463
				if(isset($payMethod) && $payMethod=='cap_float'){
464
					$url = Configure::read('saholicapihost').'order?payment_option=456789&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
465
				 	if($pincode!='0'){
466
						$url = $url.'&pinCode='.$pincode;
467
					}
468
					$orderCreationResponse = $this->post_cartinfo_request($url, null);
469
					//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
470
					$redirecturl = $orderCreationResponse['response']['redirectUrl'];
471
					if (strpos($redirecturl,'pay-success') === false) {
472
					    setcookie('txn_comp', 'no', -1, '/');
473
					} else {
474
						$order_det = array();
475
						$this->loadModel('Order');
476
						$order_det['user_id'] = $this->Auth->User('id');
477
						$order_det['store_id'] = 4;
478
						$str = Configure::read('saholicauthurl');
479
						$orderDetailsArgs = explode('/autologin/',$str);
480
						$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
481
						$this->log(print_r($order_det,1),'ordersdet');
482
						$this->Order->create();
483
 
484
						if ($this->Order->save($order_det)) {
485
							$id = $this->Order->getLastInsertID();
486
							$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
487
							$apihost = Configure::read('pythonapihost');
488
							$url = $apihost."storeorder";
489
 
490
							$this->log(print_r($url,1),'ordersdet');
491
 
492
							$this->log(print_r($order,1),'ordersdet');
493
							$response = array();
494
							if(!empty($order)) {
495
								$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']);
496
								$jsonVar = json_encode($params);
497
								$response =  $this->make_request($url,$jsonVar);
498
							}else{
499
								$result = array('success'=>false,'message'=>'Empty order array');
500
								$response = $result;
501
							}
502
							$this->log(print_r('response',1),'ordersdet');
503
							$this->log(print_r($response,1),'ordersdet');
504
							if(!empty($response) && $response['result']) {
505
								if($response['htmlRequired'] == 1) {
506
									$this->loadModel('Rawhtml');
507
									$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
508
									$this->Rawhtml->create();
509
									$this->Rawhtml->save($data);
510
									$this->log(print_r('insideif',1),'ordersdet');
511
									$result =  $response;
512
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
513
								}
514
								else {
515
									$result =array('success'=>true,'message'=> $response['result']);
516
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
517
									$this->log(print_r('insideelse',1),'ordersdet');
518
								}
519
								$this->log(print_r($sql,1),'ordersdet');
520
								$this->Order->query($sql);
521
 
522
							}					
523
						}
524
					}
525
					$this->layout = 'innerpages';
526
					$next = $redirecturl;					
527
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
18768 manish.sha 528
					$redirectToCart = true;
18633 manish.sha 529
					$this->log($redirectUrl,'headers');
18768 manish.sha 530
					$this->set(compact('redirectUrl','next','redirectToCart'));
18633 manish.sha 531
				}else{
532
					$totalSkus= intval($dataGiven->totalSkus);
533
					setcookie('txn_comp', 'no', -1, '/');
534
					$this->layout = 'innerpages';
535
					$next = "payment?cq=".$totalSkus.'&addressid='.$addressid;					
536
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
537
					$this->log($redirectUrl,'headers');
538
					$this->set(compact('redirectUrl','next'));
539
				}
17871 manish.sha 540
			}
18619 amit.gupta 541
		} else {
542
			if($tokenValidated == 0){
543
				$url = '/special/native/login';
544
			}elseif($tokenValidated == -1){
545
				$url = '/abouts/askforupdate';
546
			}
547
			$this->redirect($url);
17871 manish.sha 548
		}
549
	 }
17793 naman 550
}