Subversion Repositories SmartDukaan

Rev

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