Subversion Repositories SmartDukaan

Rev

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