Subversion Repositories SmartDukaan

Rev

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