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