Subversion Repositories SmartDukaan

Rev

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

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