Subversion Repositories SmartDukaan

Rev

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

<?php
App::uses('AppController', 'Controller');
/**
 * Orders Controller
 *
 * @property Order $Order
 * @property PaginatorComponent $Paginator
 */
class OrderTrackersController extends AppController {

/**
 * Components
 *
 * @var array
 */
        public $components = array('Paginator');

        public function beforeFilter() {                
                parent::beforeFilter();
                $this->Auth->allow('get','post');
                $this->apihost = Configure::read('pythonapihost');
        }

/**
 * get method
 *
 * @throws NotFoundException
 * @return void
 */
        public function get() {
                $storeId = $this->request->query('store_id');
                $userId = $this->request->query('user_id');
                $url = $this->apihost.'track/user/'.$userId.'?storeId='.$storeId;
                $result = $this->make_request($url,null);
                $this->response->type('json');
                $this->layout = 'ajax';
                $this->set(array(
                    'result' => $result,
                    // 'callback' => $callback,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }

        public function post() {
                $storeId = $this->request->query('store_id');
                $userId = $this->request->query('user_id');
                $this->log('storeId '.print_r($storeId,1),'order_trackers');
                $this->log('userId '.print_r($userId,1),'order_trackers');
                if ($this->request->is('post')) {
                        if($this->request->data['zip']){
                                $this->request->data['html'] = gzuncompress(base64_decode($this->request->data['html'])); 
                        }
                        $this->log(print_r($this->request->data,1),'order_trackers');
                        $url = $this->apihost.'track/user/'.$userId.'?storeId='.$storeId;
                        $this->log($url,'order_trackers');
                        $params = array('url'=>urlencode($this->request->data['url']),'html'=>urlencode($this->request->data['html']));
                        //$jsonVar = json_encode($params,JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
                        //$this->log(print_r($jsonVar,1),'order_trackers');
                        $result =  $this->post_request($url,$params);
                        //$result = array('success'=>true,'message'=>'html stored');
                        $this->response->type('json');
                        $this->layout = 'ajax';
                        $this->set(array(
                            'result' => $result,
                            '_serialize' => array('result')
                        ));
                        $this->render('/Elements/json');                
                }                       
        }

}