Subversion Repositories SmartDukaan

Rev

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

Rev 22464 Rev 22465
Line 6... Line 6...
6
 * @property Exceptionalnlc $Exceptionalnlc
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
7
 * @property PaginatorComponent $Paginator
8
 */
8
 */
9
class ShippingsController extends AppController {
9
class ShippingsController extends AppController {
10
 
10
 
11
	/**
11
/**
12
	 * Components
12
 * Components
13
	 *
13
 *
14
	 * @var array
14
 * @var array
15
	 */
15
 */
16
	public $components = array('Paginator');
16
	public $components = array('Paginator');
17
 
17
 
18
	public function beforeFilter() {
18
	public function beforeFilter() {
19
		parent::beforeFilter();
19
		parent::beforeFilter();
20
		$this->apihost = Configure::read('pythonapihost');
20
		$this->apihost = Configure::read('pythonapihost');
21
		$this->mobileapihost = Configure::read('saholicapihost');
21
		$this->mobileapihost = Configure::read('saholicapihost');
22
		$this->Auth->allow('isServicable');
22
		$this->Auth->allow('isServicable');
23
		$this->Auth->allow('createSaholicOrder');
-
 
24
	}
23
	}
25
 
24
	
26
 
25
 
27
	public function index(){
26
	public function index(){
28
		$userId = $this->Auth->User('id');
27
		$userId = $this->Auth->User('id');
29
		$dataGiven = json_decode($this->request->data['cart_details']);
28
		$dataGiven = json_decode($this->request->data['cart_details']);
30
		if ($this->request->is('post')) {
29
		if ($this->request->is('post')) {
31
			$data = $this->request->data;
30
			$data = $this->request->data;
32
		}
31
		}
33
 
32
		
34
		$suserId = base64_decode($_COOKIE['s_id']);
33
		$suserId = base64_decode($_COOKIE['s_id']);
35
		$scartId = base64_decode($_COOKIE['s_cart']);
34
		$scartId = base64_decode($_COOKIE['s_cart']);
36
		$semailId = base64_decode($_COOKIE['s_email']);
35
		$semailId = base64_decode($_COOKIE['s_email']);
37
 
36
		
38
		$pincode = 0;
37
		$pincode = 0;
39
 
38
		
40
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
39
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
41
			$pincode = base64_decode($_COOKIE['s_pincode']);
40
			$pincode = base64_decode($_COOKIE['s_pincode']);
42
			$url = $this->apihost . "pincodeValidation/" . $pincode;
41
			$url = $this->apihost . "pincodeValidation/" . $pincode;
43
			$getstate = $this->make_request ( $url, null );
42
			$getstate = $this->make_request ( $url, null );		
44
			if ($getstate != "{}") {
43
			if ($getstate != "{}") {
45
				$stateres = ucwords ( strtolower ( $getstate ['state'] ) );
44
				$stateres = ucwords ( strtolower ( $getstate ['state'] ) );
46
			}
45
			}
47
		}
46
		}
48
 
47
		
49
		$cartItems = array();
48
		$cartItems = array();
50
 
49
		
51
		foreach ($dataGiven->cartItems as $key=>$obj) {
50
		foreach ($dataGiven->cartItems as $key=>$obj) {
52
			$itemobj = array('itemId'   => $key, 'quantity' => $obj->quantity);
51
		    $itemobj = array('itemId'   => $key, 'quantity' => $obj->quantity);
53
			array_push($cartItems, $itemobj);
52
			array_push($cartItems, $itemobj);
54
		}
53
		}
55
		$postData = array('cartItems'	=>	$cartItems);
54
		$postData = array('cartItems'	=>	$cartItems);
56
		$params = array('cartMap' => urlencode(json_encode($postData)));
55
		$params = array('cartMap' => urlencode(json_encode($postData)));
57
 
56
		
58
		$this->layout = 'cartinnerpages';
57
		$this->layout = 'cartinnerpages';
59
		$url = Configure::read('saholicapihost').'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId;
58
		$url = Configure::read('saholicapihost').'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId;
60
		if($pincode!='0'){
59
		if($pincode!='0'){
61
			$url = $url.'&pinCode='.$pincode;
60
			$url = $url.'&pinCode='.$pincode;
62
		}
61
		}
63
		$cartskus = $this->post_cartinfo_request($url,$params);
62
		$cartskus = $this->post_cartinfo_request($url,$params);
64
		if(isset($cartskus['response']) && $cartskus['response']=='error'){
63
		if(isset($cartskus['response']) && $cartskus['response']=='error'){
65
			$this->set(compact('cartskus'));
64
			$this->set(compact('cartskus'));
66
			$this->render('/Users/cartdetails');
65
			$this->render('/Users/cartdetails');
67
 
66
			
68
		}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
67
		}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
69
			setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
68
			setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
70
			$this->set(compact('cartskus'));
69
			$this->set(compact('cartskus'));
71
			$this->render('/Users/cartdetails');
70
			$this->render('/Users/cartdetails');
72
		}else{
71
		}else{
Line 81... Line 80...
81
			//$codAvailable = false;
80
			//$codAvailable = false;
82
			$this->Session->write('cod', $codAvailable);
81
			$this->Session->write('cod', $codAvailable);
83
			$walletAmount = 0;
82
			$walletAmount = 0;
84
			if(array_key_exists('walletAmount',$response)){
83
			if(array_key_exists('walletAmount',$response)){
85
				$walletAmount = $response ['walletAmount'];
84
				$walletAmount = $response ['walletAmount'];
86
			}
85
			} 
87
			//$creditorAssociated
86
			//$creditorAssociated
88
			$this->Session->write('walletAmount', $walletAmount);
87
			$this->Session->write('walletAmount', $walletAmount);
89
			$taxInvoiceEnabledUser = $response ['taxInvoiceEnabledUser'];
88
			$taxInvoiceEnabledUser = $response ['taxInvoiceEnabledUser'];
90
			$this->Session->write('taxInvoiceEnabledUser', $taxInvoiceEnabledUser);
89
			$this->Session->write('taxInvoiceEnabledUser', $taxInvoiceEnabledUser);
91
 
90
			
92
			if(empty($response ['addresses'])){
91
			if(empty($response ['addresses'])){
93
				$this->redirect ( array (
92
				$this->redirect ( array (
94
						'action' => 'add' 
93
						'action' => 'add' 
95
						));
94
				));
96
			}
95
			}
97
 
96
			
98
			$firstshowaddress = array ();
97
			$firstshowaddress = array ();
99
			$findedaddress = array ();
98
			$findedaddress = array ();
100
			$moreshowaddress = array ();
99
			$moreshowaddress = array ();
101
			$current_address_id = - 1;
100
			$current_address_id = - 1;
102
			$defaultpin = - 1;
101
			$defaultpin = - 1;
103
			$defaultcookiepin = - 1;
102
			$defaultcookiepin = - 1;
104
			$defaultcheckedaddress = - 1;
103
			$defaultcheckedaddress = - 1;
105
			$defaultpinaddress = - 1;
104
			$defaultpinaddress = - 1;
106
 
105
			
107
			foreach ( $response ['addresses'] as $key => $value ) {
106
			foreach ( $response ['addresses'] as $key => $value ) {
108
 
107
				
109
				if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
108
				if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
110
					$defaultcookiepin = $key;
109
					$defaultcookiepin = $key;
111
					$user_name = $value ['name'];
110
					$user_name = $value ['name'];
112
					$user_contact = $value ['phone'];
111
					$user_contact = $value ['phone'];
113
					if ($defaultcheckedaddress == - 1) {
112
					if ($defaultcheckedaddress == - 1) {
Line 125... Line 124...
125
					$user_contact = $value ['phone'];
124
					$user_contact = $value ['phone'];
126
				} else {
125
				} else {
127
					array_push ( $moreshowaddress, $key );
126
					array_push ( $moreshowaddress, $key );
128
				}
127
				}
129
			}
128
			}
130
 
129
			
131
			$defaultselectedaddress = - 1;
130
			$defaultselectedaddress = - 1;
132
			if ($defaultpinaddress != - 1) {
131
			if ($defaultpinaddress != - 1) {
133
				$defaultselectedaddress = $defaultpinaddress;
132
				$defaultselectedaddress = $defaultpinaddress;
134
			}
133
			}
135
			if ($defaultcheckedaddress != - 1) {
134
			if ($defaultcheckedaddress != - 1) {
136
				$defaultselectedaddress = $defaultcheckedaddress;
135
				$defaultselectedaddress = $defaultcheckedaddress;
137
			}
136
			}
138
 
137
			
139
			if ($defaultcookiepin != - 1) {
138
			if ($defaultcookiepin != - 1) {
140
				array_push ( $firstshowaddress, $defaultcookiepin );
139
				array_push ( $firstshowaddress, $defaultcookiepin );
141
			}
140
			}
142
 
141
			
143
			for($i = 0; $i < count ( $findedaddress ); $i ++) {
142
			for($i = 0; $i < count ( $findedaddress ); $i ++) {
144
				array_push ( $firstshowaddress, $findedaddress [$i] );
143
				array_push ( $firstshowaddress, $findedaddress [$i] );
145
			}
144
			}
146
 
145
			
147
			if ($defaultpin != - 1) {
146
			if ($defaultpin != - 1) {
148
				array_push ( $firstshowaddress, $defaultpin );
147
				array_push ( $firstshowaddress, $defaultpin );
149
			}
148
			}
150
 
149
			
151
			for($i = 0; $i < count ( $moreshowaddress ); $i ++) {
150
			for($i = 0; $i < count ( $moreshowaddress ); $i ++) {
152
				array_push ( $firstshowaddress, $moreshowaddress [$i] );
151
				array_push ( $firstshowaddress, $moreshowaddress [$i] );
153
			}
152
			}
154
 
153
			
155
			$this->set ( 'address', $response );
154
			$this->set ( 'address', $response );
156
 
155
			
157
			$this->set ( compact ( 'stateres','firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount') );
156
			$this->set ( compact ( 'stateres','firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount') );
158
		}
157
		}
