Subversion Repositories SmartDukaan

Rev

Rev 12694 | Details | Compare with Previous | Last modification | View Log | RSS feed

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