| 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 |
|
| 22465 |
amit.gupta |
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
| 17793 |
naman |
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 |
}
|
| 22465 |
amit.gupta |
24 |
|
| 17793 |
naman |
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 |
}
|
| 22465 |
amit.gupta |
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']);
|
| 22465 |
amit.gupta |
36 |
|
| 17871 |
manish.sha |
37 |
$pincode = 0;
|
| 22465 |
amit.gupta |
38 |
|
| 17871 |
manish.sha |
39 |
if($pincode==0 && isset($_COOKIE['s_pincode'])){
|
|
|
40 |
$pincode = base64_decode($_COOKIE['s_pincode']);
|
| 19035 |
naman |
41 |
$url = $this->apihost . "pincodeValidation/" . $pincode;
|
| 22465 |
amit.gupta |
42 |
$getstate = $this->make_request ( $url, null );
|
| 19035 |
naman |
43 |
if ($getstate != "{}") {
|
|
|
44 |
$stateres = ucwords ( strtolower ( $getstate ['state'] ) );
|
|
|
45 |
}
|
| 17793 |
naman |
46 |
}
|
| 22465 |
amit.gupta |
47 |
|
| 17871 |
manish.sha |
48 |
$cartItems = array();
|
| 22465 |
amit.gupta |
49 |
|
| 17871 |
manish.sha |
50 |
foreach ($dataGiven->cartItems as $key=>$obj) {
|
| 22465 |
amit.gupta |
51 |
$itemobj = array('itemId' => $key, 'quantity' => $obj->quantity);
|
| 17871 |
manish.sha |
52 |
array_push($cartItems, $itemobj);
|
| 17838 |
manish.sha |
53 |
}
|
| 20978 |
amit.gupta |
54 |
$postData = array('cartItems' => $cartItems);
|
|
|
55 |
$params = array('cartMap' => urlencode(json_encode($postData)));
|
| 22465 |
amit.gupta |
56 |
|
| 17871 |
manish.sha |
57 |
$this->layout = 'cartinnerpages';
|
|
|
58 |
$url = Configure::read('saholicapihost').'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId;
|
|
|
59 |
if($pincode!='0'){
|
|
|
60 |
$url = $url.'&pinCode='.$pincode;
|
|
|
61 |
}
|
|
|
62 |
$cartskus = $this->post_cartinfo_request($url,$params);
|
|
|
63 |
if(isset($cartskus['response']) && $cartskus['response']=='error'){
|
|
|
64 |
$this->set(compact('cartskus'));
|
|
|
65 |
$this->render('/Users/cartdetails');
|
| 22465 |
amit.gupta |
66 |
|
| 17871 |
manish.sha |
67 |
}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
|
|
|
68 |
setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
|
|
|
69 |
$this->set(compact('cartskus'));
|
|
|
70 |
$this->render('/Users/cartdetails');
|
|
|
71 |
}else{
|
|
|
72 |
$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
|
|
|
73 |
$this->Session->write('totalPayable', $totalPayable);
|
|
|
74 |
$this->layout = 'innerpages';
|
| 17882 |
naman |
75 |
$url = Configure::read ( 'saholicapihost' ) . 'address?isLoggedIn=true&privateDealUser=true&userId=' . $suserId;
|
|
|
76 |
$response = $this->make_request ( $url, null );
|
|
|
77 |
$user_name = "";
|
|
|
78 |
$user_contact = "";
|
| 20633 |
amit.gupta |
79 |
$codAvailable = $cartskus['cod'];
|
|
|
80 |
//$codAvailable = false;
|
| 17947 |
manish.sha |
81 |
$this->Session->write('cod', $codAvailable);
|
| 20863 |
amit.gupta |
82 |
$walletAmount = 0;
|
|
|
83 |
if(array_key_exists('walletAmount',$response)){
|
|
|
84 |
$walletAmount = $response ['walletAmount'];
|
| 22465 |
amit.gupta |
85 |
}
|
| 20863 |
amit.gupta |
86 |
//$creditorAssociated
|
|
|
87 |
$this->Session->write('walletAmount', $walletAmount);
|
| 18734 |
manish.sha |
88 |
$taxInvoiceEnabledUser = $response ['taxInvoiceEnabledUser'];
|
|
|
89 |
$this->Session->write('taxInvoiceEnabledUser', $taxInvoiceEnabledUser);
|
| 22465 |
amit.gupta |
90 |
|
| 17882 |
naman |
91 |
if(empty($response ['addresses'])){
|
|
|
92 |
$this->redirect ( array (
|
|
|
93 |
'action' => 'add'
|
| 22465 |
amit.gupta |
94 |
));
|
| 17793 |
naman |
95 |
}
|
| 22465 |
amit.gupta |
96 |
|
| 17882 |
naman |
97 |
$firstshowaddress = array ();
|
|
|
98 |
$findedaddress = array ();
|
|
|
99 |
$moreshowaddress = array ();
|
|
|
100 |
$current_address_id = - 1;
|
|
|
101 |
$defaultpin = - 1;
|
|
|
102 |
$defaultcookiepin = - 1;
|
|
|
103 |
$defaultcheckedaddress = - 1;
|
|
|
104 |
$defaultpinaddress = - 1;
|
| 22465 |
amit.gupta |
105 |
|
| 17882 |
naman |
106 |
foreach ( $response ['addresses'] as $key => $value ) {
|
| 22465 |
amit.gupta |
107 |
|
| 17882 |
naman |
108 |
if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
|
|
|
109 |
$defaultcookiepin = $key;
|
|
|
110 |
$user_name = $value ['name'];
|
|
|
111 |
$user_contact = $value ['phone'];
|
|
|
112 |
if ($defaultcheckedaddress == - 1) {
|
|
|
113 |
$defaultcheckedaddress = $value ['id'];
|
|
|
114 |
}
|
|
|
115 |
} else if (intval ( $value ['pin'] ) == $pincode) {
|
|
|
116 |
$current_address_id = $key;
|
|
|
117 |
array_push ( $findedaddress, $key );
|
|
|
118 |
if ($defaultpinaddress == - 1) {
|
|
|
119 |
$defaultpinaddress = $value ['id'];
|
|
|
120 |
}
|
|
|
121 |
} else if ($value ['id'] == intval ( $response ['defaultAddress'] )) {
|
|
|
122 |
$defaultpin = $key;
|
|
|
123 |
$user_name = $value ['name'];
|
|
|
124 |
$user_contact = $value ['phone'];
|
|
|
125 |
} else {
|
|
|
126 |
array_push ( $moreshowaddress, $key );
|
| 17871 |
manish.sha |
127 |
}
|
|
|
128 |
}
|
| 22465 |
amit.gupta |
129 |
|
| 17882 |
naman |
130 |
$defaultselectedaddress = - 1;
|
|
|
131 |
if ($defaultpinaddress != - 1) {
|
|
|
132 |
$defaultselectedaddress = $defaultpinaddress;
|
| 17793 |
naman |
133 |
}
|
| 17882 |
naman |
134 |
if ($defaultcheckedaddress != - 1) {
|
|
|
135 |
$defaultselectedaddress = $defaultcheckedaddress;
|
| 17871 |
manish.sha |
136 |
}
|
| 22465 |
amit.gupta |
137 |
|
| 17882 |
naman |
138 |
if ($defaultcookiepin != - 1) {
|
|
|
139 |
array_push ( $firstshowaddress, $defaultcookiepin );
|
| 17871 |
manish.sha |
140 |
}
|
| 22465 |
amit.gupta |
141 |
|
| 17882 |
naman |
142 |
for($i = 0; $i < count ( $findedaddress ); $i ++) {
|
|
|
143 |
array_push ( $firstshowaddress, $findedaddress [$i] );
|
| 17871 |
manish.sha |
144 |
}
|
| 22465 |
amit.gupta |
145 |
|
| 17882 |
naman |
146 |
if ($defaultpin != - 1) {
|
|
|
147 |
array_push ( $firstshowaddress, $defaultpin );
|
|
|
148 |
}
|
| 22465 |
amit.gupta |
149 |
|
| 17882 |
naman |
150 |
for($i = 0; $i < count ( $moreshowaddress ); $i ++) {
|
|
|
151 |
array_push ( $firstshowaddress, $moreshowaddress [$i] );
|
|
|
152 |
}
|
| 22465 |
amit.gupta |
153 |
|
| 17882 |
naman |
154 |
$this->set ( 'address', $response );
|
| 22465 |
amit.gupta |
155 |
|
| 20863 |
amit.gupta |
156 |
$this->set ( compact ( 'stateres','firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount') );
|
| 17793 |
naman |
157 |
}
|
| 17882 |
naman |
158 |
}
|
|
|
159 |
public function add($user_name = null, $user_contact = null) {
|
|
|
160 |
$this->layout = 'cartinnerpages';
|
| 22465 |
amit.gupta |
161 |
|
| 17882 |
naman |
162 |
$totalPayable = $_SESSION ['totalPayable'];
|
| 17947 |
manish.sha |
163 |
$codAvailable = $_SESSION ['cod'];
|
| 20863 |
amit.gupta |
164 |
|
| 18734 |
manish.sha |
165 |
$taxInvoiceEnabledUser = $_SESSION['taxInvoiceEnabledUser'];
|
| 18039 |
amit.gupta |
166 |
//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
|
|
|
167 |
$pinval='';
|
| 17882 |
naman |
168 |
$suserId = base64_decode ( $_COOKIE ['s_id'] );
|
|
|
169 |
$scart = base64_decode ( $_COOKIE ['s_cart'] );
|
| 22465 |
amit.gupta |
170 |
|
| 17882 |
naman |
171 |
if ($this->request->is ( 'post' )) {
|
| 17793 |
naman |
172 |
$data = $this->request->data;
|
| 22465 |
amit.gupta |
173 |
|
| 17882 |
naman |
174 |
$senddata ['name'] = $data ['name'];
|
|
|
175 |
$senddata ['line1'] = $data ['line1'];
|
|
|
176 |
$senddata ['line2'] = "";
|
|
|
177 |
$senddata ['city'] = $data ['city'];
|
|
|
178 |
$senddata ['state'] = $data ['state'];
|
|
|
179 |
$senddata ['pin'] = $data ['pin'];
|
|
|
180 |
$senddata ['phone'] = $data ['phone'];
|
|
|
181 |
$senddata ['country'] = 'India';
|
|
|
182 |
$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";
|
| 22465 |
amit.gupta |
183 |
|
| 17882 |
naman |
184 |
$response = $this->post_request ( $url, $senddata );
|
| 22465 |
amit.gupta |
185 |
|
| 17882 |
naman |
186 |
$scartId = base64_decode ( $_COOKIE ['s_cart'] );
|
|
|
187 |
$semailId = base64_decode ( $_COOKIE ['s_email'] );
|
|
|
188 |
$blank = array ();
|
|
|
189 |
$postData = array (
|
|
|
190 |
'cartItems' => $blank
|
|
|
191 |
);
|
| 22465 |
amit.gupta |
192 |
|
| 17882 |
naman |
193 |
$params = array (
|
|
|
194 |
'cartMap' => urlencode ( json_encode ( $postData ) )
|
|
|
195 |
);
|
|
|
196 |
$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
|
|
|
197 |
// if($pin!='0'){
|
|
|
198 |
$url = $url . '&pinCode=' . $data ['pin'];
|
|
|
199 |
// }
|
|
|
200 |
$cartskus = $this->post_cartinfo_request ( $url, $params );
|
|
|
201 |
$checkestimate = 'true';
|
|
|
202 |
if ($cartskus ['maxEstimate'] == - 1) {
|
|
|
203 |
$checkestimate = 'false';
|
|
|
204 |
} else {
|
|
|
205 |
for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
|
| 17904 |
amit.gupta |
206 |
if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
|
|
|
207 |
continue;
|
|
|
208 |
}
|
|
|
209 |
$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
|
|
|
210 |
if ($estimate==-1) {
|
| 17882 |
naman |
211 |
$checkestimate = 'false';
|
|
|
212 |
break;
|
|
|
213 |
}
|
|
|
214 |
}
|
| 17793 |
naman |
215 |
}
|
| 22465 |
amit.gupta |
216 |
|
| 17882 |
naman |
217 |
if ($checkestimate == 'false') {
|
|
|
218 |
// debug("I am here");
|
|
|
219 |
$this->Session->setFlash ( "Address is not serviceable", 'default', array (
|
|
|
220 |
'class' => 'alert alert-danger custom_class'
|
| 22465 |
amit.gupta |
221 |
) );
|
|
|
222 |
// $this->Session->setFlash('Address is not serviceable');
|
|
|
223 |
return $this->redirect ( array (
|
| 17882 |
naman |
224 |
'action' => 'index'
|
| 22465 |
amit.gupta |
225 |
) );
|
| 17882 |
naman |
226 |
} else {
|
|
|
227 |
$this->Session->setFlash ( "Address is serviceable" );
|
| 17793 |
naman |
228 |
}
|
|
|
229 |
}
|
| 22465 |
amit.gupta |
230 |
|
| 17882 |
naman |
231 |
$url = $this->apihost . "pincodeValidation/" . $pinval;
|
|
|
232 |
$getstate = $this->make_request ( $url, null );
|
| 17844 |
naman |
233 |
// debug($getstate);
|
| 17793 |
naman |
234 |
$getstateval = "";
|
| 17882 |
naman |
235 |
if ($getstate != "{}") {
|
|
|
236 |
$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
|
| 17793 |
naman |
237 |
}
|
| 20863 |
amit.gupta |
238 |
$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount'));
|
| 17793 |
naman |
239 |
}
|
| 22465 |
amit.gupta |
240 |
|
|
|
241 |
|
| 17882 |
naman |
242 |
public function submitcheck() {
|
|
|
243 |
$this->autoRender = false;
|
|
|
244 |
$this->request->onlyAllow ( 'ajax' );
|
| 22465 |
amit.gupta |
245 |
|
| 17899 |
amit.gupta |
246 |
$suserId = base64_decode($_COOKIE['s_id']);
|
|
|
247 |
$scartId = base64_decode($_COOKIE['s_cart']);
|
|
|
248 |
$semailId = base64_decode($_COOKIE['s_email']);
|
| 22465 |
amit.gupta |
249 |
|
| 17882 |
naman |
250 |
$data = $this->request->data;
|
| 22465 |
amit.gupta |
251 |
|
| 17882 |
naman |
252 |
$senddata ['name'] = $data ['name'];
|
|
|
253 |
$senddata ['line1'] = $data ['line1'];
|
|
|
254 |
$senddata ['line2'] = "";
|
|
|
255 |
$senddata ['city'] = $data ['city'];
|
|
|
256 |
$senddata ['state'] = $data ['state'];
|
|
|
257 |
$senddata ['pin'] = $data ['pin'];
|
|
|
258 |
$senddata ['phone'] = $data ['phone'];
|
|
|
259 |
$senddata ['country'] = 'India';
|
| 20978 |
amit.gupta |
260 |
setcookie('s_pincode', base64_encode($data['pin']), -1, '/');
|
| 17899 |
amit.gupta |
261 |
$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scartId . "&isPrivateDealUser=true";
|
| 22465 |
amit.gupta |
262 |
|
| 17899 |
amit.gupta |
263 |
$response = $this->post_cartinfo_request($url,$senddata);
|
| 17882 |
naman |
264 |
$suserId = base64_decode ( $_COOKIE ['s_id'] );
|
| 22465 |
amit.gupta |
265 |
|
| 17882 |
naman |
266 |
$scartId = base64_decode ( $_COOKIE ['s_cart'] );
|
|
|
267 |
$semailId = base64_decode ( $_COOKIE ['s_email'] );
|
| 20978 |
amit.gupta |
268 |
|
|
|
269 |
$cartItems = array();
|
|
|
270 |
foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {
|
| 22465 |
amit.gupta |
271 |
$itemobj = array('itemId' => $key, 'quantity' => $obj->quantity);
|
| 20978 |
amit.gupta |
272 |
array_push($cartItems, $itemobj);
|
|
|
273 |
}
|
|
|
274 |
$postData = array('cartItems' => $cartItems);
|
|
|
275 |
$params = array('cartMap' => urlencode(json_encode($postData)));
|
| 22465 |
amit.gupta |
276 |
|
| 17882 |
naman |
277 |
$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
|
|
|
278 |
$url = $url . '&pinCode=' . $data ['pin'];
|
|
|
279 |
$cartskus = $this->post_cartinfo_request ( $url, $params );
|
| 20978 |
amit.gupta |
280 |
|
| 17893 |
amit.gupta |
281 |
$checkestimate = $response ['defaultAddress'];
|
| 20978 |
amit.gupta |
282 |
if (count($cartskus['cartMessages'])>0) {
|
|
|
283 |
$checkestimate = 'cart_redirect';
|
| 17882 |
naman |
284 |
}
|
|
|
285 |
return $checkestimate;
|
|
|
286 |
}
|
| 22465 |
amit.gupta |
287 |
|
| 17882 |
naman |
288 |
public function isServicable($pin) {
|
|
|
289 |
$this->autoRender = false;
|
|
|
290 |
$this->request->onlyAllow ( 'ajax' );
|
| 20978 |
amit.gupta |
291 |
$data = $this->request->data;
|
| 17882 |
naman |
292 |
$scartId = base64_decode ( $_COOKIE ['s_cart'] );
|
|
|
293 |
$suserId = base64_decode ( $_COOKIE ['s_id'] );
|
|
|
294 |
$semailId = base64_decode ( $_COOKIE ['s_email'] );
|
| 22465 |
amit.gupta |
295 |
|
| 20978 |
amit.gupta |
296 |
$cartItems = array();
|
|
|
297 |
foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {
|
| 22465 |
amit.gupta |
298 |
$itemobj = array('itemId' => $key, 'quantity' => $obj->quantity);
|
| 20978 |
amit.gupta |
299 |
array_push($cartItems, $itemobj);
|
|
|
300 |
}
|
|
|
301 |
$postData = array('cartItems' => $cartItems);
|
|
|
302 |
$params = array('cartMap' => urlencode(json_encode($postData)));
|
| 22465 |
amit.gupta |
303 |
|
| 17882 |
naman |
304 |
$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
|
|
|
305 |
$url = $url . '&pinCode=' . $pin;
|
|
|
306 |
$cartskus = $this->post_cartinfo_request ( $url, $params );
|
| 22465 |
amit.gupta |
307 |
|
|
|
308 |
if($cartskus['maxEstimate']==-1){
|
| 20978 |
amit.gupta |
309 |
$checkestimate = 'non_service';
|
| 17882 |
naman |
310 |
}
|
| 20978 |
amit.gupta |
311 |
else if (count($cartskus['cartMessages'])>0) {
|
|
|
312 |
$checkestimate = 'cart_redirect';
|
| 21007 |
amit.gupta |
313 |
setcookie('s_pincode', base64_encode($pin), -1, '/');
|
| 20978 |
amit.gupta |
314 |
} else if ($cartskus['maxEstimate']>=0) {
|
| 21007 |
amit.gupta |
315 |
setcookie('s_pincode', base64_encode($pin), -1, '/');
|
| 20978 |
amit.gupta |
316 |
$checkestimate = 'ok';
|
|
|
317 |
}
|
| 17882 |
naman |
318 |
return $checkestimate;
|
|
|
319 |
}
|
| 22465 |
amit.gupta |
320 |
|
| 20978 |
amit.gupta |
321 |
public function getstate($pin_val) {
|
|
|
322 |
$this->autoRender = false;
|
|
|
323 |
$this->request->onlyAllow ( 'ajax' );
|
|
|
324 |
$url = $this->apihost . "pincodeValidation/" . $pin_val;
|
|
|
325 |
$getstate = $this->make_request ( $url, null );
|
|
|
326 |
// $getstate['state'] = ucwords(strtolower($getstate['state']));
|
|
|
327 |
$nothing = "nothing";
|
|
|
328 |
if ($getstate != "{}") {
|
|
|
329 |
$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );
|
|
|
330 |
}
|
|
|
331 |
return json_encode ( $getstate );
|
|
|
332 |
}
|
| 22465 |
amit.gupta |
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
public function checkout(){
|
|
|
337 |
$addressid = $this->request->data['addressid'];
|
|
|
338 |
$pincode = 0;
|
| 17871 |
manish.sha |
339 |
$cod = $this->request->query('cod');
|
| 17846 |
manish.sha |
340 |
$userId = $this->request->query('user_id');
|
| 20863 |
amit.gupta |
341 |
$walletUsed = $this->request->data('walletUsed');
|
| 22465 |
amit.gupta |
342 |
|
|
|
343 |
//Added token validation to ensure only user
|
| 18834 |
manish.sha |
344 |
$testCheck = Configure::read('requireusercheck');
|
| 18832 |
manish.sha |
345 |
$tokenValidated = 0;
|
|
|
346 |
if($testCheck){
|
| 18834 |
manish.sha |
347 |
$tokenValidated = $this->checkToken($userId);
|
| 18832 |
manish.sha |
348 |
}else{
|
| 18834 |
manish.sha |
349 |
$tokenValidated = 1;
|
| 18832 |
manish.sha |
350 |
}
|
| 22465 |
amit.gupta |
351 |
|
|
|
352 |
if(!empty($userId) && $tokenValidated==1){
|
| 18619 |
amit.gupta |
353 |
$url = $this->getAutoLoginUrl($userId,$url);
|
| 22465 |
amit.gupta |
354 |
|
| 18619 |
amit.gupta |
355 |
if(isset($this->request->data->pincode)){
|
|
|
356 |
$pincode = $this->request->data->pincode;
|
| 17871 |
manish.sha |
357 |
}
|
| 18619 |
amit.gupta |
358 |
if($pincode==0 && isset($_COOKIE['s_pincode'])){
|
|
|
359 |
$pincode = base64_decode($_COOKIE['s_pincode']);
|
|
|
360 |
}
|
| 22465 |
amit.gupta |
361 |
|
| 18619 |
amit.gupta |
362 |
$suserId = base64_decode($_COOKIE['s_id']);
|
|
|
363 |
$scartId = base64_decode($_COOKIE['s_cart']);
|
|
|
364 |
$semailId = base64_decode($_COOKIE['s_email']);
|
| 22465 |
amit.gupta |
365 |
|
| 18619 |
amit.gupta |
366 |
if(isset($_COOKIE['txn_comp'])) {
|
|
|
367 |
unset($_COOKIE['txn_comp']);
|
|
|
368 |
}
|
| 22465 |
amit.gupta |
369 |
|
| 18619 |
amit.gupta |
370 |
if($cod==1){
|
| 20633 |
amit.gupta |
371 |
$url = Configure::read('saholicapihost').'order?payment_option=COD~3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
|
| 20863 |
amit.gupta |
372 |
if(isset($walletUsed)) {
|
| 20869 |
amit.gupta |
373 |
$url .= '&walletUsed='.$walletUsed;
|
| 20863 |
amit.gupta |
374 |
}
|
| 22465 |
amit.gupta |
375 |
if($pincode!='0'){
|
| 18619 |
amit.gupta |
376 |
$url = $url.'&pinCode='.$pincode;
|
|
|
377 |
}
|
|
|
378 |
$orderCreationResponse = $this->post_cartinfo_request($url, null);
|
|
|
379 |
//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
|
|
|
380 |
$redirecturl = $orderCreationResponse['response']['redirectUrl'];
|
|
|
381 |
if (strpos($redirecturl,'pay-success') === false) {
|
| 22465 |
amit.gupta |
382 |
setcookie('txn_comp', 'no', -1, '/');
|
| 18619 |
amit.gupta |
383 |
} else {
|
|
|
384 |
$order_det = array();
|
|
|
385 |
$this->loadModel('Order');
|
|
|
386 |
$order_det['user_id'] = $this->Auth->User('id');
|
|
|
387 |
$order_det['store_id'] = 4;
|
| 20274 |
amit.gupta |
388 |
$order_det['order_url'] = $this->mobileapihost.$redirecturl;
|
| 18619 |
amit.gupta |
389 |
$this->log(print_r($order_det,1),'ordersdet');
|
|
|
390 |
$this->Order->create();
|
| 22465 |
amit.gupta |
391 |
|
| 18619 |
amit.gupta |
392 |
if ($this->Order->save($order_det)) {
|
|
|
393 |
$id = $this->Order->getLastInsertID();
|
|
|
394 |
$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
|
|
|
395 |
$apihost = Configure::read('pythonapihost');
|
|
|
396 |
$url = $apihost."storeorder";
|
| 22465 |
amit.gupta |
397 |
|
| 18619 |
amit.gupta |
398 |
$this->log(print_r($url,1),'ordersdet');
|
| 22465 |
amit.gupta |
399 |
|
| 18619 |
amit.gupta |
400 |
$this->log(print_r($order,1),'ordersdet');
|
|
|
401 |
$response = array();
|
| 22465 |
amit.gupta |
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']);
|
| 18619 |
amit.gupta |
403 |
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 |
$jsonVar = json_encode($params);
|
|
|
406 |
$response = $this->make_request($url,$jsonVar);
|
|
|
407 |
}else{
|
|
|
408 |
$result = array('success'=>false,'message'=>'Empty order array');
|
|
|
409 |
$response = $result;
|
|
|
410 |
}
|
|
|
411 |
$this->log(print_r('response',1),'ordersdet');
|
|
|
412 |
$this->log(print_r($response,1),'ordersdet');
|
|
|
413 |
if(!empty($response) && $response['result']) {
|
|
|
414 |
if($response['htmlRequired'] == 1) {
|
|
|
415 |
$this->loadModel('Rawhtml');
|
|
|
416 |
$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
|
|
|
417 |
$this->Rawhtml->create();
|
|
|
418 |
$this->Rawhtml->save($data);
|
|
|
419 |
$this->log(print_r('insideif',1),'ordersdet');
|
|
|
420 |
$result = $response;
|
|
|
421 |
$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
|
|
|
422 |
}
|
|
|
423 |
else {
|
|
|
424 |
$result =array('success'=>true,'message'=> $response['result']);
|
|
|
425 |
$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
|
|
|
426 |
$this->log(print_r('insideelse',1),'ordersdet');
|
|
|
427 |
}
|
|
|
428 |
$this->log(print_r($sql,1),'ordersdet');
|
|
|
429 |
$this->Order->query($sql);
|
| 22465 |
amit.gupta |
430 |
|
|
|
431 |
}
|
| 18613 |
naman |
432 |
}
|
|
|
433 |
}
|
| 18619 |
amit.gupta |
434 |
$this->layout = 'innerpages';
|
| 22707 |
amit.gupta |
435 |
//$redirecturl = str_replace("pay-success","pay-success1", $redirecturl);
|
| 22465 |
amit.gupta |
436 |
$next = $redirecturl;
|
| 22707 |
amit.gupta |
437 |
$redirectUrl = $this->getAutoLoginUrl($userId,$next);
|
| 18619 |
amit.gupta |
438 |
$this->log($redirectUrl,'headers');
|
|
|
439 |
$this->set(compact('redirectUrl','next'));
|
|
|
440 |
}else{
|
|
|
441 |
$dataGiven = json_decode($this->request->data['cart_details']);
|
| 20863 |
amit.gupta |
442 |
if($walletUsed==$this->Session->read('totalPayable')){
|
| 20885 |
amit.gupta |
443 |
$url = Configure::read('saholicapihost').'order?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid.'&walletUsed='.$walletUsed.'&payment_option=7890';
|
| 22465 |
amit.gupta |
444 |
if($pincode!='0'){
|
| 18633 |
manish.sha |
445 |
$url = $url.'&pinCode='.$pincode;
|
|
|
446 |
}
|
|
|
447 |
$orderCreationResponse = $this->post_cartinfo_request($url, null);
|
|
|
448 |
//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
|
|
|
449 |
$redirecturl = $orderCreationResponse['response']['redirectUrl'];
|
|
|
450 |
if (strpos($redirecturl,'pay-success') === false) {
|
| 22465 |
amit.gupta |
451 |
setcookie('txn_comp', 'no', -1, '/');
|
| 18633 |
manish.sha |
452 |
} else {
|
|
|
453 |
$order_det = array();
|
|
|
454 |
$this->loadModel('Order');
|
|
|
455 |
$order_det['user_id'] = $this->Auth->User('id');
|
|
|
456 |
$order_det['store_id'] = 4;
|
| 20274 |
amit.gupta |
457 |
$order_det['order_url'] = $this->mobileapihost.$redirecturl;
|
| 18633 |
manish.sha |
458 |
$this->log(print_r($order_det,1),'ordersdet');
|
|
|
459 |
$this->Order->create();
|
| 22465 |
amit.gupta |
460 |
|
| 18633 |
manish.sha |
461 |
if ($this->Order->save($order_det)) {
|
|
|
462 |
$id = $this->Order->getLastInsertID();
|
|
|
463 |
$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
|
|
|
464 |
$apihost = Configure::read('pythonapihost');
|
|
|
465 |
$url = $apihost."storeorder";
|
| 22465 |
amit.gupta |
466 |
|
| 18633 |
manish.sha |
467 |
$this->log(print_r($url,1),'ordersdet');
|
| 22465 |
amit.gupta |
468 |
|
| 18633 |
manish.sha |
469 |
$this->log(print_r($order,1),'ordersdet');
|
|
|
470 |
$response = array();
|
|
|
471 |
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 |
$jsonVar = json_encode($params);
|
|
|
474 |
$response = $this->make_request($url,$jsonVar);
|
|
|
475 |
}else{
|
|
|
476 |
$result = array('success'=>false,'message'=>'Empty order array');
|
|
|
477 |
$response = $result;
|
|
|
478 |
}
|
|
|
479 |
$this->log(print_r('response',1),'ordersdet');
|
|
|
480 |
$this->log(print_r($response,1),'ordersdet');
|
|
|
481 |
if(!empty($response) && $response['result']) {
|
|
|
482 |
if($response['htmlRequired'] == 1) {
|
|
|
483 |
$this->loadModel('Rawhtml');
|
|
|
484 |
$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
|
|
|
485 |
$this->Rawhtml->create();
|
|
|
486 |
$this->Rawhtml->save($data);
|
|
|
487 |
$this->log(print_r('insideif',1),'ordersdet');
|
|
|
488 |
$result = $response;
|
|
|
489 |
$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
|
|
|
490 |
}
|
|
|
491 |
else {
|
|
|
492 |
$result =array('success'=>true,'message'=> $response['result']);
|
|
|
493 |
$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
|
|
|
494 |
$this->log(print_r('insideelse',1),'ordersdet');
|
|
|
495 |
}
|
|
|
496 |
$this->Order->query($sql);
|
| 22465 |
amit.gupta |
497 |
|
|
|
498 |
}
|
| 18633 |
manish.sha |
499 |
}
|
|
|
500 |
}
|
|
|
501 |
$this->layout = 'innerpages';
|
| 22465 |
amit.gupta |
502 |
$next = $redirecturl;
|
| 22707 |
amit.gupta |
503 |
$redirectUrl = $this->getAutoLoginUrl($userId,$next);
|
| 18768 |
manish.sha |
504 |
$redirectToCart = true;
|
| 18633 |
manish.sha |
505 |
$this->log($redirectUrl,'headers');
|
| 18768 |
manish.sha |
506 |
$this->set(compact('redirectUrl','next','redirectToCart'));
|
| 18633 |
manish.sha |
507 |
}
|
| 17871 |
manish.sha |
508 |
}
|
| 18619 |
amit.gupta |
509 |
} else {
|
|
|
510 |
if($tokenValidated == 0){
|
|
|
511 |
$url = '/special/native/login';
|
|
|
512 |
}elseif($tokenValidated == -1){
|
|
|
513 |
$url = '/abouts/askforupdate';
|
|
|
514 |
}
|
|
|
515 |
$this->redirect($url);
|
| 17871 |
manish.sha |
516 |
}
|
| 22465 |
amit.gupta |
517 |
}
|
| 17793 |
naman |
518 |
}
|