Subversion Repositories SmartDukaan

Rev

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

Rev 17849 Rev 17871
Line 27... Line 27...
27
		$userId = $this->Auth->User('id');
27
		$userId = $this->Auth->User('id');
28
		$dataGiven = json_decode($this->request->data['cart_details']);
28
		$dataGiven = json_decode($this->request->data['cart_details']);
29
		if ($this->request->is('post')) {
29
		if ($this->request->is('post')) {
30
			$data = $this->request->data;
30
			$data = $this->request->data;
31
		}
31
		}
32
		$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
-
 
33
		$this->Session->write('totalPayable', $totalPayable);
-
 
34
		$this->layout = 'innerpages';
32
		
35
		$suserId = base64_decode($_COOKIE['s_id']);
33
		$suserId = base64_decode($_COOKIE['s_id']);
36
		$url = Configure::read('saholicapihost').'address?isLoggedIn=true&privateDealUser=true&userId='.$suserId;
-
 
37
		$response = $this->make_request($url,null);
34
		$scartId = base64_decode($_COOKIE['s_cart']);
38
		//debug($response);
-
 
39
		if(empty($response['addresses'])){
-
 
40
			$this->redirect(array('action' => 'add'));
35
		$semailId = base64_decode($_COOKIE['s_email']);
41
		}
36
		
42
 
-
 
43
		$firstshowaddress = array();
37
		$pincode = 0;
44
		
38
		
45
		$pincode = base64_decode($_COOKIE['s_pincode']);
39
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
46
		$defaultaddressid = $response['defaultAddress'];
40
			$pincode = base64_decode($_COOKIE['s_pincode']);
47
		if(!empty($defaultaddressid)){
-
 
48
			$defaultaddressid = intval($defaultaddressid);
-
 
49
		}else{
-
 
50
			$defaultaddressid = -1;
-
 
51
		}
41
		}
52
		
42
		
53
		$defaultAddress = array();
-
 
54
		$similarAddress = array();
-
 
55
		$otherAddress = array();
43
		$cartItems = array();
56
		$defaultPinAddress = array();
-
 
57
		$defaultAddressFound = false;
-
 
58
		
44
		
59
		foreach ($response['addresses'] as $key => $value) {
45
		foreach ($dataGiven->cartItems as $key=>$obj) {
-
 
46
		    $itemobj = array(
-
 
47
					'itemId'   => $key,
-
 
48
		    		'quantity' => $obj->quantity);
-
 
49
			array_push($cartItems, $itemobj);
-
 
50
		}
-
 
51
		$postData = array(
-
 
52
					'cartItems'	=>	$cartItems
-
 
53
					);
-
 
54
					
-
 
55
		$params = array(
-
 
56
				'cartMap' => urlencode(json_encode($postData)));
-
 
57
		
-
 
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
		print_r('Cart Vaildation');
-
 
64
		$cartskus = $this->post_cartinfo_request($url,$params);
-
 
65
		print_r(count($cartskus['cartMessages']));
-
 
66
		if(isset($cartskus['response']) && $cartskus['response']=='error'){
-
 
67
			$this->set(compact('cartskus'));
-
 
68
			$this->render('/Users/cartdetails');
-
 
69
			
-
 
70
		}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
-
 
71
			setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
-
 
72
			$this->set(compact('cartskus'));
-
 
73
			$this->render('/Users/cartdetails');
-
 
74
		}else{
-
 
75
			print_r('Shipping Vaildation');
-
 
76
			$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
-
 
77
			$this->Session->write('totalPayable', $totalPayable);
-
 
78
			$this->layout = 'innerpages';
-
 
79
			$suserId = base64_decode($_COOKIE['s_id']);
-
 
80
			$url = Configure::read('saholicapihost').'address?isLoggedIn=true&privateDealUser=true&userId='.$suserId;
-
 
81
			$response = $this->make_request($url,null);
-
 
82
			//debug($response);
-
 
83
			if(empty($response['addresses'])){
-
 
84
				$this->redirect(array('action' => 'add'));
-
 
85
			}
-
 
86
	
-
 
87
			$firstshowaddress = array();
-
 
88
			
60
			if($defaultaddressid>-1 && $value['id']==$defaultaddressid && $value['pin']== $pincode){
89
			$defaultaddressid = $response['defaultAddress'];
61
				array_push($defaultAddress, $value);
90
			if(!empty($defaultaddressid)){
-
 
91
				$defaultaddressid = intval($defaultaddressid);
-
 
92
			}else{
62
				$defaultAddressFound = true;
93
				$defaultaddressid = -1;
63
			}
94
			}
-
 
95
			
-
 
96
			$defaultAddress = array();
-
 
97
			$similarAddress = array();
-
 
98
			$otherAddress = array();
-
 
99
			$defaultPinAddress = array();
-
 
100
			$defaultAddressFound = false;
-
 
101
			
-
 
102
			foreach ($response['addresses'] as $key => $value) {
-
 
103
				if($defaultaddressid>-1 && $value['id']==$defaultaddressid && $value['pin']== $pincode){
-
 
104
					array_push($defaultAddress, $value);
-
 
105
					$defaultAddressFound = true;
-
 
106
				}
64
			else if($value['pin']== $pincode){
107
				else if($value['pin']== $pincode){
65
				array_push($similarAddress, $value);
108
					array_push($similarAddress, $value);
66
				$defaultAddressFound = true;
109
					$defaultAddressFound = true;
-
 
110
				}
-
 
111
				else if($value['id'] == $defaultaddressid)
-
 
112
				{
-
 
113
					array_push($defaultPinAddress, $value);
-
 
114
				}	
-
 
115
				else{
-
 
116
					array_push($otherAddress, $value);
-
 
117
				}
67
			}
118
			}
68
			else if($value['id'] == $defaultaddressid)
119
			for($i= 0; $i<count($defaultAddress);$i++)
69
			{
120
			{
70
				array_push($defaultPinAddress, $value);
-
 
71
			}	
-
 
72
			else{
-
 
73
				array_push($otherAddress, $value);
121
				array_push($firstshowaddress,$defaultAddress[$i]);
74
			}
122
			}
75
		}
