Subversion Repositories SmartDukaan

Rev

Rev 18619 | Rev 18662 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18619 Rev 18633
Line 79... Line 79...
79
			$user_contact = "";
79
			$user_contact = "";
80
			
80
			
81
			$codAvailable = $cartskus['cod'];
81
			$codAvailable = $cartskus['cod'];
82
			$this->Session->write('cod', $codAvailable);
82
			$this->Session->write('cod', $codAvailable);
83
			
83
			
-
 
84
			$creditorAssociated = $response ['creditorAssociated'];
-
 
85
			if(empty($response ['userSanctions'])){
-
 
86
				$creditLimit = 0;
-
 
87
			}else{
-
 
88
				$creditLimit = 0;
-
 
89
				foreach ( $response ['userSanctions'] as $key => $value ) {
-
 
90
					$creditLimit = $creditLimit + intval($response ['credit_limit']) - (intval($response['credit_blocked'])+intval($response['loan']));
-
 
91
				}
-
 
92
			}
-
 
93
			$this->Session->write('creditorAssociated', $creditorAssociated);
-
 
94
			$this->Session->write('creditLimit', $creditLimit);
-
 
95
			$addressEditable = $response ['addressEditable'];
-
 
96
			$this->Session->write('addressEditable', $addressEditable);
-
 
97
			
84
			if(empty($response ['addresses'])){
98
			if(empty($response ['addresses'])){
85
				$this->redirect ( array (
99
				$this->redirect ( array (
86
						'action' => 'add' 
100
						'action' => 'add' 
87
				));
101
				));
88
			}
102
			}
Line 93... Line 107...
93
			$current_address_id = - 1;
107
			$current_address_id = - 1;
94
			$defaultpin = - 1;
108
			$defaultpin = - 1;
95
			$defaultcookiepin = - 1;
109
			$defaultcookiepin = - 1;
96
			$defaultcheckedaddress = - 1;
110
			$defaultcheckedaddress = - 1;
97
			$defaultpinaddress = - 1;
111
			$defaultpinaddress = - 1;
98
			$taxInvoiceCounter = $response ['taxInvoiceCounter'];
-
 
-
 
112
			
99
			foreach ( $response ['addresses'] as $key => $value ) {
113
			foreach ( $response ['addresses'] as $key => $value ) {
100
				// debug($value['']);
-
 
101
				
114
				
102
				if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
115
				if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
103
					$defaultcookiepin = $key;
116
					$defaultcookiepin = $key;
104
					$user_name = $value ['name'];
117
					$user_name = $value ['name'];
105
					$user_contact = $value ['phone'];
118
					$user_contact = $value ['phone'];
Line 145... Line 158...
145
				array_push ( $firstshowaddress, $moreshowaddress [$i] );
158
				array_push ( $firstshowaddress, $moreshowaddress [$i] );
146
			}
159
			}
147
			
160
			
148
			$this->set ( 'address', $response );
161
			$this->set ( 'address', $response );
149
			
162
			
150
			$this->set ( compact ( 'firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'taxInvoiceCounter') );
163
			$this->set ( compact ( 'firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'addressEditable', 'creditorAssociated', 'creditLimit') );
151
		}
164
		}
152
	}
165
	}
153
	public function add($user_name = null, $user_contact = null) {
166
	public function add($user_name = null, $user_contact = null) {
154
		$this->layout = 'cartinnerpages';
167
		$this->layout = 'cartinnerpages';
155
		
168
		
156
		$totalPayable = $_SESSION ['totalPayable'];
169
		$totalPayable = $_SESSION ['totalPayable'];
157
		$codAvailable = $_SESSION ['cod'];
170
		$codAvailable = $_SESSION ['cod'];
-
 
171
		$creditLimit = $_SESSION ['creditLimit'];
-
 
172
		$creditorAssociated = $_SESSION ['creditorAssociated'];
158
		//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
173
		//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
159
		$pinval='';
174
		$pinval='';
160
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
175
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
161
		$scart = base64_decode ( $_COOKIE ['s_cart'] );
176
		$scart = base64_decode ( $_COOKIE ['s_cart'] );
162
		
177
		
Line 225... Line 240...
225
		// debug($getstate);
240
		// debug($getstate);
226
		$getstateval = "";
241
		$getstateval = "";
227
		if ($getstate != "{}") {
242
		if ($getstate != "{}") {
228
			$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
243
			$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
229
		}
244
		}
230
		$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable'));
245
		$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable', 'creditorAssociated', 'creditLimit'));
231
	}
246
	}
