Subversion Repositories SmartDukaan

Rev

Rev 10582 | Rev 10600 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
3
class Checkout extends MY_Controller {
4
 
5
public $layoutName ='';
6
 
7
	function __construct() {
8
 
9
		// Call the CI_controller constructor
10
		parent::__construct();
11
		$admin = $this->session->userdata('admin');
12
		if(!isset($admin) || empty($admin)) {
13
			redirect(base_url().'authorize');
14
		}
15
		$this->layout->setlayout('layout/layout_main');
16
		$this->load->model('checkout_model');
17
		$this->load->model('captcha_model');
18
		$this->layoutName= $this->layout->getLayout();
19
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
20
			//print_r($this->session->userdata);
21
 
22
 
23
	}
24
	public function index()
25
	{
26
		$authorized = $this->session->userdata('authorized');
27
		if(isset($authorized) and !empty($authorized['id']))
28
		{
29
			//if user logged-in
30
			redirect(base_url().strtolower(__CLASS__).'/shipping');
31
		}
32
 
33
		//standard array
34
		$data = array();
35
		$checkoutconfig = $this->config->item('checkout');
36
		if(!isset($_POST['submit'])){
37
		unset($checkoutconfig['response'][1]);	
38
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$checkoutconfig);
39
		$this->layout->view('checkout/checkout_view',$data);
40
		}
41
		if(isset($_POST['submit'])){
42
			$type = $this->input->post('type');
43
			if($type == "member"){
44
			unset($checkoutconfig['response'][0]);	
45
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$checkoutconfig);
46
			if(isset($data['response']['response']['login_submit']['authorized'])){
47
			$this->session->set_userdata('authorized',$data['response']['response']['login_submit']['authorized']);
48
			$this->session->set_flashdata(array('msg'=>$data['response']['response']['login_submit']['msg']));
49
			redirect(base_url().$data['response']['response']['login_submit']['redirect']);
50
			}
51
			else
52
			{
53
				$this->layout->view(strtolower(__CLASS__).'/checkout_view',$data);
54
			}
55
			}
56
			if($type == 'guest'){
57
				redirect(base_url().strtolower(__CLASS__).'/shipping');	
58
			}
59
			if($type == 'register'){
60
				redirect(base_url().'auth/signup');	
61
			}
62
		}
63
	}
64
	// public function billing()
65
	// {
66
	// 	//standard array
67
	// 	$data = array();
68
 
69
	// 	$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('billing'));
70
	// 	$this->layout->view('checkout/checkout_view',$data);
71
 
72
	// }
73
	public function __paginateList($data=array())
74
	{
75
			//$data['baseSubTotal']=$data['baseSubTotal'];
76
			$data['subTotal'] = $data['subTotal'];
77
			//$data['shippingCharges'] = $data['shippingCharges'];
78
			return $data;	
79
 
80
	}
81
 
82
	public function orderconfirmation()
83
	{
84
		$authorized = $this->session->userdata('authorized');
85
	    if(isset($authorized) && !empty($authorized)){
86
			$_GET['userId'] = $authorized['Id'];
87
			$_GET['Id'] = $authorized['cartId'];
88
			if($authorized['isLoggedIn'] == 1){
89
				$_GET['isLoggedIn'] = 'true';
90
			}
91
		elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
92
				$_GET['isLoggedIn'] = 'false';
93
			}
94
		}
95
    	//die();
96
    	$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
97
        $data['stylesheet'] = 'shipping.css';
98
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('orderconfirmation'));
99
		// $this->session->unset_userdata('shipping');
100
		// $this->session->unset_userdata('billing');
101
		// $this->session->unset_userdata('shoppingId');
102
		$this->session->unset_userdata('hotspotId');
103
		$this->session->unset_userdata('addressId');
104
		$this->layout->view('checkout/checkout_view',$data);
105
	}
106
	public function payment()
