Subversion Repositories SmartDukaan

Rev

Rev 17871 | Rev 17880 | 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
		print_r(count($cartskus['cartMessages']));
65
		if(isset($cartskus['response']) && $cartskus['response']=='error'){
66
			$this->set(compact('cartskus'));
67
			$this->render('/Users/cartdetails');
68
 
69
		}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
70
			setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
71
			$this->set(compact('cartskus'));
72
			$this->render('/Users/cartdetails');
73
		}else{
74
			$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
75
			$this->Session->write('totalPayable', $totalPayable);
76
			$this->layout = 'innerpages';
77
			$suserId = base64_decode($_COOKIE['s_id']);
78
			$url = Configure::read('saholicapihost').'address?isLoggedIn=true&privateDealUser=true&userId='.$suserId;
79
			$response = $this->make_request($url,null);
80
			//debug($response);
81
			if(empty($response['addresses'])){
82
				$this->redirect(array('action' => 'add'));
17793 naman 83
			}
17871 manish.sha 84
 
85
			$firstshowaddress = array();
86
 
87
			$defaultaddressid = $response['defaultAddress'];
88
			if(!empty($defaultaddressid)){
89
				$defaultaddressid = intval($defaultaddressid);
90
			}else{
91
				$defaultaddressid = -1;
17793 naman 92
			}
17871 manish.sha 93
 
94
			$defaultAddress = array();
95
			$similarAddress = array();
96
			$otherAddress = array();
97
			$defaultPinAddress = array();
98
			$defaultAddressFound = false;
99
 
100
			foreach ($response['addresses'] as $key => $value) {
101
				if($defaultaddressid>-1 && $value['id']==$defaultaddressid && $value['pin']== $pincode){
102
					array_push($defaultAddress, $value);
103
					$defaultAddressFound = true;
104
				}
105
				else if($value['pin']== $pincode){
106
					array_push($similarAddress, $value);
107
					$defaultAddressFound = true;
108
				}
109
				else if($value['id'] == $defaultaddressid)
110
				{
111
					array_push($defaultPinAddress, $value);
112
				}	
113
				else{
114
					array_push($otherAddress, $value);
115
				}
116
			}
117
			for($i= 0; $i<count($defaultAddress);$i++)
17793 naman 118
			{
17871 manish.sha 119
				array_push($firstshowaddress,$defaultAddress[$i]);
17793 naman 120
			}
17871 manish.sha 121
			for($i= 0; $i<count($similarAddress);$i++)
122
			{
123
				array_push($firstshowaddress,$similarAddress[$i]);
124
			}
125
			for($i= 0; $i<count($defaultPinAddress);$i++)
126
			{
127
				array_push($firstshowaddress,$defaultPinAddress[$i]);
128
			}
129
			for($i= 0; $i<count($otherAddress);$i++)
130
			{
131
				array_push($firstshowaddress,$otherAddress[$i]);
132
			}
133
 
134
			$this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
17793 naman 135
		}
136
 
17871 manish.sha 137
 
17793 naman 138
	}
139
 
140
	public function add() {
141
		$this->layout = 'innerpages';
142
		$pinval = 232104;
143
		setcookie('pin', $pinval, -1, '/');
17844 naman 144
		$nameval = "Roman";
17793 naman 145
		setcookie('name', $nameval, -1, '/');
146
 
147
		if ($this->request->is('post')) {
148
			$data = $this->request->data;
149
			if($data['name'] == "")
150
			{
151
				$senddata['name'] = $_COOKIE['name'];	
152
			}
153
			else
154
			{
155
				$senddata['name'] = $data['name'];	
156
			}
157
 
158
			$senddata['line1'] = $data['line1'];
159
			$senddata['line2'] = "";
160
			$senddata['city'] = $data['city'];
161
			$senddata['state'] = $data['state'];
162
			if($data['pin'] == "")
163
			{
164
				$senddata['pin'] = $_COOKIE['pin'];	
165
			}
166
			else
167
			{
168
				$senddata['pin'] = $data['pin'];	
169
			}
170
			$senddata['phone'] = $data['phone'];
171
			$senddata['country'] = 'India';
172
			// debug($senddata);
173
			$url  = "http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true&cartId=41&isPrivateDealUser=true";
174
			$response = $this->post_request($url,$senddata);
175
			$this->redirect(array('action' => 'index'));
176
 
177
		}
178
 
179
		// debug($_COOKIE['pin']);
180
		$url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
181
		$getstate =$this->make_request($url , null);
17844 naman 182
		// debug($getstate);
17793 naman 183
		$getstateval = "";
184
		if($getstate != "{}"){
185
			$getstateval =ucwords(strtolower($getstate['state']));
186
		}
187
		$this->set(compact('getstateval'));
188
	}
