Subversion Repositories SmartDukaan

Rev

Rev 18862 | Rev 19035 | 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 = '';
18862 manish.sha 293
		} 
294
		else if ($cartskus ['maxEstimate'] == - 2) {
295
			$checkestimate = 'non_service';
17882 naman 296
		} else {
297
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 298
				if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
299
					continue;
300
				}
301
				$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
302
				if ($estimate==-1) {
17893 amit.gupta 303
					$checkestimate = '';
17882 naman 304
					break;
305
				}
306
			}
307
		}
308
 
309
		return $checkestimate;
310
	}
311
	public function getstate($pin_val) {
312
		$this->autoRender = false;
313
		$this->request->onlyAllow ( 'ajax' );
314
		$url = $this->apihost . "pincodeValidation/" . $pin_val;
315
		$getstate = $this->make_request ( $url, null );
316
		// $getstate['state'] = ucwords(strtolower($getstate['state']));
17844 naman 317
		$nothing = "nothing";
17882 naman 318
		if ($getstate != "{}") {
319
			$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );
17844 naman 320
		}
17882 naman 321
		return json_encode ( $getstate );
322
	}
323
	public function isServicable($pin) {
324
		$this->autoRender = false;
325
		$this->request->onlyAllow ( 'ajax' );
17793 naman 326
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
327
		// $response = $this->make_request($url,null);
17882 naman 328
 
329
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
330
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
331
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
332
		$blank = array ();
333
		$postData = array (
334
				'cartItems' => $blank 
335
		);
336
 
337
		$params = array (
338
				'cartMap' => urlencode ( json_encode ( $postData ) ) 
339
		);
340
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
341
		$url = $url . '&pinCode=' . $pin;
342
		$cartskus = $this->post_cartinfo_request ( $url, $params );
343
		$checkestimate = 'true';
18865 manish.sha 344
		if ($cartskus ['maxEstimate'] == -1) {
17882 naman 345
			$checkestimate = 'false';
18865 manish.sha 346
		} 
347
		else if ($cartskus ['maxEstimate'] == -2) {
348
			$checkestimate = 'false';
349
		} 
350
		else {
17882 naman 351
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 352
				if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
353
					continue;
354
				}
355
				$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
356
				if ($estimate==-1) {
17882 naman 357
					$checkestimate = 'false';
358
					break;
359
				}
360
			}
361
		}
362
 
363
		return $checkestimate;
364
	}
365
 
