Subversion Repositories SmartDukaan

Rev

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

Rev 17880 Rev 17882
Line 71... Line 71...
71
			$this->render('/Users/cartdetails');
71
			$this->render('/Users/cartdetails');
72
		}else{
72
		}else{
73
			$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
73
			$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
74
			$this->Session->write('totalPayable', $totalPayable);
74
			$this->Session->write('totalPayable', $totalPayable);
75
			$this->layout = 'innerpages';
75
			$this->layout = 'innerpages';
76
			$suserId = base64_decode($_COOKIE['s_id']);
-
 
77
			$url = Configure::read('saholicapihost').'address?isLoggedIn=true&privateDealUser=true&userId='.$suserId;
76
			$url = Configure::read ( 'saholicapihost' ) . 'address?isLoggedIn=true&privateDealUser=true&userId=' . $suserId;
78
			$response = $this->make_request($url,null);
77
			$response = $this->make_request ( $url, null );
-
 
78
			$user_name = "";
79
			//debug($response);
79
			$user_contact = "";
-
 
80
			
80
			if(empty($response['addresses'])){
81
			if(empty($response ['addresses'])){
81
				$this->redirect(array('action' => 'add'));
82
				$this->redirect ( array (
-
 
83
						'action' => 'add' 
-
 
84
				));
82
			}
85
			}
83
	
-
 
84
			$firstshowaddress = array();
-
 
85
			
86
			
86
			$defaultaddressid = $response['defaultAddress'];
87
			$firstshowaddress = array ();
87
			if(!empty($defaultaddressid)){
88
			$findedaddress = array ();
88
				$defaultaddressid = intval($defaultaddressid);
89
			$moreshowaddress = array ();
89
			}else{
-
 
90
				$defaultaddressid = -1;
90
			$current_address_id = - 1;
91
			}
-
 
92
			
-
 
93
			$defaultAddress = array();
91
			$defaultpin = - 1;
94
			$similarAddress = array();
92
			$defaultcookiepin = - 1;
95
			$otherAddress = array();
93
			$defaultcheckedaddress = - 1;
96
			$defaultPinAddress = array();
94
			$defaultpinaddress = - 1;
-
 
95
			foreach ( $response ['addresses'] as $key => $value ) {
97
			$defaultAddressFound = false;
96
				// debug($value['']);
98
			
97
				
99
			foreach ($response['addresses'] as $key => $value) {
98
				if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
-
 
99
					$defaultcookiepin = $key;
-
 
100
					$user_name = $value ['name'];
100
				if($defaultaddressid>-1 && $value['id']==$defaultaddressid && $value['pin']== $pincode){
101
					$user_contact = $value ['phone'];
101
					array_push($defaultAddress, $value);
102
					if ($defaultcheckedaddress == - 1) {
102
					$defaultAddressFound = true;
103
						$defaultcheckedaddress = $value ['id'];
103
				}
104
					}
104
				else if($value['pin']== $pincode){
105
				} else if (intval ( $value ['pin'] ) == $pincode) {
-
 
106
					$current_address_id = $key;
105
					array_push($similarAddress, $value);
107
					array_push ( $findedaddress, $key );
-
 
108
					if ($defaultpinaddress == - 1) {
106
					$defaultAddressFound = true;
109
						$defaultpinaddress = $value ['id'];
107
				}
110
					}
108
				else if($value['id'] == $defaultaddressid)
111
				} else if ($value ['id'] == intval ( $response ['defaultAddress'] )) {
109
				{
112
					$defaultpin = $key;
110
					array_push($defaultPinAddress, $value);
113
					$user_name = $value ['name'];
111
				}	
114
					$user_contact = $value ['phone'];
112
				else{
115
				} else {
113
					array_push($otherAddress, $value);
116
					array_push ( $moreshowaddress, $key );
114
				}
117
				}
115
			}
118
			}
-
 
119
			
-
 
120
			$defaultselectedaddress = - 1;
