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