159
	}
158
	}
160
	public function add($user_name = null, $user_contact = null) {
159
	public function add($user_name = null, $user_contact = null) {
161
		$this->layout = 'cartinnerpages';
160
		$this->layout = 'cartinnerpages';
162
 
161
		
163
		$totalPayable = $_SESSION ['totalPayable'];
162
		$totalPayable = $_SESSION ['totalPayable'];
164
		$codAvailable = $_SESSION ['cod'];
163
		$codAvailable = $_SESSION ['cod'];
165
 
164
 
166
		$taxInvoiceEnabledUser = $_SESSION['taxInvoiceEnabledUser'];
165
		$taxInvoiceEnabledUser = $_SESSION['taxInvoiceEnabledUser'];
167
		//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
166
		//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
168
		$pinval='';
167
		$pinval='';
169
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
168
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
170
		$scart = base64_decode ( $_COOKIE ['s_cart'] );
169
		$scart = base64_decode ( $_COOKIE ['s_cart'] );
171
 
170
		
172
		if ($this->request->is ( 'post' )) {
171
		if ($this->request->is ( 'post' )) {
173
			$data = $this->request->data;
172
			$data = $this->request->data;
174
 
173
			
175
			$senddata ['name'] = $data ['name'];
174
			$senddata ['name'] = $data ['name'];
176
			$senddata ['line1'] = $data ['line1'];
175
			$senddata ['line1'] = $data ['line1'];
177
			$senddata ['line2'] = "";
176
			$senddata ['line2'] = "";
178
			$senddata ['city'] = $data ['city'];
177
			$senddata ['city'] = $data ['city'];
179
			$senddata ['state'] = $data ['state'];
178
			$senddata ['state'] = $data ['state'];
180
			$senddata ['pin'] = $data ['pin'];
179
			$senddata ['pin'] = $data ['pin'];
181
			$senddata ['phone'] = $data ['phone'];
180
			$senddata ['phone'] = $data ['phone'];
182
			$senddata ['country'] = 'India';
181
			$senddata ['country'] = 'India';
183
			$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";
182
			$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";
184
 
183
			
185
			$response = $this->post_request ( $url, $senddata );
184
			$response = $this->post_request ( $url, $senddata );
186
 
185
			
187
			$scartId = base64_decode ( $_COOKIE ['s_cart'] );
186
			$scartId = base64_decode ( $_COOKIE ['s_cart'] );
188
			$semailId = base64_decode ( $_COOKIE ['s_email'] );
187
			$semailId = base64_decode ( $_COOKIE ['s_email'] );
189
			$blank = array ();
188
			$blank = array ();
190
			$postData = array (
189
			$postData = array (
191
					'cartItems' => $blank 
190
					'cartItems' => $blank 
192
			);
191
			);
193
 
192
			
194
			$params = array (
193
			$params = array (
195
					'cartMap' => urlencode ( json_encode ( $postData ) ) 
194
					'cartMap' => urlencode ( json_encode ( $postData ) ) 
196
			);
195
			);
197
			$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
196
			$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
198
			// if($pin!='0'){
197
			// if($pin!='0'){
Line 212... Line 211...
212
						$checkestimate = 'false';
211
						$checkestimate = 'false';
213
						break;
212
						break;
214
					}
213
					}
215
				}
214
				}