107
	{
108
		//standard array
109
		//print_r($this->session->all_userdata())
110
		$authorized = $this->session->userdata('authorized');
111
		if(!isset($authorized) || empty($authorized)){
112
			redirect(base_url()."cart");
113
		}
114
 
115
		$data = array();
116
		$codCaptcha = $this->session->userdata('cod');
117
		if(isset($codCaptcha) && $codCaptcha == 1){
118
			$data['codCaptcha'] = 1;
119
			$this->session->unset_userdata('cod');
120
		}else{
121
			$data['codCaptcha'] = 0;
122
		}
123
		$paymentconfig = $this->config->item('payment');
124
		if(!isset($_POST['submit'])){
125
			$hotspot = $this->session->userdata('hotspotId');
126
			if(isset($hotspot) && !empty($hotspot)){
127
				$_GET['hotSpotAddressId'] = $hotspot;
128
				$_GET['deliveryLocation'] = 'hotSpot';
129
			}else{
130
				$_GET['deliveryLocation'] = 'myLocation';
131
			}
132
			unset($paymentconfig['response'][2]);
133
			if(isset($authorized) && !empty($authorized)){
134
				$_GET['userId'] = $authorized['Id'];
135
				$_GET['Id'] = $authorized['cartId'];
136
				if($authorized['isLoggedIn'] == 1){
137
					$_GET['isLoggedIn'] = 'true';
138
				}
139
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
140
					$_GET['isLoggedIn'] = 'false';
141
				}
142
			}
143
			$addressId = $this->session->userdata('addressId');
144
			$_GET['addressid'] = $addressId;
145
			$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
146
      		$data['stylesheet'] = 'shipping.css';
147
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),'',$paymentconfig);
148
			if(isset($data['response']['response']['payment_process'])){
149
				$result = json_decode($data['response']['response']['payment_process'][0]);
150
				$totalAmount = $result->results->totalAmount;
151
				if(isset($result->results->isTotalAmountZero)){
152
					$isTotalAmountZero = $result->results->isTotalAmountZero;
153
				}
154
				$totalAmount = number_format((float)$totalAmount,0,'.','');
155
				$captcha = $this->captcha_model->generateCaptcha();
156
				$this->session->set_userdata('captcha',$captcha['word']);
157
				$data['captcha'] = $captcha;
158
				// if($totalAmount == 0 && isset($isTotalAmountZero) && $isTotalAmountZero == 1){
159
				// 	$captcha = $this->captcha_model->generateCaptcha();
160
				// 	$this->session->set_userdata('captcha',$captcha['word']);
161
				// 	$this->session->set_userdata('captchaDisplay',$isTotalAmountZero);
162
				// 	$data['captcha'] = $captcha;
163
				// }
164
				$this->layout->view('checkout/checkout_view',$data);
165
			}
166
			else{
167
				redirect(base_url()."cart");
168
			}
169
		}
170
		elseif(isset($_POST['submit'])){
171
			if(isset($_POST['captcha_response_field']) && !empty($_POST['captcha_response_field'])){
172
				$captcha = $this->session->userdata('captcha');
173
				if(strcmp($captcha,$_POST['captcha_response_field']) != 0){
174
					if(isset($_POST['payoption']) && $_POST['payoption'] == 3000){
175
						$this->session->set_userdata('cod',1);
176
					}
177
        			redirect(base_url().'payment');
178
      			}
179
			}
180
			unset($paymentconfig['response'][0]);
181
			unset($paymentconfig['response'][1]);
182
			if(isset($authorized) && !empty($authorized)){
183
				$_POST['userId'] = $authorized['Id'];
184
				if($authorized['isLoggedIn'] == 1){
185
					$_POST['isLoggedIn'] = 'true';
186
				}
187
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
188
					$_POST['isLoggedIn'] = 'false';
189
				}
190
			}
191
			$addressId = $this->session->userdata('addressId');
192
			$_POST['addressid'] = $addressId;
193
			$_POST['payment_option'] = $_POST['payoption'];