17871 manish.sha 366
	 public function checkout(){
18662 manish.sha 367
	 	$addressid = $this->request->data['addressid'];
17846 manish.sha 368
	 	$pincode = 0;
17871 manish.sha 369
		$cod = $this->request->query('cod');
17846 manish.sha 370
		$userId = $this->request->query('user_id');
371
 
18619 amit.gupta 372
		//Added token validation to ensure only user 
18834 manish.sha 373
		$testCheck = Configure::read('requireusercheck');
18832 manish.sha 374
		$tokenValidated = 0;
375
		if($testCheck){
18834 manish.sha 376
			$tokenValidated = $this->checkToken($userId);
18832 manish.sha 377
		}else{
18834 manish.sha 378
			$tokenValidated = 1;
18832 manish.sha 379
		}
380
 
18834 manish.sha 381
		if(!empty($userId) && $tokenValidated==1){			
18619 amit.gupta 382
			$url = $this->getAutoLoginUrl($userId,$url);
383
 
384
			if(isset($this->request->data->pincode)){
385
				$pincode = $this->request->data->pincode;
17871 manish.sha 386
			}
18619 amit.gupta 387
			if($pincode==0 && isset($_COOKIE['s_pincode'])){
388
				$pincode = base64_decode($_COOKIE['s_pincode']);
389
			}
390
 
391
			$suserId = base64_decode($_COOKIE['s_id']);
392
			$scartId = base64_decode($_COOKIE['s_cart']);
393
			$semailId = base64_decode($_COOKIE['s_email']);
394
 
395
			if(isset($_COOKIE['txn_comp'])) {
396
				unset($_COOKIE['txn_comp']);
397
			}
398
 
399
			if($cod==1){
400
				$url = Configure::read('saholicapihost').'order?payment_option=3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
401
			 	if($pincode!='0'){
402
					$url = $url.'&pinCode='.$pincode;
403
				}
404
				$orderCreationResponse = $this->post_cartinfo_request($url, null);
405
				//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
406
				$redirecturl = $orderCreationResponse['response']['redirectUrl'];
407
				if (strpos($redirecturl,'pay-success') === false) {
408
				    setcookie('txn_comp', 'no', -1, '/');
409
				} else {
410
					$order_det = array();
411
					$this->loadModel('Order');
412
					$order_det['user_id'] = $this->Auth->User('id');
413
					$order_det['store_id'] = 4;
414
					$str = Configure::read('saholicauthurl');
18633 manish.sha 415
					$orderDetailsArgs = explode('/autologin/',$str);
416
					$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
18619 amit.gupta 417
					$this->log(print_r($order_det,1),'ordersdet');
418
					$this->Order->create();
18613 naman 419
 
18619 amit.gupta 420
					if ($this->Order->save($order_det)) {
421
						$id = $this->Order->getLastInsertID();
422
						$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
423
						$apihost = Configure::read('pythonapihost');
424
						$url = $apihost."storeorder";
425
 
426
						$this->log(print_r($url,1),'ordersdet');
427
 
428
						$this->log(print_r($order,1),'ordersdet');
429
						$response = array();
430
	// 					$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']);
431
						if(!empty($order)) {
432
							$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']);
433
							$jsonVar = json_encode($params);
434
							$response =  $this->make_request($url,$jsonVar);
435
						}else{
436
							$result = array('success'=>false,'message'=>'Empty order array');
437
							$response = $result;
438
						}
439
						$this->log(print_r('response',1),'ordersdet');
440
						$this->log(print_r($response,1),'ordersdet');
441
						if(!empty($response) && $response['result']) {
442
							if($response['htmlRequired'] == 1) {
443
								$this->loadModel('Rawhtml');
444
								$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
445
								$this->Rawhtml->create();
446
								$this->Rawhtml->save($data);
447
								$this->log(print_r('insideif',1),'ordersdet');
448
								$result =  $response;
449
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
450
							}
451
							else {
452
								$result =array('success'=>true,'message'=> $response['result']);
453
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
454
								$this->log(print_r('insideelse',1),'ordersdet');
455
							}
456
							$this->log(print_r($sql,1),'ordersdet');
457
							$this->Order->query($sql);
458
 
459
						}					
18613 naman 460
					}
461
				}
18619 amit.gupta 462
				$this->layout = 'innerpages';
463
				$next = $redirecturl;					
464
				$redirectUrl = $this->getAutoLoginUrl($userId,$next);
465
				$this->log($redirectUrl,'headers');
466
				$this->set(compact('redirectUrl','next'));
467
			}else{
468
				$dataGiven = json_decode($this->request->data['cart_details']);
18662 manish.sha 469
				$payMethod = $this->request->data['paymethod'];
18633 manish.sha 470
				if(isset($payMethod) && $payMethod=='cap_float'){
471
					$url = Configure::read('saholicapihost').'order?payment_option=456789&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
472
				 	if($pincode!='0'){
473
						$url = $url.'&pinCode='.$pincode;
474
					}
475
					$orderCreationResponse = $this->post_cartinfo_request($url, null);
476
					//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
477
					$redirecturl = $orderCreationResponse['response']['redirectUrl'];
478
					if (strpos($redirecturl,'pay-success') === false) {
479
					    setcookie('txn_comp', 'no', -1, '/');
480
					} else {
481
						$order_det = array();
482
						$this->loadModel('Order');
483
						$order_det['user_id'] = $this->Auth->User('id');
484
						$order_det['store_id'] = 4;
485
						$str = Configure::read('saholicauthurl');
486
						$orderDetailsArgs = explode('/autologin/',$str);
487
						$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
488
						$this->log(print_r($order_det,1),'ordersdet');
489
						$this->Order->create();
490
 
491
						if ($this->Order->save($order_det)) {
492
							$id = $this->Order->getLastInsertID();
493
							$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
494
							$apihost = Configure::read('pythonapihost');
495
							$url = $apihost."storeorder";
496
 
497
							$this->log(print_r($url,1),'ordersdet');
498
 
499
							$this->log(print_r($order,1),'ordersdet');
500
							$response = array();
501
							if(!empty($order)) {
502
								$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']);
503
								$jsonVar = json_encode($params);
504
								$response =  $this->make_request($url,$jsonVar);
505
							}else{
506
								$result = array('success'=>false,'message'=>'Empty order array');
507
								$response = $result;
508
							}
509
							$this->log(print_r('response',1),'ordersdet');
510
							$this->log(print_r($response,1),'ordersdet');
511
							if(!empty($response) && $response['result']) {
512
								if($response['htmlRequired'] == 1) {
513
									$this->loadModel('Rawhtml');
514
									$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
515
									$this->Rawhtml->create();
516
									$this->Rawhtml->save($data);
517
									$this->log(print_r('insideif',1),'ordersdet');
518
									$result =  $response;
519
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
520
								}
521
								else {
522
									$result =array('success'=>true,'message'=> $response['result']);
523
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
524
									$this->log(print_r('insideelse',1),'ordersdet');
525
								}
526
								$this->log(print_r($sql,1),'ordersdet');
527
								$this->Order->query($sql);
528
 
529
							}					
530
						}
531
					}
532
					$this->layout = 'innerpages';
533
					$next = $redirecturl;					
534
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
18768 manish.sha 535
					$redirectToCart = true;
18633 manish.sha 536
					$this->log($redirectUrl,'headers');
18768 manish.sha 537
					$this->set(compact('redirectUrl','next','redirectToCart'));
18633 manish.sha 538
				}else{
539
					$totalSkus= intval($dataGiven->totalSkus);
540
					setcookie('txn_comp', 'no', -1, '/');
541
					$this->layout = 'innerpages';
542
					$next = "payment?cq=".$totalSkus.'&addressid='.$addressid;					
543
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
544
					$this->log($redirectUrl,'headers');
545
					$this->set(compact('redirectUrl','next'));
546
				}
17871 manish.sha 547
			}
18619 amit.gupta 548
		} else {
549
			if($tokenValidated == 0){
550
				$url = '/special/native/login';
551
			}elseif($tokenValidated == -1){
552
				$url = '/abouts/askforupdate';
553
			}
554
			$this->redirect($url);
17871 manish.sha 555
		}
556
	 }
17793 naman 557
}