216
			}
215
			}
217
 
216
			
218
			if ($checkestimate == 'false') {
217
			if ($checkestimate == 'false') {
219
				// debug("I am here");
218
				// debug("I am here");
220
				$this->Session->setFlash ( "Address is not serviceable", 'default', array (
219
				$this->Session->setFlash ( "Address is not serviceable", 'default', array (
221
						'class' => 'alert alert-danger custom_class' 
220
						'class' => 'alert alert-danger custom_class' 
222
						) );
221
				) );
223
						// $this->Session->setFlash('Address is not serviceable');
222
				// $this->Session->setFlash('Address is not serviceable');
224
						return $this->redirect ( array (
223
				return $this->redirect ( array (
225
						'action' => 'index' 
224
						'action' => 'index' 
226
						) );
225
				) );
227
			} else {
226
			} else {
228
				$this->Session->setFlash ( "Address is  serviceable" );
227
				$this->Session->setFlash ( "Address is  serviceable" );
229
			}
228
			}
230
		}
229
		}
231
 
230
		
232
		$url = $this->apihost . "pincodeValidation/" . $pinval;
231
		$url = $this->apihost . "pincodeValidation/" . $pinval;
233
		$getstate = $this->make_request ( $url, null );
232
		$getstate = $this->make_request ( $url, null );