189
	 public function change(){
190
	 	$this->layout = 'innerpages';
191
	 	if($this->request->is('post'))
192
	 	{
193
	 		echo "Hello";
194
	 	}
195
	 }
196
 
17844 naman 197
	 public function getstate($pin_val){
198
	 	$this->autoRender = false;	
199
		$this->request->onlyAllow('ajax');
17849 amit.gupta 200
		$url = $this->apihost."pincodeValidation/".$pin_val;
17844 naman 201
		$getstate =$this->make_request($url , null);
202
		// $getstate['state'] =  ucwords(strtolower($getstate['state']));
203
		$nothing = "nothing";
204
		if($getstate != "{}"){
205
			$getstate['state'] =  ucwords(strtolower($getstate['state']));
206
 
207
		}
208
		return json_encode($getstate);
209
	 }
210
 
17793 naman 211
	 public function isServicable($pin){
212
	 	$this->autoRender = false;	
213
		$this->request->onlyAllow('ajax');
214
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
215
		// $response = $this->make_request($url,null);
17838 manish.sha 216
		if($pin == 110019)
17793 naman 217
		{$res = 'false';}
218
		else
219
			{$res = 'true';}
220
	 	return $res;
221
	 }
17846 manish.sha 222
 
17871 manish.sha 223
	 public function checkout(){
224
	 	$addressid = json_decode($this->request->data['addressid']);
17846 manish.sha 225
	 	$pincode = 0;
17871 manish.sha 226
		$cod = $this->request->query('cod');
17846 manish.sha 227
		$userId = $this->request->query('user_id');
228
 
229
		if(isset($this->request->data->pincode)){
230
			$pincode = $this->request->data->pincode;
231
		}
232
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
233
			$pincode = base64_decode($_COOKIE['s_pincode']);
234
		}
235
 
17871 manish.sha 236
		$suserId = base64_decode($_COOKIE['s_id']);
237
		$scartId = base64_decode($_COOKIE['s_cart']);
238
		$semailId = base64_decode($_COOKIE['s_email']);
239
 
240
		if(isset($_COOKIE['txn_comp'])) {
241
			unset($_COOKIE['txn_comp']);
242
		}
243
 
244
		if($cod==1){
245
			$url = Configure::read('saholicapihost').'order?payment_option=3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
246
		 	if($pincode!='0'){
247
				$url = $url.'&pinCode='.$pincode;
248
			}
249
			$orderCreationResponse = $this->post_cartinfo_request($url, null);
250
			//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
251
			$redirecturl = $orderCreationResponse['response']['redirectUrl'];
252
			if (strpos($redirecturl,'pay-success') === false) {
253
			    setcookie('txn_comp', 0, -1, '/');
254
			}
255
			$this->layout = 'innerpages';
256
			$next = $redirecturl;					
257
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
258
			$this->log($redirectUrl,'headers');
259
			$this->set(compact('redirectUrl','next'));
260
		}else{
261
			$dataGiven = json_decode($this->request->data['cart_details']);
262
			$totalSkus= intval($dataGiven->totalSkus);
263
			setcookie('txn_comp', 0, -1, '/');
264
			$this->layout = 'innerpages';
265
			$next = "payment?cq=".$totalSkus;					
266
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
267
			$this->log($redirectUrl,'headers');
268
			$this->set(compact('redirectUrl','next'));
269
		}
270
	 }
17793 naman 271
 
272
}