232
	public function submitcheck() {
247
	public function submitcheck() {
233
		$this->autoRender = false;
248
		$this->autoRender = false;
234
		$this->request->onlyAllow ( 'ajax' );
249
		$this->request->onlyAllow ( 'ajax' );
235
		
250
		
Line 376... Line 391...
376
					$order_det = array();
391
					$order_det = array();
377
					$this->loadModel('Order');
392
					$this->loadModel('Order');
378
					$order_det['user_id'] = $this->Auth->User('id');
393
					$order_det['user_id'] = $this->Auth->User('id');
379
					$order_det['store_id'] = 4;
394
					$order_det['store_id'] = 4;
380
					$str = Configure::read('saholicauthurl');
395
					$str = Configure::read('saholicauthurl');
-
 
396
					$orderDetailsArgs = explode('/autologin/',$str);
381
					$order_det['order_url'] = explode('/autologin/',$str)[0]."/".$redirecturl;
397
					$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
382
					$this->log(print_r($order_det,1),'ordersdet');
398
					$this->log(print_r($order_det,1),'ordersdet');
383
					$this->Order->create();
399
					$this->Order->create();
384
					
400
					
385
					if ($this->Order->save($order_det)) {
401
					if ($this->Order->save($order_det)) {
386
						$id = $this->Order->getLastInsertID();
402
						$id = $this->Order->getLastInsertID();
Line 429... Line 445...
429
				$redirectUrl = $this->getAutoLoginUrl($userId,$next);
445
				$redirectUrl = $this->getAutoLoginUrl($userId,$next);
430
				$this->log($redirectUrl,'headers');
446
				$this->log($redirectUrl,'headers');
431
				$this->set(compact('redirectUrl','next'));
447
				$this->set(compact('redirectUrl','next'));
432
			}else{
448
			}else{
433
				$dataGiven = json_decode($this->request->data['cart_details']);
449
				$dataGiven = json_decode($this->request->data['cart_details']);
-
 
450
				$payMethod = json_decode($this->request->data['paymethod']);
-
 
451
				if(isset($payMethod) && $payMethod=='cap_float'){
-
 
452
					$url = Configure::read('saholicapihost').'order?payment_option=456789&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
-
 
453
				 	if($pincode!='0'){
-
 
454
						$url = $url.'&pinCode='.$pincode;
-
 
455
					}
-
 
456
					$orderCreationResponse = $this->post_cartinfo_request($url, null);
-
 
457
					//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
-
 
458
					$redirecturl = $orderCreationResponse['response']['redirectUrl'];
-
 
459
					if (strpos($redirecturl,'pay-success') === false) {
-
 
460
					    setcookie('txn_comp', 'no', -1, '/');
-
 
461
					} else {
-
 
462
						$order_det = array();
-
 
463
						$this->loadModel('Order');
-
 
464
						$order_det['user_id'] = $this->Auth->User('id');
-
 
465
						$order_det['store_id'] = 4;
-
 
466
						$str = Configure::read('saholicauthurl');
-
 
467
						$orderDetailsArgs = explode('/autologin/',$str);
-
 
468
						$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
-
 
469
						$this->log(print_r($order_det,1),'ordersdet');
-
 
470
						$this->Order->create();
-
 
471
						
-
 
472
						if ($this->Order->save($order_det)) {
-
 
473
							$id = $this->Order->getLastInsertID();
-
 
474
							$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
-
 
475
							$apihost = Configure::read('pythonapihost');
-
 
476
							$url = $apihost."storeorder";
-
 
477
							
-
 
478
							$this->log(print_r($url,1),'ordersdet');
-
 
479
							
-
 
480
							$this->log(print_r($order,1),'ordersdet');
-
 
481
							$response = array();
-
 
482
							if(!empty($order)) {
-
 
483
								$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']);
-
 
484
								$jsonVar = json_encode($params);
-
 
485
								$response =  $this->make_request($url,$jsonVar);
-
 
486
							}else{
-
 
487
								$result = array('success'=>false,'message'=>'Empty order array');
-
 
488
								$response = $result;
-
 
489
							}
-
 
490
							$this->log(print_r('response',1),'ordersdet');
-
 
491
							$this->log(print_r($response,1),'ordersdet');
-
 
492
							if(!empty($response) && $response['result']) {
-
 
493
								if($response['htmlRequired'] == 1) {
-
 
494
									$this->loadModel('Rawhtml');
-
 
495
									$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
-
 
496
									$this->Rawhtml->create();
-
 
497
									$this->Rawhtml->save($data);
-
 
498
									$this->log(print_r('insideif',1),'ordersdet');
-
 
499
									$result =  $response;
-
 
500
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
-
 
501
								}
-
 
502
								else {
-
 
503
									$result =array('success'=>true,'message'=> $response['result']);
-
 
504
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
-
 
505
									$this->log(print_r('insideelse',1),'ordersdet');
-
 
506
								}
-
 
507
								$this->log(print_r($sql,1),'ordersdet');
-
 
508
								$this->Order->query($sql);
-
 
509
								
-
 
510
							}					
-
 
511
						}
-
 
512
					}
-
 
513
					$this->layout = 'innerpages';
-
 
514
					$next = $redirecturl;					
-
 
515
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
-
 
516
					$this->log($redirectUrl,'headers');
-
 
517
					$this->set(compact('redirectUrl','next'));
-
 
518
				}else{
434
				$totalSkus= intval($dataGiven->totalSkus);
519
					$totalSkus= intval($dataGiven->totalSkus);
435
				setcookie('txn_comp', 'no', -1, '/');
520
					setcookie('txn_comp', 'no', -1, '/');
436
				$this->layout = 'innerpages';
521
					$this->layout = 'innerpages';
437
				$next = "payment?cq=".$totalSkus.'&addressid='.$addressid;					
522
					$next = "payment?cq=".$totalSkus.'&addressid='.$addressid;					
438
				$redirectUrl = $this->getAutoLoginUrl($userId,$next);
523
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
439
				$this->log($redirectUrl,'headers');
524
					$this->log($redirectUrl,'headers');
440
				$this->set(compact('redirectUrl','next'));
525
					$this->set(compact('redirectUrl','next'));
-
 
526
				}
441
			}
527
			}
442
		} else {
528
		} else {
443
			if($tokenValidated == 0){
529
			if($tokenValidated == 0){
444
				$url = '/special/native/login';
530
				$url = '/special/native/login';
445
			}elseif($tokenValidated == -1){
531
			}elseif($tokenValidated == -1){