234
		// debug($getstate);
233
		// debug($getstate);
235
		$getstateval = "";
234
		$getstateval = "";
236
		if ($getstate != "{}") {
235
		if ($getstate != "{}") {
237
			$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
236
			$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
238
		}
237
		}
239
		$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount'));
238
		$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount'));
240
	}
239
	}
241
 
240
	
242
 
241
	
243
	public function submitcheck() {
242
	public function submitcheck() {
244
		$this->autoRender = false;
243
		$this->autoRender = false;
245
		$this->request->onlyAllow ( 'ajax' );
244
		$this->request->onlyAllow ( 'ajax' );
246
 
245
		
247
		$suserId = base64_decode($_COOKIE['s_id']);
246
		$suserId = base64_decode($_COOKIE['s_id']);
248
		$scartId = base64_decode($_COOKIE['s_cart']);
247
		$scartId = base64_decode($_COOKIE['s_cart']);
249
		$semailId = base64_decode($_COOKIE['s_email']);
248
		$semailId = base64_decode($_COOKIE['s_email']);
250
 
249
		
251
		$data = $this->request->data;
250
		$data = $this->request->data;
252
 
251
		
253
		$senddata ['name'] = $data ['name'];
252
		$senddata ['name'] = $data ['name'];
254
		$senddata ['line1'] = $data ['line1'];
253
		$senddata ['line1'] = $data ['line1'];
255
		$senddata ['line2'] = "";
254
		$senddata ['line2'] = "";
256
		$senddata ['city'] = $data ['city'];
255
		$senddata ['city'] = $data ['city'];
257
		$senddata ['state'] = $data ['state'];
256
		$senddata ['state'] = $data ['state'];
258
		$senddata ['pin'] = $data ['pin'];
257
		$senddata ['pin'] = $data ['pin'];
259
		$senddata ['phone'] = $data ['phone'];
258
		$senddata ['phone'] = $data ['phone'];
260
		$senddata ['country'] = 'India';
259
		$senddata ['country'] = 'India';
261
		setcookie('s_pincode', base64_encode($data['pin']), -1, '/');
260
		setcookie('s_pincode', base64_encode($data['pin']), -1, '/');
262
		$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scartId . "&isPrivateDealUser=true";
261
		$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scartId . "&isPrivateDealUser=true";
263
 
262
		
264
		$response = $this->post_cartinfo_request($url,$senddata);
263
		$response = $this->post_cartinfo_request($url,$senddata);
265
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
264
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
266
 
265
		
267
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
266
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
268
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
267
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
269
 
268
 
270
		$cartItems = array();
269
		$cartItems = array();
271
		foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {
270
		foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {
272
			$itemobj = array('itemId'   => $key, 'quantity' => $obj->quantity);
271
		    $itemobj = array('itemId'   => $key, 'quantity' => $obj->quantity);
273
			array_push($cartItems, $itemobj);
272
			array_push($cartItems, $itemobj);
274
		}
273
		}
275
		$postData = array('cartItems'	=>	$cartItems);
274
		$postData = array('cartItems'	=>	$cartItems);
276
		$params = array('cartMap' => urlencode(json_encode($postData)));
275
		$params = array('cartMap' => urlencode(json_encode($postData)));
277
 
276
		
278
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
277
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
279
		$url = $url . '&pinCode=' . $data ['pin'];
278
		$url = $url . '&pinCode=' . $data ['pin'];
280
		$cartskus = $this->post_cartinfo_request ( $url, $params );
279
		$cartskus = $this->post_cartinfo_request ( $url, $params );
281
 
280
 
282
		$checkestimate = $response ['defaultAddress'];
281
		$checkestimate = $response ['defaultAddress'];
283
		if (count($cartskus['cartMessages'])>0) {
282
		if (count($cartskus['cartMessages'])>0) {
284
			$checkestimate = 'cart_redirect';
283
			$checkestimate = 'cart_redirect';
285
		}
284
		}
286
		return $checkestimate;
285
		return $checkestimate;
287
	}
286
	}