194
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
195
			if(isset($data['response']['response']['payment_submit'][0]) && !empty($data['response']['response']['payment_submit'][0])){
196
				$paymentSubmit = $data['response']['response']['payment_submit'][0];
197
				if(isset($paymentSubmit->response->isPaymentRedirect) && $paymentSubmit->response->isPaymentRedirect == 1){
198
					$image = base_url().'/images/loading.gif';
199
					$location = $paymentSubmit->response->redirectUrl;
200
					echo '<html><head><meta http-equiv="refresh" content="2;url='.$paymentSubmit->response->redirectUrl.'">
201
  					<title>Saholic Mobile Site: Redirecting to <'.$paymentSubmit->response->gatewayName.'> Payment Gateway</title>
202
 					</head>
203
 						<body>
204
     					<div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
205
     					<div align="center" class="img">
206
      					<img title="loading" alt="loading" src="'.$image.'">
207
     					</div>
208
 						</body>
209
						</html>';
210
				}elseif(strpos($paymentSubmit->response->redirectUrl, 'ebs-pay') !== false){
211
					$url = $this->config->item('curl_base_url').$paymentSubmit->response->redirectUrl;
212
					//echo $url;
213
					$authorized = $this->session->userdata('authorized');
214
					if(isset($authorized) && !empty($authorized)){
215
						$params['userId'] = $authorized['Id'];
216
						if($authorized['isLoggedIn'] == 1){
217
							$params['isLoggedIn'] = 'true';
218
						}
219
						elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
220
							$params['isLoggedIn'] = 'false';
221
						}
222
					}
223
					$this->mcurl->add_call('ebs','get',$url,$params);
224
         			$response = $this->mcurl->execute($url);
225
         			$data['response'] = $response['ebs']['response'];
226
         			$response = $this->magento_model->payment_submit($data);
227
         			if(isset($response) && !empty($response)){
228
         				$ebs = $response[0]->response;
229
         				echo '<html>
230
						<head>
231
						 <title>m.saholic.com: Redirecting to EBS Payment Page</title>
232
						</head>
233
						<body>
234
						    <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
235
						 <div align="center" class="img">
236
						  <img title="loading" alt="loading" src="'.base_url().'assets/images/loading.gif">
237
						 </div>
238
						 <div style="display:none">
239
						  <form  method="post" action="'.$ebs->postAction.'" name="frmTransaction" id="frmTransaction">  
240
				           <!-- Account Id -->
241
				           <input name="account_id" type="hidden" value="'.$ebs->account_id.'" />
242
				           <!-- Transaction Details -->
243
				           <input name="reference_no" type="hidden" value="'.$ebs->reference_no.'" />
244
				           <input name="amount" type="hidden" value="'.$ebs->amount.'" />
245
				           <input name="description" type="hidden" value="'.$ebs->description.'" />
246
				           <input name="payment_option" type="hidden" value="'.$ebs->payment_option.'"/>
247
				           <!-- Billing Address -->
248
				           <input name="name" type="hidden" value="'.$ebs->name.'" />
249
				           <input name="address" type="hidden" value="'.$ebs->address.'" />
250
				           <input name="city" type="hidden" value="'.$ebs->city.'" />
251
				           <input name="state" type="hidden" value="'.$ebs->state.'" />
252
				           <input name="postal_code" type="hidden" value="'.$ebs->postal_code.'" />
253
				           <input name="country" type="hidden" value="IND"/>
254
				           <input name="email" type="hidden" value="'.$ebs->email.'" />
255
				           <input name="phone" type="hidden" value="'.$ebs->phone.'" />
256
				           <!-- Delivery Address -->
257
				           <input name="ship_name" type="hidden" value="'.$ebs->ship_name.'" />
258
				           <input name="ship_address" type="hidden" value="'.$ebs->ship_address.'" />
259
				           <input name="ship_city" type="hidden" value="'.$ebs->ship_city.'" />
260
				           <input name="ship_state" type="hidden" value="'.$ebs->ship_state.'" />
261
				           <input name="ship_postal_code" type="hidden" value="'.$ebs->ship_postal_code.'" />
262
				           <input name="ship_country" type="hidden" value="IND"/> 
263
				           <input name="ship_phone" type="hidden" value="'.$ebs->ship_phone.'" />
264
				           <input name="return_url" type="hidden" value="'.$ebs->return_url.'" />
265
				           <input name="mode" value="'.$ebs->mode.'"/>
266
				           <input name="secure_hash" type="hidden" value="'.$ebs->secure_hash.'" />
267
				           <input name="channel" type="hidden" value="'.$ebs->channel.'" />
268
				           <input name="page_id" type="hidden" value="'.$ebs->page_id.'" />
269
				           <input name="submitted" value="Submit" type="submit" /> 
270
				           <input value="Reset" type="reset" />
271
						  </form>
272
						    </div>
273
						    <script type="text/javascript">
274
						     document.getElementById("frmTransaction").submit();
275
						    </script>
276
						  </body>
277
						</html>';
278
         			}else{
279
         				redirect(base_url().'payment');
280
         			}
281
				}