-
 
76
		for($i= 0; $i<count($defaultAddress);$i++)
123
			for($i= 0; $i<count($similarAddress);$i++)
77
		{
124
			{
78
			array_push($firstshowaddress,$defaultAddress[$i]);
125
				array_push($firstshowaddress,$similarAddress[$i]);
79
		}
126
			}
80
		for($i= 0; $i<count($similarAddress);$i++)
127
			for($i= 0; $i<count($defaultPinAddress);$i++)
81
		{
128
			{
82
			array_push($firstshowaddress,$similarAddress[$i]);
129
				array_push($firstshowaddress,$defaultPinAddress[$i]);
83
		}
130
			}
84
		for($i= 0; $i<count($defaultPinAddress);$i++)
131
			for($i= 0; $i<count($otherAddress);$i++)
85
		{
132
			{
86
			array_push($firstshowaddress,$defaultPinAddress[$i]);
133
				array_push($firstshowaddress,$otherAddress[$i]);
87
		}
134
			}
88
		for($i= 0; $i<count($otherAddress);$i++)
-
 
89
		{
135
			
90
			array_push($firstshowaddress,$otherAddress[$i]);
136
			$this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
91
		}
137
		}
92
		
138
		
93
		$this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
-
 
-
 
139
 
94
	}
140
	}
95
 
141
 
96
	public function add() {
142
	public function add() {
97
		$this->layout = 'innerpages';
143
		$this->layout = 'innerpages';
98
		$pinval = 232104;
144
		$pinval = 232104;
Line 174... Line 220...
174
		else
220
		else
175
			{$res = 'true';}
221
			{$res = 'true';}
176
	 	return $res;
222
	 	return $res;
177
	 }
223
	 }
178
	 
224
	 
179
	 /*public function checkout(){
225
	 public function checkout(){
180
	 	$dataGiven = json_decode($this->request->data['cart_details']);
226
	 	$addressid = json_decode($this->request->data['addressid']);
181
	 	$pincode = 0;
227
	 	$pincode = 0;
-
 
228
		$cod = $this->request->query('cod');
182
		$userId = $this->request->query('user_id');
229
		$userId = $this->request->query('user_id');
183
		
230
		
184
		if(isset($this->request->data->pincode)){
231
		if(isset($this->request->data->pincode)){
185
			$pincode = $this->request->data->pincode;
232
			$pincode = $this->request->data->pincode;
186
		}
233
		}
187
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
234
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
188
			$pincode = base64_decode($_COOKIE['s_pincode']);
235
			$pincode = base64_decode($_COOKIE['s_pincode']);
189
		}
236
		}
190
		$suserId = 0;
-
 
191
		$scartId = 0;
-
 
192
		$semailId = '';
-
 
193
	 	
237
	 	
-
 
238
		$suserId = base64_decode($_COOKIE['s_id']);
-
 
239
		$scartId = base64_decode($_COOKIE['s_cart']);
-
 
240
		$semailId = base64_decode($_COOKIE['s_email']);
-
 
241
		
-
 
242
		if(isset($_COOKIE['txn_comp'])) {
-
 
243
			unset($_COOKIE['txn_comp']);
-
 
244
		}
-
 
245
		
-
 
246
		if($cod==1){
-
 
247
			$url = Configure::read('saholicapihost').'order?payment_option=3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
-
 
248
		 	if($pincode!='0'){
-
 
249
				$url = $url.'&pinCode='.$pincode;
-
 
250
			}
-
 
251
			$orderCreationResponse = $this->post_cartinfo_request($url, null);
-
 
252
			//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
-
 
253
			$redirecturl = $orderCreationResponse['response']['redirectUrl'];
-
 
254
			if (strpos($redirecturl,'pay-success') === false) {
-
 
255
			    setcookie('txn_comp', 0, -1, '/');
-
 
256
			}
-
 
257
			$this->layout = 'innerpages';
-
 
258
			$next = $redirecturl;					
-
 
259
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
-
 
260
			$this->log($redirectUrl,'headers');
-
 
261
			$this->set(compact('redirectUrl','next'));
-
 
262
		}else{
-
 
263
			$dataGiven = json_decode($this->request->data['cart_details']);
-
 
264
			$totalSkus= intval($dataGiven->totalSkus);
-
 
265
			setcookie('txn_comp', 0, -1, '/');
-
 
266
			$this->layout = 'innerpages';
-
 
267
			$next = "payment?cq=".$totalSkus;					
-
 
268
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
-
 
269
			$this->log($redirectUrl,'headers');
-
 
270
			$this->set(compact('redirectUrl','next'));
-
 
271
		}
194
	 }*/
272
	 }
195
 
273
 
196
}
274
}