288
 
287
	
289
	public function isServicable($pin) {
288
	public function isServicable($pin) {
290
		$this->autoRender = false;
289
		$this->autoRender = false;
291
		$this->request->onlyAllow ( 'ajax' );
290
		$this->request->onlyAllow ( 'ajax' );
292
		$data = $this->request->data;
291
		$data = $this->request->data;
293
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
292
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
294
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
293
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
295
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
294
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
296
 
295
		
297
		$cartItems = array();
296
		$cartItems = array();
298
		foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {
297
		foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {
299
			$itemobj = array('itemId'   => $key, 'quantity' => $obj->quantity);
298
		    $itemobj = array('itemId'   => $key, 'quantity' => $obj->quantity);
300
			array_push($cartItems, $itemobj);
299
			array_push($cartItems, $itemobj);
301
		}
300
		}
302
		$postData = array('cartItems'	=>	$cartItems);
301
		$postData = array('cartItems'	=>	$cartItems);
303
		$params = array('cartMap' => urlencode(json_encode($postData)));
302
		$params = array('cartMap' => urlencode(json_encode($postData)));
304
 
303
		
305
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
304
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
306
		$url = $url . '&pinCode=' . $pin;
305
		$url = $url . '&pinCode=' . $pin;
307
		$cartskus = $this->post_cartinfo_request ( $url, $params );
306
		$cartskus = $this->post_cartinfo_request ( $url, $params );
308
 
307
		
309
		if( $cartskus['maxEstimate']==-1){
308
		if($cartskus['maxEstimate']==-1){
310
			$checkestimate = 'non_service';
309
			$checkestimate = 'non_service';
311
		}
310
		}
312
		else if (count($cartskus['cartMessages'])>0) {
311
		else if (count($cartskus['cartMessages'])>0) {
313
			$checkestimate = 'cart_redirect';
312
			$checkestimate = 'cart_redirect';
314
			setcookie('s_pincode', base64_encode($pin), -1, '/');
313
			setcookie('s_pincode', base64_encode($pin), -1, '/');
Line 316... Line 315...
316
			setcookie('s_pincode', base64_encode($pin), -1, '/');
315
			setcookie('s_pincode', base64_encode($pin), -1, '/');
317
			$checkestimate = 'ok';
316
			$checkestimate = 'ok';
318
		}
317
		}
319
		return $checkestimate;
318
		return $checkestimate;
320
	}
319
	}
321
 
320
	
322
	public function getstate($pin_val) {
321
	public function getstate($pin_val) {
323
		$this->autoRender = false;
322
		$this->autoRender = false;
324
		$this->request->onlyAllow ( 'ajax' );
323
		$this->request->onlyAllow ( 'ajax' );
325
		$url = $this->apihost . "pincodeValidation/" . $pin_val;
324
		$url = $this->apihost . "pincodeValidation/" . $pin_val;
326
		$getstate = $this->make_request ( $url, null );
325
		$getstate = $this->make_request ( $url, null );
Line 329... Line 328...
329
		if ($getstate != "{}") {
328
		if ($getstate != "{}") {
330
			$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );
329
			$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );
331
		}
330
		}
332
		return json_encode ( $getstate );
331
		return json_encode ( $getstate );
333
	}
332
	}
334
 
333
	
335
 
334
	
336
 
335
	
