Rev 22466 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Exceptionalnlcs Controller** @property Exceptionalnlc $Exceptionalnlc* @property PaginatorComponent $Paginator*/class ShippingsController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function beforeFilter() {parent::beforeFilter();$this->apihost = Configure::read('pythonapihost');$this->mobileapihost = Configure::read('saholicapihost');$this->Auth->allow('isServicable');}public function index(){$userId = $this->Auth->User('id');$dataGiven = json_decode($this->request->data['cart_details']);if ($this->request->is('post')) {$data = $this->request->data;}$suserId = base64_decode($_COOKIE['s_id']);$scartId = base64_decode($_COOKIE['s_cart']);$semailId = base64_decode($_COOKIE['s_email']);$pincode = 0;if($pincode==0 && isset($_COOKIE['s_pincode'])){$pincode = base64_decode($_COOKIE['s_pincode']);$url = $this->apihost . "pincodeValidation/" . $pincode;$getstate = $this->make_request ( $url, null );if ($getstate != "{}") {$stateres = ucwords ( strtolower ( $getstate ['state'] ) );}}$cartItems = array();foreach ($dataGiven->cartItems as $key=>$obj) {$itemobj = array('itemId' => $key, 'quantity' => $obj->quantity);array_push($cartItems, $itemobj);}$postData = array('cartItems' => $cartItems);$params = array('cartMap' => urlencode(json_encode($postData)));$this->layout = 'cartinnerpages';$url = Configure::read('saholicapihost').'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId;if($pincode!='0'){$url = $url.'&pinCode='.$pincode;}$cartskus = $this->post_cartinfo_request($url,$params);if(isset($cartskus['response']) && $cartskus['response']=='error'){$this->set(compact('cartskus'));$this->render('/Users/cartdetails');}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');$this->set(compact('cartskus'));$this->render('/Users/cartdetails');}else{$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);$this->Session->write('totalPayable', $totalPayable);$this->layout = 'innerpages';$url = Configure::read ( 'saholicapihost' ) . 'address?isLoggedIn=true&privateDealUser=true&userId=' . $suserId;$response = $this->make_request ( $url, null );$user_name = "";$user_contact = "";$codAvailable = $cartskus['cod'];//$codAvailable = false;$this->Session->write('cod', $codAvailable);$walletAmount = 0;if(array_key_exists('walletAmount',$response)){$walletAmount = $response ['walletAmount'];}//$creditorAssociated$this->Session->write('walletAmount', $walletAmount);$taxInvoiceEnabledUser = $response ['taxInvoiceEnabledUser'];$this->Session->write('taxInvoiceEnabledUser', $taxInvoiceEnabledUser);if(empty($response ['addresses'])){$this->redirect ( array ('action' => 'add'));}$firstshowaddress = array ();$findedaddress = array ();$moreshowaddress = array ();$current_address_id = - 1;$defaultpin = - 1;$defaultcookiepin = - 1;$defaultcheckedaddress = - 1;$defaultpinaddress = - 1;foreach ( $response ['addresses'] as $key => $value ) {if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {$defaultcookiepin = $key;$user_name = $value ['name'];$user_contact = $value ['phone'];if ($defaultcheckedaddress == - 1) {$defaultcheckedaddress = $value ['id'];}} else if (intval ( $value ['pin'] ) == $pincode) {$current_address_id = $key;array_push ( $findedaddress, $key );if ($defaultpinaddress == - 1) {$defaultpinaddress = $value ['id'];}} else if ($value ['id'] == intval ( $response ['defaultAddress'] )) {$defaultpin = $key;$user_name = $value ['name'];$user_contact = $value ['phone'];} else {array_push ( $moreshowaddress, $key );}}$defaultselectedaddress = - 1;if ($defaultpinaddress != - 1) {$defaultselectedaddress = $defaultpinaddress;}if ($defaultcheckedaddress != - 1) {$defaultselectedaddress = $defaultcheckedaddress;}if ($defaultcookiepin != - 1) {array_push ( $firstshowaddress, $defaultcookiepin );}for($i = 0; $i < count ( $findedaddress ); $i ++) {array_push ( $firstshowaddress, $findedaddress [$i] );}if ($defaultpin != - 1) {array_push ( $firstshowaddress, $defaultpin );}for($i = 0; $i < count ( $moreshowaddress ); $i ++) {array_push ( $firstshowaddress, $moreshowaddress [$i] );}$this->set ( 'address', $response );$this->set ( compact ( 'stateres','firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount') );}}public function add($user_name = null, $user_contact = null) {$this->layout = 'cartinnerpages';$totalPayable = $_SESSION ['totalPayable'];$codAvailable = $_SESSION ['cod'];$taxInvoiceEnabledUser = $_SESSION['taxInvoiceEnabledUser'];//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );$pinval='';$suserId = base64_decode ( $_COOKIE ['s_id'] );$scart = base64_decode ( $_COOKIE ['s_cart'] );if ($this->request->is ( 'post' )) {$data = $this->request->data;$senddata ['name'] = $data ['name'];$senddata ['line1'] = $data ['line1'];$senddata ['line2'] = "";$senddata ['city'] = $data ['city'];$senddata ['state'] = $data ['state'];$senddata ['pin'] = $data ['pin'];$senddata ['phone'] = $data ['phone'];$senddata ['country'] = 'India';$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";$response = $this->post_request ( $url, $senddata );$scartId = base64_decode ( $_COOKIE ['s_cart'] );$semailId = base64_decode ( $_COOKIE ['s_email'] );$blank = array ();$postData = array ('cartItems' => $blank);$params = array ('cartMap' => urlencode ( json_encode ( $postData ) ));$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;// if($pin!='0'){$url = $url . '&pinCode=' . $data ['pin'];// }$cartskus = $this->post_cartinfo_request ( $url, $params );$checkestimate = 'true';if ($cartskus ['maxEstimate'] == - 1) {$checkestimate = 'false';} else {for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){continue;}$estimate = $cartskus ['cartItems'] [$i] ['estimate'];if ($estimate==-1) {$checkestimate = 'false';break;}}}if ($checkestimate == 'false') {// debug("I am here");$this->Session->setFlash ( "Address is not serviceable", 'default', array ('class' => 'alert alert-danger custom_class') );// $this->Session->setFlash('Address is not serviceable');return $this->redirect ( array ('action' => 'index') );} else {$this->Session->setFlash ( "Address is serviceable" );}}$url = $this->apihost . "pincodeValidation/" . $pinval;$getstate = $this->make_request ( $url, null );// debug($getstate);$getstateval = "";if ($getstate != "{}") {$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );}$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable', 'taxInvoiceEnabledUser', 'walletAmount'));}public function submitcheck() {$this->autoRender = false;$this->request->onlyAllow ( 'ajax' );$suserId = base64_decode($_COOKIE['s_id']);$scartId = base64_decode($_COOKIE['s_cart']);$semailId = base64_decode($_COOKIE['s_email']);$data = $this->request->data;$senddata ['name'] = $data ['name'];$senddata ['line1'] = $data ['line1'];$senddata ['line2'] = "";$senddata ['city'] = $data ['city'];$senddata ['state'] = $data ['state'];$senddata ['pin'] = $data ['pin'];$senddata ['phone'] = $data ['phone'];$senddata ['country'] = 'India';setcookie('s_pincode', base64_encode($data['pin']), -1, '/');$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scartId . "&isPrivateDealUser=true";$response = $this->post_cartinfo_request($url,$senddata);$suserId = base64_decode ( $_COOKIE ['s_id'] );$scartId = base64_decode ( $_COOKIE ['s_cart'] );$semailId = base64_decode ( $_COOKIE ['s_email'] );$cartItems = array();foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {$itemobj = array('itemId' => $key, 'quantity' => $obj->quantity);array_push($cartItems, $itemobj);}$postData = array('cartItems' => $cartItems);$params = array('cartMap' => urlencode(json_encode($postData)));$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;$url = $url . '&pinCode=' . $data ['pin'];$cartskus = $this->post_cartinfo_request ( $url, $params );$checkestimate = $response ['defaultAddress'];if (count($cartskus['cartMessages'])>0) {$checkestimate = 'cart_redirect';}return $checkestimate;}public function isServicable($pin) {$this->autoRender = false;$this->request->onlyAllow ( 'ajax' );$data = $this->request->data;$scartId = base64_decode ( $_COOKIE ['s_cart'] );$suserId = base64_decode ( $_COOKIE ['s_id'] );$semailId = base64_decode ( $_COOKIE ['s_email'] );$cartItems = array();foreach (json_decode($data['cart_details'])->cartItems as $key=>$obj) {$itemobj = array('itemId' => $key, 'quantity' => $obj->quantity);array_push($cartItems, $itemobj);}$postData = array('cartItems' => $cartItems);$params = array('cartMap' => urlencode(json_encode($postData)));$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;$url = $url . '&pinCode=' . $pin;$cartskus = $this->post_cartinfo_request ( $url, $params );if($cartskus['maxEstimate']==-1){$checkestimate = 'non_service';}else if (count($cartskus['cartMessages'])>0) {$checkestimate = 'cart_redirect';setcookie('s_pincode', base64_encode($pin), -1, '/');} else if ($cartskus['maxEstimate']>=0) {setcookie('s_pincode', base64_encode($pin), -1, '/');$checkestimate = 'ok';}return $checkestimate;}public function getstate($pin_val) {$this->autoRender = false;$this->request->onlyAllow ( 'ajax' );$url = $this->apihost . "pincodeValidation/" . $pin_val;$getstate = $this->make_request ( $url, null );// $getstate['state'] = ucwords(strtolower($getstate['state']));$nothing = "nothing";if ($getstate != "{}") {$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );}return json_encode ( $getstate );}public function checkout(){$addressid = $this->request->data['addressid'];$pincode = 0;$cod = $this->request->query('cod');$userId = $this->request->query('user_id');$walletUsed = $this->request->data('walletUsed');//Added token validation to ensure only user$testCheck = Configure::read('requireusercheck');$tokenValidated = 0;if($testCheck){$tokenValidated = $this->checkToken($userId);}else{$tokenValidated = 1;}if(!empty($userId) && $tokenValidated==1){$url = $this->getAutoLoginUrl($userId,$url);if(isset($this->request->data->pincode)){$pincode = $this->request->data->pincode;}if($pincode==0 && isset($_COOKIE['s_pincode'])){$pincode = base64_decode($_COOKIE['s_pincode']);}$suserId = base64_decode($_COOKIE['s_id']);$scartId = base64_decode($_COOKIE['s_cart']);$semailId = base64_decode($_COOKIE['s_email']);if(isset($_COOKIE['txn_comp'])) {unset($_COOKIE['txn_comp']);}if($cod==1){$url = Configure::read('saholicapihost').'order?payment_option=COD~3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;if(isset($walletUsed)) {$url .= '&walletUsed='.$walletUsed;}if($pincode!='0'){$url = $url.'&pinCode='.$pincode;}$orderCreationResponse = $this->post_cartinfo_request($url, null);//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}$redirecturl = $orderCreationResponse['response']['redirectUrl'];if (strpos($redirecturl,'pay-success') === false) {setcookie('txn_comp', 'no', -1, '/');} else {$order_det = array();$this->loadModel('Order');$order_det['user_id'] = $this->Auth->User('id');$order_det['store_id'] = 4;$order_det['order_url'] = $this->mobileapihost.$redirecturl;$this->log(print_r($order_det,1),'ordersdet');$this->Order->create();if ($this->Order->save($order_det)) {$id = $this->Order->getLastInsertID();$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));$apihost = Configure::read('pythonapihost');$url = $apihost."storeorder";$this->log(print_r($url,1),'ordersdet');$this->log(print_r($order,1),'ordersdet');$response = array();// $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']);if(!empty($order)) {$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']);$jsonVar = json_encode($params);$response = $this->make_request($url,$jsonVar);}else{$result = array('success'=>false,'message'=>'Empty order array');$response = $result;}$this->log(print_r('response',1),'ordersdet');$this->log(print_r($response,1),'ordersdet');if(!empty($response) && $response['result']) {if($response['htmlRequired'] == 1) {$this->loadModel('Rawhtml');$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');$this->Rawhtml->create();$this->Rawhtml->save($data);$this->log(print_r('insideif',1),'ordersdet');$result = $response;$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];}else {$result =array('success'=>true,'message'=> $response['result']);$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];$this->log(print_r('insideelse',1),'ordersdet');}$this->log(print_r($sql,1),'ordersdet');$this->Order->query($sql);}}}$this->layout = 'innerpages';//$redirecturl = str_replace("pay-success","pay-success1", $redirecturl);$next = $redirecturl;$redirectUrl = $this->getAutoLoginUrl($userId,$next);$this->log($redirectUrl,'headers');$this->set(compact('redirectUrl','next'));}else{$dataGiven = json_decode($this->request->data['cart_details']);if($walletUsed==$this->Session->read('totalPayable')){$url = Configure::read('saholicapihost').'order?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid.'&walletUsed='.$walletUsed.'&payment_option=7890';if($pincode!='0'){$url = $url.'&pinCode='.$pincode;}$orderCreationResponse = $this->post_cartinfo_request($url, null);//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}$redirecturl = $orderCreationResponse['response']['redirectUrl'];if (strpos($redirecturl,'pay-success') === false) {setcookie('txn_comp', 'no', -1, '/');} else {$order_det = array();$this->loadModel('Order');$order_det['user_id'] = $this->Auth->User('id');$order_det['store_id'] = 4;$order_det['order_url'] = $this->mobileapihost.$redirecturl;$this->log(print_r($order_det,1),'ordersdet');$this->Order->create();if ($this->Order->save($order_det)) {$id = $this->Order->getLastInsertID();$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));$apihost = Configure::read('pythonapihost');$url = $apihost."storeorder";$this->log(print_r($url,1),'ordersdet');$this->log(print_r($order,1),'ordersdet');$response = array();if(!empty($order)) {$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']);$jsonVar = json_encode($params);$response = $this->make_request($url,$jsonVar);}else{$result = array('success'=>false,'message'=>'Empty order array');$response = $result;}$this->log(print_r('response',1),'ordersdet');$this->log(print_r($response,1),'ordersdet');if(!empty($response) && $response['result']) {if($response['htmlRequired'] == 1) {$this->loadModel('Rawhtml');$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');$this->Rawhtml->create();$this->Rawhtml->save($data);$this->log(print_r('insideif',1),'ordersdet');$result = $response;$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];}else {$result =array('success'=>true,'message'=> $response['result']);$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];$this->log(print_r('insideelse',1),'ordersdet');}$this->Order->query($sql);}}}$this->layout = 'innerpages';$next = $redirecturl;$redirectUrl = $this->getAutoLoginUrl($userId,$next);$redirectToCart = true;$this->log($redirectUrl,'headers');$this->set(compact('redirectUrl','next','redirectToCart'));}}} else {if($tokenValidated == 0){$url = '/special/native/login';}elseif($tokenValidated == -1){$url = '/abouts/askforupdate';}$this->redirect($url);}}}