Subversion Repositories SmartDukaan

Rev

Rev 18834 | Rev 18865 | 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';
344
		if ($cartskus ['maxEstimate'] == - 1) {
345
			$checkestimate = 'false';
346
		} else {
347
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 348
				if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
349
					continue;
350
				}
351
				$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
352
				if ($estimate==-1) {
17882 naman 353
					$checkestimate = 'false';
354
					break;
355
				}
356
			}
357
		}
358
 
359
		return $checkestimate;
360
	}
361
 
17871 manish.sha 362
	 public function checkout(){
18662 manish.sha 363
	 	$addressid = $this->request->data['addressid'];
17846 manish.sha 364
	 	$pincode = 0;
17871 manish.sha 365
		$cod = $this->request->query('cod');
17846 manish.sha 366
		$userId = $this->request->query('user_id');
367
 
18619 amit.gupta 368
		//Added token validation to ensure only user 
18834 manish.sha 369
		$testCheck = Configure::read('requireusercheck');
18832 manish.sha 370
		$tokenValidated = 0;
371
		if($testCheck){
18834 manish.sha 372
			$tokenValidated = $this->checkToken($userId);
18832 manish.sha 373
		}else{
18834 manish.sha 374
			$tokenValidated = 1;
18832 manish.sha 375
		}
376
 
18834 manish.sha 377
		if(!empty($userId) && $tokenValidated==1){			
18619 amit.gupta 378
			$url = $this->getAutoLoginUrl($userId,$url);
379
 
380
			if(isset($this->request->data->pincode)){
381
				$pincode = $this->request->data->pincode;
17871 manish.sha 382
			}
18619 amit.gupta 383
			if($pincode==0 && isset($_COOKIE['s_pincode'])){
384
				$pincode = base64_decode($_COOKIE['s_pincode']);
385
			}
386
 
387
			$suserId = base64_decode($_COOKIE['s_id']);
388
			$scartId = base64_decode($_COOKIE['s_cart']);
389
			$semailId = base64_decode($_COOKIE['s_email']);
390
 
391
			if(isset($_COOKIE['txn_comp'])) {
392
				unset($_COOKIE['txn_comp']);
393
			}
394
 
395
			if($cod==1){
396
				$url = Configure::read('saholicapihost').'order?payment_option=3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
397
			 	if($pincode!='0'){
398
					$url = $url.'&pinCode='.$pincode;
399
				}
400
				$orderCreationResponse = $this->post_cartinfo_request($url, null);
401
				//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
402
				$redirecturl = $orderCreationResponse['response']['redirectUrl'];
403
				if (strpos($redirecturl,'pay-success') === false) {
404
				    setcookie('txn_comp', 'no', -1, '/');
405
				} else {
406
					$order_det = array();
407
					$this->loadModel('Order');
408
					$order_det['user_id'] = $this->Auth->User('id');
409
					$order_det['store_id'] = 4;
410
					$str = Configure::read('saholicauthurl');
18633 manish.sha 411
					$orderDetailsArgs = explode('/autologin/',$str);
412
					$order_det['order_url'] = $orderDetailsArgs[0]."/".$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';
459
				$next = $redirecturl;					
460
				$redirectUrl = $this->getAutoLoginUrl($userId,$next);
461
				$this->log($redirectUrl,'headers');
462
				$this->set(compact('redirectUrl','next'));
463
			}else{
464
				$dataGiven = json_decode($this->request->data['cart_details']);
18662 manish.sha 465
				$payMethod = $this->request->data['paymethod'];
18633 manish.sha 466
				if(isset($payMethod) && $payMethod=='cap_float'){
467
					$url = Configure::read('saholicapihost').'order?payment_option=456789&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
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;
481
						$str = Configure::read('saholicauthurl');
482
						$orderDetailsArgs = explode('/autologin/',$str);
483
						$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
484
						$this->log(print_r($order_det,1),'ordersdet');
485
						$this->Order->create();
486
 
487
						if ($this->Order->save($order_det)) {
488
							$id = $this->Order->getLastInsertID();
489
							$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
490
							$apihost = Configure::read('pythonapihost');
491
							$url = $apihost."storeorder";
492
 
493
							$this->log(print_r($url,1),'ordersdet');
494
 
495
							$this->log(print_r($order,1),'ordersdet');
496
							$response = array();
497
							if(!empty($order)) {
498
								$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']);
499
								$jsonVar = json_encode($params);
500
								$response =  $this->make_request($url,$jsonVar);
501
							}else{
502
								$result = array('success'=>false,'message'=>'Empty order array');
503
								$response = $result;
504
							}
505
							$this->log(print_r('response',1),'ordersdet');
506
							$this->log(print_r($response,1),'ordersdet');
507
							if(!empty($response) && $response['result']) {
508
								if($response['htmlRequired'] == 1) {
509
									$this->loadModel('Rawhtml');
510
									$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
511
									$this->Rawhtml->create();
512
									$this->Rawhtml->save($data);
513
									$this->log(print_r('insideif',1),'ordersdet');
514
									$result =  $response;
515
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
516
								}
517
								else {
518
									$result =array('success'=>true,'message'=> $response['result']);
519
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
520
									$this->log(print_r('insideelse',1),'ordersdet');
521
								}
522
								$this->log(print_r($sql,1),'ordersdet');
523
								$this->Order->query($sql);
524
 
525
							}					
526
						}
527
					}
528
					$this->layout = 'innerpages';
529
					$next = $redirecturl;					
530
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
18768 manish.sha 531
					$redirectToCart = true;
18633 manish.sha 532
					$this->log($redirectUrl,'headers');
18768 manish.sha 533
					$this->set(compact('redirectUrl','next','redirectToCart'));
18633 manish.sha 534
				}else{
535
					$totalSkus= intval($dataGiven->totalSkus);
536
					setcookie('txn_comp', 'no', -1, '/');
537
					$this->layout = 'innerpages';
538
					$next = "payment?cq=".$totalSkus.'&addressid='.$addressid;					
539
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
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
}