337
	public function checkout(){
336
	 public function checkout(){
338
		$addressid = $this->request->data['addressid'];
337
	 	$addressid = $this->request->data['addressid'];
339
		$pincode = 0;
338
	 	$pincode = 0;
340
		$cod = $this->request->query('cod');
339
		$cod = $this->request->query('cod');
341
		$userId = $this->request->query('user_id');
340
		$userId = $this->request->query('user_id');
342
		$walletUsed = $this->request->data('walletUsed');
341
		$walletUsed = $this->request->data('walletUsed');
343
 
342
		
344
		//Added token validation to ensure only user
343
		//Added token validation to ensure only user 
345
		$testCheck = Configure::read('requireusercheck');
344
		$testCheck = Configure::read('requireusercheck');
346
		$tokenValidated = 0;
345
		$tokenValidated = 0;
347
		if($testCheck){
346
		if($testCheck){
348
			$tokenValidated = $this->checkToken($userId);
347
			$tokenValidated = $this->checkToken($userId);
349
		}else{
348
		}else{
350
			$tokenValidated = 1;
349
			$tokenValidated = 1;
351
		}
350
		}
352
 
351
	
353
		if(!empty($userId) && $tokenValidated==1){
352
		if(!empty($userId) && $tokenValidated==1){			
354
			$url = $this->getAutoLoginUrl($userId,$url);
353
			$url = $this->getAutoLoginUrl($userId,$url);
355
 
354
	
356
			if(isset($this->request->data->pincode)){
355
			if(isset($this->request->data->pincode)){
357
				$pincode = $this->request->data->pincode;
356
				$pincode = $this->request->data->pincode;
358
			}
357
			}
359
			if($pincode==0 && isset($_COOKIE['s_pincode'])){
358
			if($pincode==0 && isset($_COOKIE['s_pincode'])){
360
				$pincode = base64_decode($_COOKIE['s_pincode']);
359
				$pincode = base64_decode($_COOKIE['s_pincode']);
361
			}
360
			}
362
 
361
		 	
363
			$suserId = base64_decode($_COOKIE['s_id']);
362
			$suserId = base64_decode($_COOKIE['s_id']);
364
			$scartId = base64_decode($_COOKIE['s_cart']);
363
			$scartId = base64_decode($_COOKIE['s_cart']);
365
			$semailId = base64_decode($_COOKIE['s_email']);
364
			$semailId = base64_decode($_COOKIE['s_email']);
366
 
365
			
367
			if(isset($_COOKIE['txn_comp'])) {
366
			if(isset($_COOKIE['txn_comp'])) {
368
				unset($_COOKIE['txn_comp']);
367
				unset($_COOKIE['txn_comp']);
369
			}
368
			}
370
 
369
			
371
			if($cod==1){
370
			if($cod==1){
372
				$url = Configure::read('saholicapihost').'order?payment_option=COD~3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
371
				$url = Configure::read('saholicapihost').'order?payment_option=COD~3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
373
				if(isset($walletUsed)) {
372
				if(isset($walletUsed)) {
374
					$url .= '&walletUsed='.$walletUsed;
373
					$url .= '&walletUsed='.$walletUsed;
375
				}
374
				}
376
				if($pincode!='0'){
375
			 	if($pincode!='0'){
377
					$url = $url.'&pinCode='.$pincode;
376
					$url = $url.'&pinCode='.$pincode;
378
				}
377
				}
379
				$orderCreationResponse = $this->post_cartinfo_request($url, null);
378
				$orderCreationResponse = $this->post_cartinfo_request($url, null);
380
				//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
379
				//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
381
				$redirecturl = $orderCreationResponse['response']['redirectUrl'];
380
				$redirecturl = $orderCreationResponse['response']['redirectUrl'];
382
				if (strpos($redirecturl,'pay-success') === false) {
381
				if (strpos($redirecturl,'pay-success') === false) {
383
					setcookie('txn_comp', 'no', -1, '/');
382
				    setcookie('txn_comp', 'no', -1, '/');
384
				} else {
383
				} else {
385
					$order_det = array();
384
					$order_det = array();
386
					$this->loadModel('Order');
385
					$this->loadModel('Order');
387
					$order_det['user_id'] = $this->Auth->User('id');
386
					$order_det['user_id'] = $this->Auth->User('id');
388
					$order_det['store_id'] = 4;
387
					$order_det['store_id'] = 4;
389
					$order_det['order_url'] = $this->mobileapihost.$redirecturl;
388
					$order_det['order_url'] = $this->mobileapihost.$redirecturl;
390
					$this->log(print_r($order_det,1),'ordersdet');
389
					$this->log(print_r($order_det,1),'ordersdet');
391
					$this->Order->create();
390
					$this->Order->create();
392
 
391
					
393
					if ($this->Order->save($order_det)) {
392
					if ($this->Order->save($order_det)) {
394
						$id = $this->Order->getLastInsertID();
393
						$id = $this->Order->getLastInsertID();
395
						$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
394
						$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
396
						$apihost = Configure::read('pythonapihost');
395
						$apihost = Configure::read('pythonapihost');
397
						$url = $apihost."storeorder";
396
						$url = $apihost."storeorder";
398
 
397
						
399
						$this->log(print_r($url,1),'ordersdet');
398
						$this->log(print_r($url,1),'ordersdet');
400
 
399
						
401
						$this->log(print_r($order,1),'ordersdet');
400
						$this->log(print_r($order,1),'ordersdet');
402
						$response = array();
401
						$response = array();
403
						// 					$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
402
	// 					$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
404
						if(!empty($order)) {
403
						if(!empty($order)) {
405
							$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
404
							$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
406
							$jsonVar = json_encode($params);
405
							$jsonVar = json_encode($params);
407
							$response =  $this->make_request($url,$jsonVar);
406
							$response =  $this->make_request($url,$jsonVar);
408
						}else{
407
						}else{
Line 426... Line 425...
426
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
425
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
427
								$this->log(print_r('insideelse',1),'ordersdet');
426
								$this->log(print_r('insideelse',1),'ordersdet');
428
							}
427
							}
429
							$this->log(print_r($sql,1),'ordersdet');
428
							$this->log(print_r($sql,1),'ordersdet');
430
							$this->Order->query($sql);
429
							$this->Order->query($sql);
431
 
430
							
432
						}
431
						}					
433
					}
432
					}
434
				}
433
				}
435
				$this->layout = 'innerpages';
434
				$this->layout = 'innerpages';
436
				$redirecturl = str_replace("pay-success","pay-success1", $redirecturl);
435
				$redirecturl = str_replace("pay-success","pay-success1", $redirecturl);
437
				$next = $redirecturl;
436
				$next = $redirecturl;					
438
				$redirectUrl = $this->getBigUtsavAutoLoginUrl($userId,$next);
437
				$redirectUrl = $this->getBigUtsavAutoLoginUrl($userId,$next);
439
				$this->log($redirectUrl,'headers');
438
				$this->log($redirectUrl,'headers');
440
				$this->set(compact('redirectUrl','next'));
439
				$this->set(compact('redirectUrl','next'));
441
			}else{
440
			}else{
442
				$dataGiven = json_decode($this->request->data['cart_details']);
441
				$dataGiven = json_decode($this->request->data['cart_details']);
443
				if($walletUsed==$this->Session->read('totalPayable')){
442
				if($walletUsed==$this->Session->read('totalPayable')){
444
					$url = Configure::read('saholicapihost').'order?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid.'&walletUsed='.$walletUsed.'&payment_option=7890';
443
					$url = Configure::read('saholicapihost').'order?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid.'&walletUsed='.$walletUsed.'&payment_option=7890';
445
					if($pincode!='0'){
444
				 	if($pincode!='0'){
446
						$url = $url.'&pinCode='.$pincode;
445
						$url = $url.'&pinCode='.$pincode;
447
					}
446
					}
448
					$orderCreationResponse = $this->post_cartinfo_request($url, null);
447
					$orderCreationResponse = $this->post_cartinfo_request($url, null);
449
					//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
448
					//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
450
					$redirecturl = $orderCreationResponse['response']['redirectUrl'];
449
					$redirecturl = $orderCreationResponse['response']['redirectUrl'];
451
					if (strpos($redirecturl,'pay-success') === false) {
450
					if (strpos($redirecturl,'pay-success') === false) {
452
						setcookie('txn_comp', 'no', -1, '/');
451
					    setcookie('txn_comp', 'no', -1, '/');
453
					} else {
452
					} else {
454
						$order_det = array();
453
						$order_det = array();
455
						$this->loadModel('Order');
454
						$this->loadModel('Order');
456
						$order_det['user_id'] = $this->Auth->User('id');
455
						$order_det['user_id'] = $this->Auth->User('id');
457
						$order_det['store_id'] = 4;
456
						$order_det['store_id'] = 4;
458
						$order_det['order_url'] = $this->mobileapihost.$redirecturl;
457
						$order_det['order_url'] = $this->mobileapihost.$redirecturl;
459
						$this->log(print_r($order_det,1),'ordersdet');
458
						$this->log(print_r($order_det,1),'ordersdet');
460
						$this->Order->create();
459
						$this->Order->create();
461
 
460
						
462
						if ($this->Order->save($order_det)) {
461
						if ($this->Order->save($order_det)) {
463
							$id = $this->Order->getLastInsertID();
462
							$id = $this->Order->getLastInsertID();
464
							$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
463
							$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
465
							$apihost = Configure::read('pythonapihost');
464
							$apihost = Configure::read('pythonapihost');
466
							$url = $apihost."storeorder";
465
							$url = $apihost."storeorder";
467
 
466
							
468
							$this->log(print_r($url,1),'ordersdet');
467
							$this->log(print_r($url,1),'ordersdet');
469
 
468
							
470
							$this->log(print_r($order,1),'ordersdet');
469
							$this->log(print_r($order,1),'ordersdet');
471
							$response = array();
470
							$response = array();
472
							if(!empty($order)) {
471
							if(!empty($order)) {
473
								$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
472
								$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
474
								$jsonVar = json_encode($params);
473
								$jsonVar = json_encode($params);
Line 493... Line 492...
493
									$result =array('success'=>true,'message'=> $response['result']);
492
									$result =array('success'=>true,'message'=> $response['result']);
494
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
493
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
495
									$this->log(print_r('insideelse',1),'ordersdet');
494
									$this->log(print_r('insideelse',1),'ordersdet');
496
								}
495
								}
497
								$this->Order->query($sql);
496
								$this->Order->query($sql);
498
 
-
 
499
							}
497
								
-
 
498
							}					
500
						}
499
						}
501
					}
500
					}
502
					$this->layout = 'innerpages';
501
					$this->layout = 'innerpages';
503
					$next = $redirecturl;
502
					$next = $redirecturl;					
504
					$redirectUrl = $this->getBigUtsavAutoLoginUrl($userId,$next);
503
					$redirectUrl = $this->getBigUtsavAutoLoginUrl($userId,$next);
505
					$redirectToCart = true;
504
					$redirectToCart = true;
506
					$this->log($redirectUrl,'headers');
505
					$this->log($redirectUrl,'headers');
507
					$this->set(compact('redirectUrl','next','redirectToCart'));
506
					$this->set(compact('redirectUrl','next','redirectToCart'));
-
 
507
				}else{
-
 
508
					$totalSkus= intval($dataGiven->totalSkus);
-
 
509
					setcookie('txn_comp', 'no', -1, '/');
-
 
510
					$this->layout = 'innerpages';
-
 
511
					$next = "payment1?cq=".$totalSkus.'&addressid='.$addressid;
-
 
512
					if(isset($walletUsed)) {
-
 
513
						$next .= '&walletUsed='.$walletUsed;
-
 
514
					}					
-
 
515
					$redirectUrl = $this->getBigUtsavAutoLoginUrl($userId,$next);
-
 
516
					$this->log($redirectUrl,'headers');
-
 
517
					$this->set(compact('redirectUrl','next'));
508
				}
518
				}
509
			}
519
			}