116
			for($i= 0; $i<count($defaultAddress);$i++)
121
			if ($defaultpinaddress != - 1) {
-
 
122
				$defaultselectedaddress = $defaultpinaddress;
117
			{
123
			}
-
 
124
			if ($defaultcheckedaddress != - 1) {
118
				array_push($firstshowaddress,$defaultAddress[$i]);
125
				$defaultselectedaddress = $defaultcheckedaddress;
119
			}
126
			}
-
 
127
			
-
 
128
			if ($defaultcookiepin != - 1) {
120
			for($i= 0; $i<count($similarAddress);$i++)
129
				array_push ( $firstshowaddress, $defaultcookiepin );
121
			{
130
			}
-
 
131
			
-
 
132
			for($i = 0; $i < count ( $findedaddress ); $i ++) {
122
				array_push($firstshowaddress,$similarAddress[$i]);
133
				array_push ( $firstshowaddress, $findedaddress [$i] );
123
			}
134
			}
124
			for($i= 0; $i<count($defaultPinAddress);$i++)
-
 
125
			{
135
			
-
 
136
			if ($defaultpin != - 1) {
126
				array_push($firstshowaddress,$defaultPinAddress[$i]);
137
				array_push ( $firstshowaddress, $defaultpin );
127
			}
138
			}
128
			for($i= 0; $i<count($otherAddress);$i++)
-
 
129
			{
139
			
-
 
140
			for($i = 0; $i < count ( $moreshowaddress ); $i ++) {
130
				array_push($firstshowaddress,$otherAddress[$i]);
141
				array_push ( $firstshowaddress, $moreshowaddress [$i] );
131
			}
142
			}
132
			
143
			
-
 
144
			$this->set ( 'address', $response );
-
 
145
			
133
			$this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
146
			$this->set ( compact ( 'firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message' ) );
134
		}
147
		}
135
		
-
 
136
 
-
 
137
	}
148
	}
138
 
-
 
139
	public function add() {
149
	public function add($user_name = null, $user_contact = null) {
140
		$this->layout = 'innerpages';
150
		$this->layout = 'cartinnerpages';
-
 
151
		
141
		$pinval = 232104;
152
		$totalPayable = $_SESSION ['totalPayable'];
142
		setcookie('pin', $pinval, -1, '/');
153
		$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
-
 
154
		;
143
		$nameval = "Roman";
155
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
144
		setcookie('name', $nameval, -1, '/');
156
		$scart = base64_decode ( $_COOKIE ['s_cart'] );
145
 
157
		
146
		if ($this->request->is('post')) {
158
		if ($this->request->is ( 'post' )) {
147
			$data = $this->request->data;
159
			$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
			
160
			
-
 
161
			$senddata ['name'] = $data ['name'];
-
 
162
			$senddata ['line1'] = $data ['line1'];
-
 
163
			$senddata ['line2'] = "";
-
 
164
			$senddata ['city'] = $data ['city'];
-
 
165
			$senddata ['state'] = $data ['state'];
-
 
166
			$senddata ['pin'] = $data ['pin'];
-
 
167
			$senddata ['phone'] = $data ['phone'];
-
 
168
			$senddata ['country'] = 'India';
-
 
169
			$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";
-
 
170
			
-
 
171
			$response = $this->post_request ( $url, $senddata );
-
 
172
			
-
 
173
			$scartId = base64_decode ( $_COOKIE ['s_cart'] );
-
 
174
			$semailId = base64_decode ( $_COOKIE ['s_email'] );
-
 
175
			$blank = array ();
-
 
176
			$postData = array (
-
 
177
					'cartItems' => $blank 
-
 
178
			);
-
 
179
			
-
 
180
			$params = array (
-
 
181
					'cartMap' => urlencode ( json_encode ( $postData ) ) 
-
 
182
			);
-
 
183
			$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
-
 
184
			// if($pin!='0'){
-
 
185
			$url = $url . '&pinCode=' . $data ['pin'];
-
 
186
			// }
-
 
187
			$cartskus = $this->post_cartinfo_request ( $url, $params );
-
 
188
			$checkestimate = 'true';
-
 
189
			if ($cartskus ['maxEstimate'] == - 1) {
-
 
190
				$checkestimate = 'false';
-
 
191
			} else {
-
 
192
				for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
-
 
193
					if ($cartskus ['cartItems'] [$i] ['estimate'] == - 1) {
-
 
194
						$checkestimate = 'false';
-
 
195
						break;
-
 
196
					}
-
 
197
				}
-
 
198
			}
-
 
199
			
-
 
200
			if ($checkestimate == 'false') {
-
 
201
				// debug("I am here");
-
 
202
				$this->Session->setFlash ( "Address is not serviceable", 'default', array (
-
 
203
						'class' => 'alert alert-danger custom_class' 
-
 
204
				) );
-
 
205
				// $this->Session->setFlash('Address is not serviceable');
-
 
206
				return $this->redirect ( array (
-
 
207
						'action' => 'index' 
-
 
208
				) );
-
 
209
			} else {
-
 
210
				$this->Session->setFlash ( "Address is  serviceable" );
-
 
211
			}
176
		}
212
		}
177
		
213
		
178
		// debug($_COOKIE['pin']);
-
 
179
		$url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
214
		$url = $this->apihost . "pincodeValidation/" . $pinval;
180
		$getstate =$this->make_request($url , null);
215
		$getstate = $this->make_request ( $url, null );
181
		// debug($getstate);
216
		// debug($getstate);
182
		$getstateval = "";
217
		$getstateval = "";
183
		if($getstate != "{}"){
218
		if ($getstate != "{}") {
184
			$getstateval =ucwords(strtolower($getstate['state']));
219
			$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
185
		}
220
		}
186
		$this->set(compact('getstateval'));
221
		$this->set ( compact ( 'getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable' ) );
187
	}
