Subversion Repositories SmartDukaan

Rev

Rev 17793 | Rev 17845 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::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;
                }
                $totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
                $this->layout = 'innerpages';
                $suserId = base64_decode($_COOKIE['s_id']);
                $url = Configure::read('saholicapihost').'address?isLoggedIn=true&privateDealUser=true&userId='.$suserId;
                $response = $this->make_request($url,null);
                //debug($response);
                if(empty($response['addresses'])){
                        $this->redirect(array('action' => 'add'));
                }

                $firstshowaddress = array();
                
                $pincode = base64_decode($_COOKIE['s_pincode']);
                $defaultaddressid = $response['defaultAddress'];
                if(!empty($defaultaddressid)){
                        $defaultaddressid = intval($defaultaddressid);
                }else{
                        $defaultaddressid = -1;
                }
                
                $defaultAddress = array();
                $similarAddress = array();
                $otherAddress = array();
                $defaultPinAddress = array();
                $defaultAddressFound = false;
                
                foreach ($response['addresses'] as $key => $value) {
                        if($defaultaddressid>-1 && $value['id']==$defaultaddressid && $value['pin']== $pincode){
                                array_push($defaultAddress, $value);
                                $defaultAddressFound = true;
                        }
                        else if($value['pin']== $pincode){
                                array_push($similarAddress, $value);
                        }
                        else if($value['id'] == $defaultaddressid)
                        {
                                array_push($defaultPinAddress, $value);
                        }       
                        else{
                                array_push($otherAddress, $value);
                        }
                }
                for($i= 0; $i<count($defaultAddress);$i++)
                {
                        array_push($firstshowaddress,$defaultAddress[$i]);
                }
                for($i= 0; $i<count($similarAddress);$i++)
                {
                        array_push($firstshowaddress,$similarAddress[$i]);
                }
                for($i= 0; $i<count($defaultPinAddress);$i++)
                {
                        array_push($firstshowaddress,$defaultPinAddress[$i]);
                }
                for($i= 0; $i<count($otherAddress);$i++)
                {
                        array_push($firstshowaddress,$otherAddress[$i]);
                }
                
                $this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
        }

        public function add() {
                $this->layout = 'innerpages';
                $pinval = 232104;
                setcookie('pin', $pinval, -1, '/');
                $nameval = "Supermans";
                setcookie('name', $nameval, -1, '/');

                if ($this->request->is('post')) {
                        $data = $this->request->data;
                        if($data['name'] == "")
                        {
                                $senddata['name'] = $_COOKIE['name'];   
                        }
                        else
                        {
                                $senddata['name'] = $data['name'];      
                        }
                        
                        $senddata['line1'] = $data['line1'];
                        $senddata['line2'] = "";
                        $senddata['city'] = $data['city'];
                        $senddata['state'] = $data['state'];
                        if($data['pin'] == "")
                        {
                                $senddata['pin'] = $_COOKIE['pin'];     
                        }
                        else
                        {
                                $senddata['pin'] = $data['pin'];        
                        }
                        $senddata['phone'] = $data['phone'];
                        $senddata['country'] = 'India';
                        // debug($senddata);
                        $url  = "http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true&cartId=41&isPrivateDealUser=true";
                        $response = $this->post_request($url,$senddata);
                        $this->redirect(array('action' => 'index'));
                        
                }
                
                // debug($_COOKIE['pin']);
                $url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
                $getstate =$this->make_request($url , null);
                $getstateval = "";
                if($getstate != "{}"){
                        $getstateval =ucwords(strtolower($getstate['state']));
                }
                $this->set(compact('getstateval'));
        }
         public function change(){
                $this->layout = 'innerpages';
                if($this->request->is('post'))
                {
                        echo "Hello";
                }
         }

         public function isServicable($pin){
                $this->autoRender = false;      
                $this->request->onlyAllow('ajax');
                // $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
                // $response = $this->make_request($url,null);
                if($pin == 110019)
                {$res = 'false';}
                else
                        {$res = 'true';}
                return $res;
         }

}