Subversion Repositories SmartDukaan

Rev

Rev 17849 | Rev 17878 | 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
		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'));
17793 naman 85
			}
17871 manish.sha 86
 
87
			$firstshowaddress = array();
88
 
89
			$defaultaddressid = $response['defaultAddress'];
90
			if(!empty($defaultaddressid)){
91
				$defaultaddressid = intval($defaultaddressid);
92
			}else{
93
				$defaultaddressid = -1;
17793 naman 94
			}
17871 manish.sha 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
				}
107
				else if($value['pin']== $pincode){
108
					array_push($similarAddress, $value);
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
				}
118
			}
119
			for($i= 0; $i<count($defaultAddress);$i++)
17793 naman 120
			{
17871 manish.sha 121
				array_push($firstshowaddress,$defaultAddress[$i]);
17793 naman 122
			}
17871 manish.sha 123
			for($i= 0; $i<count($similarAddress);$i++)
124
			{
125
				array_push($firstshowaddress,$similarAddress[$i]);
126
			}
127
			for($i= 0; $i<count($defaultPinAddress);$i++)
128
			{
129
				array_push($firstshowaddress,$defaultPinAddress[$i]);
130
			}
131
			for($i= 0; $i<count($otherAddress);$i++)
132
			{
133
				array_push($firstshowaddress,$otherAddress[$i]);
134
			}
135
 
136
			$this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
17793 naman 137
		}
138
 
17871 manish.sha 139
 
17793 naman 140
	}
141
 
142
	public function add() {
143
		$this->layout = 'innerpages';
144
		$pinval = 232104;
145
		setcookie('pin', $pinval, -1, '/');
17844 naman 146
		$nameval = "Roman";
17793 naman 147
		setcookie('name', $nameval, -1, '/');
148
 
149
		if ($this->request->is('post')) {
150
			$data = $this->request->data;
151
			if($data['name'] == "")
152
			{
153
				$senddata['name'] = $_COOKIE['name'];	
154
			}
155
			else
156
			{
157
				$senddata['name'] = $data['name'];	
158
			}
159
 
160
			$senddata['line1'] = $data['line1'];
161
			$senddata['line2'] = "";
162
			$senddata['city'] = $data['city'];
163
			$senddata['state'] = $data['state'];
164
			if($data['pin'] == "")
165
			{
166
				$senddata['pin'] = $_COOKIE['pin'];	
167
			}
168
			else
169
			{
170
				$senddata['pin'] = $data['pin'];	
171
			}
172
			$senddata['phone'] = $data['phone'];
173
			$senddata['country'] = 'India';
174
			// debug($senddata);
175
			$url  = "http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true&cartId=41&isPrivateDealUser=true";
176
			$response = $this->post_request($url,$senddata);
177
			$this->redirect(array('action' => 'index'));
178
 
179
		}
180
 
181
		// debug($_COOKIE['pin']);
182
		$url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
183
		$getstate =$this->make_request($url , null);
17844 naman 184
		// debug($getstate);
17793 naman 185
		$getstateval = "";
186
		if($getstate != "{}"){
187
			$getstateval =ucwords(strtolower($getstate['state']));
188
		}
189
		$this->set(compact('getstateval'));
190
	}
191
	 public function change(){
192
	 	$this->layout = 'innerpages';
193
	 	if($this->request->is('post'))
194
	 	{
195
	 		echo "Hello";
196
	 	}
197
	 }
198
 
17844 naman 199
	 public function getstate($pin_val){
200
	 	$this->autoRender = false;	
201
		$this->request->onlyAllow('ajax');
17849 amit.gupta 202
		$url = $this->apihost."pincodeValidation/".$pin_val;
17844 naman 203
		$getstate =$this->make_request($url , null);
204
		// $getstate['state'] =  ucwords(strtolower($getstate['state']));
205
		$nothing = "nothing";
206
		if($getstate != "{}"){
207
			$getstate['state'] =  ucwords(strtolower($getstate['state']));
208
 
209
		}
210
		return json_encode($getstate);
211
	 }
212
 
17793 naman 213
	 public function isServicable($pin){
214
	 	$this->autoRender = false;	
215
		$this->request->onlyAllow('ajax');
216
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
217
		// $response = $this->make_request($url,null);
17838 manish.sha 218
		if($pin == 110019)
17793 naman 219
		{$res = 'false';}
220
		else
221
			{$res = 'true';}
222
	 	return $res;
223
	 }
17846 manish.sha 224
 
17871 manish.sha 225
	 public function checkout(){
226
	 	$addressid = json_decode($this->request->data['addressid']);
17846 manish.sha 227
	 	$pincode = 0;
17871 manish.sha 228
		$cod = $this->request->query('cod');
17846 manish.sha 229
		$userId = $this->request->query('user_id');
230
 
231
		if(isset($this->request->data->pincode)){
232
			$pincode = $this->request->data->pincode;
233
		}
234
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
235
			$pincode = base64_decode($_COOKIE['s_pincode']);
236
		}
237
 
17871 manish.sha 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
		}
272
	 }
17793 naman 273
 
274
}