222
	}
188
	 public function change(){
223
	public function submitcheck() {
189
	 	$this->layout = 'innerpages';
224
		$this->autoRender = false;
190
	 	if($this->request->is('post'))
225
		$this->request->onlyAllow ( 'ajax' );
-
 
226
		
-
 
227
		$data = $this->request->data;
-
 
228
		
-
 
229
		$senddata ['name'] = $data ['name'];
-
 
230
		$senddata ['line1'] = $data ['line1'];
-
 
231
		$senddata ['line2'] = "";
-
 
232
		$senddata ['city'] = $data ['city'];
-
 
233
		$senddata ['state'] = $data ['state'];
-
 
234
		$senddata ['pin'] = $data ['pin'];
-
 
235
		$senddata ['phone'] = $data ['phone'];
-
 
236
		$senddata ['country'] = 'India';
-
 
237
		$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";
-
 
238
		
-
 
239
		// $response = $this->post_request($url,$senddata);
-
 
240
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
-
 
241
		
-
 
242
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
-
 
243
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
-
 
244
		$blank = array ();
-
 
245
		$postData = array (
-
 
246
				'cartItems' => $blank 
-
 
247
		);
191
	 	{
248
		
-
 
249
		$params = array (
-
 
250
				'cartMap' => urlencode ( json_encode ( $postData ) ) 
-
 
251
		);
-
 
252
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
-
 
253
		// if($pin!='0'){
-
 
254
		$url = $url . '&pinCode=' . $data ['pin'];
-
 
255
		// }
-
 
256
		$cartskus = $this->post_cartinfo_request ( $url, $params );
-
 
257
		$checkestimate = 'true';
-
 
258
		if ($cartskus ['maxEstimate'] == - 1) {
-
 
259
			$checkestimate = 'false';
-
 
260
		} else {
-
 
261
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
-
 
262
				if ($cartskus ['cartItems'] [$i] ['estimate'] == - 1) {
-
 
263
					$checkestimate = 'false';
192
	 		echo "Hello";
264
					break;
-
 
265
				}
193
	 	}
266
			}
-
 
267
		}
-
 
268
		
-
 
269
		if ($checkestimate == 'false') {
-
 
270
			setcookie ( 'address_message', "Address is not Servicable", - 1, '/' );
194
	 }
271
		}