282
				else{
283
					redirect(base_url().$paymentSubmit->response->redirectUrl);
284
				}
285
			}
286
			else{
287
			redirect(base_url()."payment");	
288
			}
289
		}
290
 
291
	}
292
	public function ebsprocessing(){
293
		if(isset($_GET['DR']) && !empty($_GET['DR'])){
294
			$paymentconfig = $this->config->item('ebsProcessing');
295
			$authorized = $this->session->userdata('authorized');
296
			if(isset($authorized) && !empty($authorized)){
297
				$_GET['userId'] = $authorized['Id'];
298
				if($authorized['isLoggedIn'] == 1){
299
					$_GET['isLoggedIn'] = 'true';
300
				}
301
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
302
					$_GET['isLoggedIn'] = 'false';
303
				}
304
			}
305
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
306
			if(isset($data['response']['response']['ebs_processing'][0]->response)){
307
				$redirectUrl = $data['response']['response']['ebs_processing'][0]->response->redirectUrl;
308
				$redirectUrl = explode('?', $redirectUrl);
309
				$redirectUrl = base_url().'ebs-pay-response/?'.$redirectUrl[1];
310
				echo '<html><head><meta http-equiv="refresh" content="2;url='.$redirectUrl.'">
311
  					<title>Saholic Mobile Site:</title>
312
 					</head>
313
 						<body>
314
     					<div style="text-align:center; margin-top:200px;">'.$data['response']['response']['ebs_processing'][0]->response->redirectMessage.'</div>
315
     					<div align="center" class="img">
316
      					<img title="loading" alt="loading" src="">
317
     					</div>
318
 						</body>
319
						</html>';
320
			}
321
		}
322
	}
323
	public function ebsresponse(){
324
		if(isset($_GET['DR']) && !empty($_GET['DR'])){
325
			$paymentconfig = $this->config->item('ebsResponse');
326
			$authorized = $this->session->userdata('authorized');
327
			if(isset($authorized) && !empty($authorized)){
328
				$_GET['userId'] = $authorized['Id'];
329
				if($authorized['isLoggedIn'] == 1){
330
					$_GET['isLoggedIn'] = 'true';
331
				}
332
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
333
					$_GET['isLoggedIn'] = 'false';
334
				}
335
			}
336
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
337
			if(isset($data['response']['response']['ebs_response'][0]->response) && !empty($data['response']['response']['ebs_response'][0]->response)){
338
				$redirectUrl = $data['response']['response']['ebs_response'][0]->response->redirectUrl;
339
				redirect($redirectUrl);
340
			}
341
			else{
342
				redirect(base_url().'payment');
343
			}
344
		}
345
	}
346
	public function hdfcPayResponse(){
347
		if(isset($_POST)){
348
			$paymentconfig = $this->config->item('hdfcResponse');
349
			$authorized = $this->session->userdata('authorized');
350
			if(isset($authorized) && !empty($authorized)){
351
				$_POST['userId'] = $authorized['Id'];
352
				if($authorized['isLoggedIn'] == 1){
353
					$_POST['isLoggedIn'] = 'true';
354
				}
355
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
356
					$_POST['isLoggedIn'] = 'false';
357
				}
358
			}
359
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
360
			if(isset($data['response']['response']['hdfc_response'][0]->response) && !empty($data['response']['response']['hdfc_response'][0]->response)){
361
				$redirectUrl = $data['response']['response']['hdfc_response'][0]->response->redirectUrl;
362
				redirect($redirectUrl);
363
			}
364
			else{
365
				redirect(base_url());
366
			}	
367
		}else{
368
			redirect(base_url());
369
		}
