Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
17793 naman 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ShippingsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->apihost = Configure::read('pythonapihost');
21
		$this->mobileapihost = Configure::read('saholicapihost');
17838 manish.sha 22
		$this->Auth->allow('isServicable');
17793 naman 23
	}
24
 
25
 
26
	public function index(){
27
		$userId = $this->Auth->User('id');
17838 manish.sha 28
		$dataGiven = json_decode($this->request->data['cart_details']);
17793 naman 29
		if ($this->request->is('post')) {
30
			$data = $this->request->data;
31
		}
17871 manish.sha 32
 
17838 manish.sha 33
		$suserId = base64_decode($_COOKIE['s_id']);
17871 manish.sha 34
		$scartId = base64_decode($_COOKIE['s_cart']);
35
		$semailId = base64_decode($_COOKIE['s_email']);
36
 
37
		$pincode = 0;
38
 
39
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
40
			$pincode = base64_decode($_COOKIE['s_pincode']);
17793 naman 41
		}
17838 manish.sha 42
 
17871 manish.sha 43
		$cartItems = array();
44
 
45
		foreach ($dataGiven->cartItems as $key=>$obj) {
46
		    $itemobj = array(
47
					'itemId'   => $key,
48
		    		'quantity' => $obj->quantity);
49
			array_push($cartItems, $itemobj);
17838 manish.sha 50
		}
17871 manish.sha 51
		$postData = array(
52
					'cartItems'	=>	$cartItems
53
					);
54
 
55
		$params = array(
56
				'cartMap' => urlencode(json_encode($postData)));
17838 manish.sha 57
 
17871 manish.sha 58
		$this->layout = 'cartinnerpages';
59
		$url = Configure::read('saholicapihost').'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId;
60
		if($pincode!='0'){
61
			$url = $url.'&pinCode='.$pincode;
62
		}
63
		$cartskus = $this->post_cartinfo_request($url,$params);
64
		if(isset($cartskus['response']) && $cartskus['response']=='error'){
65
			$this->set(compact('cartskus'));
66
			$this->render('/Users/cartdetails');
67
 
68
		}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
69
			setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
70
			$this->set(compact('cartskus'));
71
			$this->render('/Users/cartdetails');
72
		}else{
73
			$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
74
			$this->Session->write('totalPayable', $totalPayable);
75
			$this->layout = 'innerpages';
76
			$suserId = base64_decode($_COOKIE['s_id']);
77
			$url = Configure::read('saholicapihost').'address?isLoggedIn=true&privateDealUser=true&userId='.$suserId;
78
			$response = $this->make_request($url,null);
79
			//debug($response);
80
			if(empty($response['addresses'])){
81
				$this->redirect(array('action' => 'add'));
17793 naman 82
			}
17871 manish.sha 83
 
84
			$firstshowaddress = array();
85
 
86
			$defaultaddressid = $response['defaultAddress'];
87
			if(!empty($defaultaddressid)){
88
				$defaultaddressid = intval($defaultaddressid);
89
			}else{
90
				$defaultaddressid = -1;
17793 naman 91
			}
17871 manish.sha 92
 
93
			$defaultAddress = array();
94
			$similarAddress = array();
95
			$otherAddress = array();
96
			$defaultPinAddress = array();
97
			$defaultAddressFound = false;
98
 
99
			foreach ($response['addresses'] as $key => $value) {
100
				if($defaultaddressid>-1 && $value['id']==$defaultaddressid && $value['pin']== $pincode){
101
					array_push($defaultAddress, $value);
102
					$defaultAddressFound = true;
103
				}
104
				else if($value['pin']== $pincode){
105
					array_push($similarAddress, $value);
106
					$defaultAddressFound = true;
107
				}
108
				else if($value['id'] == $defaultaddressid)
109
				{
110
					array_push($defaultPinAddress, $value);
111
				}	
112
				else{
113
					array_push($otherAddress, $value);
114
				}
115
			}
116
			for($i= 0; $i<count($defaultAddress);$i++)
17793 naman 117
			{
17871 manish.sha 118
				array_push($firstshowaddress,$defaultAddress[$i]);
17793 naman 119
			}
17871 manish.sha 120
			for($i= 0; $i<count($similarAddress);$i++)
121
			{
122
				array_push($firstshowaddress,$similarAddress[$i]);
123
			}
124
			for($i= 0; $i<count($defaultPinAddress);$i++)
125
			{
126
				array_push($firstshowaddress,$defaultPinAddress[$i]);
127
			}
128
			for($i= 0; $i<count($otherAddress);$i++)
129
			{
130
				array_push($firstshowaddress,$otherAddress[$i]);
131
			}
132
 
133
			$this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
17793 naman 134
		}
135
 
17871 manish.sha 136
 
17793 naman 137
	}
138
 
