Subversion Repositories SmartDukaan

Rev

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