370
	}
371
	public function innovitiPayment(){
372
		$last = $this->uri->total_segments();
373
		$itemcode = $this->uri->segment($last);
374
		if(isset($itemcode) && !empty($itemcode)){
375
			$url = $this->config->item('curl_base_url').'innoviti-pay/'.$itemcode;
376
			$params = array();
377
			$authorized = $this->session->userdata('authorized');
378
			if(isset($authorized) && !empty($authorized)){
379
				$params['userId'] = $authorized['Id'];
380
				if($authorized['isLoggedIn'] == 1){
381
					$params['isLoggedIn'] = 'true';
382
				}
383
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
384
					$params['isLoggedIn'] = 'false';
385
				}
386
			$this->mcurl->add_call('innoviti','get',$url,$params);
387
 			$response = $this->mcurl->execute($url);
388
 			$data['response'] = $response['innoviti']['response'];
389
         	$response = $this->magento_model->payment_submit($data);
390
         	if(isset($response) && !empty($response)){
391
         		$innoviti = $response[0]->response;
10592 lgm 392
         		echo '
393
         			<div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
394
						 <div align="center" class="img">
395
						  <img title="loading" alt="loading" src="../assets/images/loading.gif">
396
						 </div>
397
         			<form  method="post" action="'.$innoviti->action.'" name="frmTransaction" id="frmTransaction">  
10582 lgm 398
           				<input name="merchantId" type="hidden" value="'.$innoviti->merchantId.'" />
399
     					<input name="subMerchantId" type="hidden" value="'.$innoviti->subMerchantId.'" />
400
           				<!-- Transaction Details -->
401
           				<input name="orderId" type="hidden" value="'.$innoviti->orderId.'" />
402
     					<input name="amt" type="hidden" value="'.$innoviti->amt.'" />   
403
     					<input name="cur" type="hidden" value="INR" />
404
     					<input name="processingCode" type="hidden" value="'.$innoviti->processingCode.'" />
405
     					<input name="proSku" type="hidden" value="'.$innoviti->proSku.'" />
406
           				<input name="Cname" type="hidden" value="'.$innoviti->Cname.'" /></td>
407
     					<input name="mobile" type="hidden" value="'.$innoviti->mobile.'" />
408
     					<input name="emailId" type="hidden" value="'.$innoviti->emailId.'" />     
409
   						<input name="redirUrl" type="hidden" value="'.$innoviti->redirUrl.'" />
410
     					<input name="chksum" type="hidden" value="'.$innoviti->chksum.'" />
411
     					<input name="isCtx" type="hidden" value="NO" />
412
           				<script type="text/javascript">
413
						    document.getElementById("frmTransaction").submit();
414
						</script>
415
      				  </form>';
416
         	}
417
			}else{
418
				redirect(base_url());
419
			}
420
 
421
		}else{
422
			redirect(base_url());
423
		}
424
	}
425
	public function innovitiResponse(){
426
		if(isset($_POST)){
427
			$paymentconfig = $this->config->item('innovitiResponse');
428
			$authorized = $this->session->userdata('authorized');
429
			if(isset($authorized) && !empty($authorized)){
430
				$_POST['userId'] = $authorized['Id'];
431
				if($authorized['isLoggedIn'] == 1){
432
					$_POST['isLoggedIn'] = 'true';
433
				}
434
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
435
					$_POST['isLoggedIn'] = 'false';
436
				}
437
			}
438
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
439
			if(isset($data['response']['response']['innoviti_response'][0]->response) && !empty($data['response']['response']['innoviti_response'][0]->response)){
440
				$redirectUrl = $data['response']['response']['innoviti_response'][0]->response->redirectUrl;
441
				redirect($redirectUrl);
442
			}
443
			else{
444
				redirect(base_url());
445
			}	
446
		}else{
447
			redirect(base_url());
448
		}
449
	}