-
 
272
		
-
 
273
		return $checkestimate;
195
 
274
	}
196
	 public function getstate($pin_val){
275
	public function getstate($pin_val) {
197
	 	$this->autoRender = false;	
276
		$this->autoRender = false;
198
		$this->request->onlyAllow('ajax');
277
		$this->request->onlyAllow ( 'ajax' );
199
		$url = $this->apihost."pincodeValidation/".$pin_val;
278
		$url = $this->apihost . "pincodeValidation/" . $pin_val;
200
		$getstate =$this->make_request($url , null);
279
		$getstate = $this->make_request ( $url, null );
201
		// $getstate['state'] =  ucwords(strtolower($getstate['state']));
280
		// $getstate['state'] = ucwords(strtolower($getstate['state']));
202
		$nothing = "nothing";
281
		$nothing = "nothing";
203
		if($getstate != "{}"){
282
		if ($getstate != "{}") {
204
			$getstate['state'] =  ucwords(strtolower($getstate['state']));
283
			$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );
205
			
-
 
206
		}
284
		}
207
		return json_encode($getstate);
285
		return json_encode ( $getstate );
208
	 }
286
	}
209
 
-
 
210
	 public function isServicable($pin){
287
	public function isServicable($pin) {
211
	 	$this->autoRender = false;	
288
		$this->autoRender = false;
212
		$this->request->onlyAllow('ajax');
289
		$this->request->onlyAllow ( 'ajax' );
213
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
290
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
214
		// $response = $this->make_request($url,null);
291
		// $response = $this->make_request($url,null);
-
 
292
		
-
 
293
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
-
 
294
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
-
 
295
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
-
 
296
		$blank = array ();
-
 
297
		$postData = array (
-
 
298
				'cartItems' => $blank 
-
 
299
		);
-
 
300
		
215
		if($pin == 110019)
301
		$params = array (
-
 
302
				'cartMap' => urlencode ( json_encode ( $postData ) ) 
-
 
303
		);
-
 
304
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
-
 
305
		$url = $url . '&pinCode=' . $pin;
-
 
306
		$cartskus = $this->post_cartinfo_request ( $url, $params );
-
 
307
		$checkestimate = 'true';
-
 
308
		if ($cartskus ['maxEstimate'] == - 1) {
216
		{$res = 'false';}
309
			$checkestimate = 'false';
217
		else
310
		} else {
-
 
311
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
-
 
312
				if ($cartskus ['cartItems'] [$i] ['estimate'] == - 1) {
218
			{$res = 'true';}
313
					$checkestimate = 'false';
-
 
314
					break;
-
 
315
				}
-
 
316
			}
-
 
317
		}
-
 
318
		
219
	 	return $res;
319
		return $checkestimate;
220
	 }
320
	}
221
	 
321
	
222
	 public function checkout(){
322
	 public function checkout(){
223
	 	$addressid = json_decode($this->request->data['addressid']);
323
	 	$addressid = json_decode($this->request->data['addressid']);
224
	 	$pincode = 0;
324
	 	$pincode = 0;
225
		$cod = $this->request->query('cod');
325
		$cod = $this->request->query('cod');
226
		$userId = $this->request->query('user_id');
326
		$userId = $this->request->query('user_id');
Line 265... Line 365...
265
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
365
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
266
			$this->log($redirectUrl,'headers');
366
			$this->log($redirectUrl,'headers');
267
			$this->set(compact('redirectUrl','next'));
367
			$this->set(compact('redirectUrl','next'));
268
		}
368
		}
269
	 }
369
	 }
270
 
-
 
271
}
370
}