139
	public function add() {
140
		$this->layout = 'innerpages';
141
		$pinval = 232104;
142
		setcookie('pin', $pinval, -1, '/');
17844 naman 143
		$nameval = "Roman";
17793 naman 144
		setcookie('name', $nameval, -1, '/');
145
 
146
		if ($this->request->is('post')) {
147
			$data = $this->request->data;
148
			if($data['name'] == "")
149
			{
150
				$senddata['name'] = $_COOKIE['name'];	
151
			}
152
			else
153
			{
154
				$senddata['name'] = $data['name'];	
155
			}
156
 
157
			$senddata['line1'] = $data['line1'];
158
			$senddata['line2'] = "";
159
			$senddata['city'] = $data['city'];
160
			$senddata['state'] = $data['state'];
161
			if($data['pin'] == "")
162
			{
163
				$senddata['pin'] = $_COOKIE['pin'];	
164
			}
165
			else
166
			{
167
				$senddata['pin'] = $data['pin'];	
168
			}
169
			$senddata['phone'] = $data['phone'];
170
			$senddata['country'] = 'India';
171
			// debug($senddata);
172
			$url  = "http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true&cartId=41&isPrivateDealUser=true";
173
			$response = $this->post_request($url,$senddata);
174
			$this->redirect(array('action' => 'index'));
175
 
176
		}
177
 
178
		// debug($_COOKIE['pin']);
179
		$url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
180
		$getstate =$this->make_request($url , null);
17844 naman 181
		// debug($getstate);
17793 naman 182
		$getstateval = "";
183
		if($getstate != "{}"){
184
			$getstateval =ucwords(strtolower($getstate['state']));
185
		}
186
		$this->set(compact('getstateval'));
187
	}
188
	 public function change(){
189
	 	$this->layout = 'innerpages';
190
	 	if($this->request->is('post'))
191
	 	{
192
	 		echo "Hello";
193
	 	}
194
	 }
195
 
17844 naman 196
	 public function getstate($pin_val){
197
	 	$this->autoRender = false;	
198
		$this->request->onlyAllow('ajax');
17849 amit.gupta 199
		$url = $this->apihost."pincodeValidation/".$pin_val;
17844 naman 200
		$getstate =$this->make_request($url , null);
201
		// $getstate['state'] =  ucwords(strtolower($getstate['state']));
202
		$nothing = "nothing";
203
		if($getstate != "{}"){
204
			$getstate['state'] =  ucwords(strtolower($getstate['state']));
205
 
206
		}
207
		return json_encode($getstate);
208
	 }
209
 
17793 naman 210
	 public function isServicable($pin){
211
	 	$this->autoRender = false;	
212
		$this->request->onlyAllow('ajax');
213
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
214
		// $response = $this->make_request($url,null);
17838 manish.sha 215
		if($pin == 110019)
17793 naman 216
		{$res = 'false';}
217
		else
218
			{$res = 'true';}
219
	 	return $res;
220
	 }
17846 manish.sha 221
 
17871 manish.sha 222
	 public function checkout(){
223
	 	$addressid = json_decode($this->request->data['addressid']);
17846 manish.sha 224
	 	$pincode = 0;
17871 manish.sha 225
		$cod = $this->request->query('cod');
17846 manish.sha 226
		$userId = $this->request->query('user_id');
227
 
228
		if(isset($this->request->data->pincode)){
229
			$pincode = $this->request->data->pincode;
230
		}
231
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
232
			$pincode = base64_decode($_COOKIE['s_pincode']);
233
		}
234
 
17871 manish.sha 235
		$suserId = base64_decode($_COOKIE['s_id']);
236
		$scartId = base64_decode($_COOKIE['s_cart']);
237
		$semailId = base64_decode($_COOKIE['s_email']);
238
 
239
		if(isset($_COOKIE['txn_comp'])) {
240
			unset($_COOKIE['txn_comp']);
241
		}
242
 
243
		if($cod==1){
244
			$url = Configure::read('saholicapihost').'order?payment_option=3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
245
		 	if($pincode!='0'){
246
				$url = $url.'&pinCode='.$pincode;
247
			}
248
			$orderCreationResponse = $this->post_cartinfo_request($url, null);
249
			//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
250
			$redirecturl = $orderCreationResponse['response']['redirectUrl'];
251
			if (strpos($redirecturl,'pay-success') === false) {
252
			    setcookie('txn_comp', 0, -1, '/');
253
			}
254
			$this->layout = 'innerpages';
255
			$next = $redirecturl;					
256
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
257
			$this->log($redirectUrl,'headers');
258
			$this->set(compact('redirectUrl','next'));
259
		}else{
260
			$dataGiven = json_decode($this->request->data['cart_details']);
261
			$totalSkus= intval($dataGiven->totalSkus);
262
			setcookie('txn_comp', 0, -1, '/');
263
			$this->layout = 'innerpages';
264
			$next = "payment?cq=".$totalSkus;					
265
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
266
			$this->log($redirectUrl,'headers');
267
			$this->set(compact('redirectUrl','next'));
268
		}
269
	 }
17793 naman 270
 
271
}