450
	public function paymenterror(){
451
			$authorized = $this->session->userdata('authorized');
452
			if(isset($authorized) && !empty($authorized)){
453
				$data = array();
454
				$paymentconfig = $this->config->item('paymenterror');
455
				$data['stylesheet'] = 'shipping.css';
456
				$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
457
				$this->layout->view('checkout/checkout_view',$data);
458
			}else{
459
				redirect(base_url());
460
			}
461
	}
462
	public function shipping()
463
	{
464
 
465
		$data = array();
466
		$authorized = $this->session->userdata('authorized');
467
		if($authorized['isLoggedIn'] != 1){
468
			$this->session->set_userdata('location','shipping');
469
			redirect(base_url()."login");
470
		}
471
		$shippingconfig = $this->config->item('shipping');
472
		if(!isset($_POST['submit']))
473
		{
474
			$authorized = $this->session->userdata('authorized');
475
				if(isset($authorized) && !empty($authorized)){
476
					$_GET['userId'] = $authorized['Id'];
477
					$_GET['Id'] = $authorized['cartId'];
478
					if($authorized['isLoggedIn'] == 1){
479
						$_GET['isLoggedIn'] = 'true';
480
					}
481
					elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
482
						$_GET['isLoggedIn'] = 'false';
483
					}
484
				}
485
			$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
486
			$data['stylesheet'] = 'shipping.css';
487
			$cache = getFileCache('pickup');
488
			if(isset($cache) && !empty($cache)){
489
				unset($shippingconfig['response'][1]);
490
				$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
491
				$data['response']['response']['pickup'] = $cache;
492
			}else{
493
				$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
494
        		if(isset($data['response']['response']['pickup']) && !empty($data['response']['response']['pickup']))
495
        		setFileCache($data['response']['response']['pickup'], 'pickup',900);
496
			}
497
			$this->layout->view('checkout/checkout_view',$data);
498
		}
499
		if(isset($_POST['submit']))
500
		{
501
			unset($shippingconfig['response'][1]);	
502
			$data = $this->get_shipping_billing($_POST);
503
			$this->session->set_userdata($data);
504
			$authorized = $this->session->userdata('authorized');
505
			if(isset($authorized) && !empty($authorized)){
506
				$_POST['userId'] = $authorized['Id'];
507
				//$_POST['Id'] = $authorized['cartId'];
508
					if($authorized['isLoggedIn'] == 1){
509
						$_POST['isLoggedIn'] = 'true';
510
					}
511
					elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
512
						$_POST['isLoggedIn'] = 'false';
513
					}
514
				}
515
			//$data['stylesheet'] = 'shipping.less';
516
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
517
			//$this->layout->view('checkout/checkout_view',$data);
518
			redirect(base_url()."shipping");
519
 
520
		}
521
 
522
	}
523
	public function shippingmode()
524
	{
525
		$data = array();
526
		$shippingconfig = $this->config->item('shippingmethod');
527
		if(!isset($_POST['submit']))
528
		{
529
			unset($shippingconfig['response'][1]);
530
			$data['response']['address']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
531
			$this->layout->view('checkout/checkout_view',$data);
532
		}
533
		if(isset($_POST['submit']))
534
		{
535
			unset($shippingconfig['response'][0]);
536
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
537
			if($data['response']['response']['shippingmethod_submit'][0] == 1){
538
			redirect(base_url().strtolower(__CLASS__)."/payment");
539
			}
540
			else{
541
			redirect(base_url().strtolower(__CLASS__)."/shippingmode");	
542
			}
543
 
544
		}
545
	}
546
	public function review()
547
	{
548
		//standard array
549
		$authorized = $this->session->userdata('authorized');
550
		if(isset($authorized) and !empty($authorized['id']))
551
		{
552
			//if user logged-in
553
			$_GET['customerId'] = $authorized['id'];
554
		}
555
		$data = array();
556
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('review'));
557
		if(isset($data['response']['response']['review_process']) && !empty($data['response']['response']['review_process'])){
558
		$this->layout->view('checkout/checkout_view',$data);
559
		}
560
		else{
561
			redirect(base_url().strtolower(__CLASS__)."/shipping");
562
		}
563
	}
564
 