510
		} else {
520
		} else {
511
			if($tokenValidated == 0){
521
			if($tokenValidated == 0){
512
				$url = '/special/native/login';
522
				$url = '/special/native/login';
513
			}elseif($tokenValidated == -1){
523
			}elseif($tokenValidated == -1){
514
				$url = '/abouts/askforupdate';
524
				$url = '/abouts/askforupdate';
515
			}
525
			}
516
			$this->redirect($url);
526
			$this->redirect($url);
517
		}
527
		}
518
	}
-
 
519
 
-
 
520
	public function createSaholicOrder() {
-
 
521
		 $order_det = array();
-
 
522
		 $this->loadModel('Order');
-
 
523
		 $order_det['user_id'] = $this->Auth->User('id');
-
 
524
		 $order_det['store_id'] = 4;
-
 
525
		 $order_det['order_url'] = $this->mobileapihost.$redirecturl;
-
 
526
		 $this->log(print_r($order_det,1),'ordersdet');
-
 
527
		 $this->Order->create();
-
 
528
	
-
 
529
		 if ($this->Order->save($order_det)) {
-
 
530
		 	$id = $this->Order->getLastInsertID();
-
 
531
		 	$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
-
 
532
		 	$apihost = Configure::read('pythonapihost');
-
 
533
		 	$url = $apihost."storeorder";
-
 
534
	
-
 
535
		 	$this->log(print_r($url,1),'ordersdet');
-
 
536
	
-
 
537
		 	$this->log(print_r($order,1),'ordersdet');
-
 
538
		 	$response = array();
-
 
539
		 	if(!empty($order)) {
-
 
540
		 		$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
528
	 }
541
		 		$jsonVar = json_encode($params);
-
 
542
		 		$response =  $this->make_request($url,$jsonVar);
-
 
543
		 	}else{
-
 
544
		 		$result = array('success'=>false,'message'=>'Empty order array');
-
 
545
		 		$response = $result;
-
 
546
		 	}
-
 
547
		 	$this->log(print_r($response,1),'ordersdet');
-
 
548
		 	if(!empty($response) && $response['result']) {
-
 
549
		 			$result =array('success'=>true,'message'=> $response['result']);
-
 
550
		 			$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
-
 
551
		 			$this->log(print_r('insideelse',1),'ordersdet');
-
 
552
			 		$this->Order->query($sql);
-
 
553
		 		}
-
 
554
		 	}
-
 
555
		 }
-
 
556
	}
-
 
557
}
529
}