565
	public function get_shipping_billing($data=array()){
566
		$billing =array();
567
		$shipping =array();
568
		if (isset($data) && !empty($data)) {
569
			$shipping=array('name'  => $data['name'],'line1' => $data['line1'],'line2' => $data['line2'], 'city' => $data['city'], 'pin' => $data['pin'], 'phonenumber' => $data['phone']);
570
			return array('shipping'=>$shipping,'billing'=>$billing);
571
		}
572
	}
573
 
574
	public function delete($addressId){
575
		$shippingconfig = $this->config->item('shipping_delete');
576
		$_GET['addressId'] = $addressId;
577
		$authorized = $this->session->userdata('authorized');
578
		if(isset($authorized) && !empty($authorized)){
579
			$_GET['userId'] = $authorized['Id'];
580
			$_GET['Id'] = $authorized['cartId'];
581
			if($authorized['isLoggedIn'] == 1){
582
				$_GET['isLoggedIn'] = 'true';
583
			}
584
			elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
585
				$_GET['isLoggedIn'] = 'false';
586
				}
587
			}
588
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
589
			print_r($data['response']);
590
		}
591
 
592
	public function changeAddress($addressId,$type){
593
		if(isset($addressId) && isset($type)){
594
		$shippingconfig = $this->config->item('shipping_change');
595
		$_GET['addressId'] = $addressId;
596
		$_GET['addressType'] = $type;
597
		$authorized = $this->session->userdata('authorized');
598
		if(isset($authorized) && !empty($authorized)){
599
			$_GET['userId'] = $authorized['Id'];
600
			$_GET['Id'] = $authorized['cartId'];
601
			if($authorized['isLoggedIn'] == 1){
602
				$_GET['isLoggedIn'] = 'true';
603
			}
604
			elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
605
				$_GET['isLoggedIn'] = 'false';
606
				}
607
			}
608
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
609
			$this->session->set_userdata('addressId',$addressId);
610
			print_r($data['response']['response']['changeAddress'][0]->message);
611
		}
612
	}
613
	public function changeCaptcha(){
614
		$captchaDisplay = $this->session->userdata('captchaDisplay');
615
		//if(isset($captchaDisplay) && $captchaDisplay == 1){
616
			$captcha = $this->captcha_model->generateCaptcha();
617
			$this->session->set_userdata('captcha',$captcha['word']);
618
			unset($captcha['word']);
619
			unset($captcha['time']);
620
			unset($captcha['name']);
621
			echo json_encode($captcha);
622
		//}
623
	}
624
	public function insuranceInfo($bday,$gname,$addressId){
625
	if((isset($bday) && !empty($bday)) && (isset($gname) && !empty($gname)) && (isset($addressId) && !empty($addressId))){
626
		if(isset($gname) && !empty($gname)){
627
			$gname = str_replace('-','',$gname);
628
			$gname = ltrim($gname);
629
			$gname = rtrim($gname);
630
			$_GET['guardianName'] = $gname;
631
		}
632
		if(isset($bday) && !empty($bday)){
633
			$dob = explode('-',$bday);
634
			$dob = array_reverse($dob);
635
			$temp1 = $dob[1];
636
			$temp2 = $dob[0];
637
			$dob[0] = $temp1;
638
			$dob[1] = $temp2;
639
			$dob = implode('/', $dob);
640
			$_GET['dob'] = $dob; 
641
		}
642
		$insuranceconfig = $this->config->item('insurance_info');
643
		$_GET['addressId'] = $addressId;
644
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$insuranceconfig);
645
		if(isset($data['response']['response']['insuranceInfo'][0]->response) && (!empty($data['response']['response']['insuranceInfo'][0]->response))) {
646
			echo json_encode($data['response']['response']['insuranceInfo'][0]);
647
		}
648
	}
649
  }
650
  public function pickupSpot($id){
651
  	if(isset($id) && !empty($id) && is_numeric($id)){
652
  		$this->session->set_userdata('hotspotId',$id);
653
  		$response['msg'] = 'sucess';
654
  		echo json_encode($response);
655
  	}
656
  }
657
 
658
}
659
 
660
 
661
/* End of file welcome.php */
662
/* Location: ./application/controllers/welcome.php */