Subversion Repositories SmartDukaan

Rev

Rev 13794 | Rev 13815 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13794 Rev 13808
Line 12... Line 12...
12
 * Components
12
 * Components
13
 *
13
 *
14
 * @var array
14
 * @var array
15
 */
15
 */
16
	public $components = array('Paginator');
16
	public $components = array('Paginator');
17
	public $apihost;
17
	public $apihost;	
18
	public $limit;
-
 
19
 
18
 
20
	public function beforeFilter() {
19
	public function beforeFilter() {
21
		parent::beforeFilter();
20
		parent::beforeFilter();
22
		$this->Auth->allow('bycategory','category','mine');
21
		$this->Auth->allow('bycategory','category','mine','getdeals');
23
		$callback = $this->request->query('callback');
22
		$callback = $this->request->query('callback');		
-
 
23
	}
-
 
24
 
-
 
25
	public function search() {
24
		$this->apihost = Configure::read('pythonapihost');
26
		$q = $this->request->query('q');
25
		$this->limit = Configure::read('dealsperpage');
27
		if(isset($q) && !empty($q)){
-
 
28
			//Handle with solr
-
 
29
		}
26
	}
30
	}
27
 
31
 
28
	public function mine() {		
32
	public function mine() {		
29
		$userId = $this->request->query('user_id');
33
		$userId = $this->request->query('user_id');
30
		if(isset($userId) && !empty($userId)){
34
		if(isset($userId) && !empty($userId)){
31
			$this->loadModel('User');
35
			$this->loadModel('User');
32
			$dbuser = $this->User->findById($userId);
36
			$dbuser = $this->User->findById($userId);
33
			$this->Auth->login($dbuser['User']);
37
			$this->Auth->login($dbuser['User']);
34
		}
38
		}
35
		$this->checkMobileNumber();
39
		// $this->checkMobileNumber();
36
		$likedDeals = $disLikedDeals = array();
40
		$likedDeals = $disLikedDeals = array();
37
		$this->loadModel('Api');
41
		$this->loadModel('Api');
38
		$page = $this->request->query('page');
42
		$page = $this->request->query('page');
39
		if(!isset($page)){
43
		if(!isset($page)){
40
			$page = 1;
44
			$page = 1;
41
		}		
45
		}				
42
		$offset = ($page - 1) * $this->limit;
46
		//Sort and Direction
43
		
-
 
44
		// $apideals = $this->Api->getDeals($this->Auth->User('id'));
47
		$sort = $this->request->query('sort');
45
		// $deals = $apideals['products'];
48
		$direction = $this->request->query('direction');
46
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
49
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),0,$sort,$direction);		
47
		$deals = $this->make_request($url,null);
50
		$deals = $this->make_request($url,null);
48
		// debug($deals);
51
		// debug($deals);
49
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
52
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
50
		if(!empty($myactions)) {
53
		if(!empty($myactions)) {
51
			foreach ($myactions['actions'] as $key => $value) {
54
			foreach ($myactions['actions'] as $key => $value) {
Line 56... Line 59...
56
				}
59
				}
57
			}
60
			}
58
		}
61
		}
59
		$title_for_layout = "Get Cashback on favourite";
62
		$title_for_layout = "Get Cashback on favourite";
60
		$description = "Get cashback on your favourite products. Mouth watering deals";
63
		$description = "Get cashback on your favourite products. Mouth watering deals";
61
		$this->set(compact('page', 'title_for_layout', 'description', 'deals', 'likedDeals','disLikedDeals'));
64
		$this->set(compact('page', 'title_for_layout', 'description', 'deals', 'likedDeals','disLikedDeals','sort','direction'));
62
		$this->render('/Pages/home');
65
		$this->render('/Pages/home');
63
	}
66
	}
64
 
67
 
65
	public function getdeals() {
68
	public function getdeals() {
66
		$likedDeals = $disLikedDeals = array();
69
		$likedDeals = $disLikedDeals = array();
Line 68... Line 71...
68
		$this->loadModel('Api');
71
		$this->loadModel('Api');
69
		$page = $this->request->query('page');
72
		$page = $this->request->query('page');
70
		if(!isset($page)){
73
		if(!isset($page)){
71
			$page = 1;
74
			$page = 1;
72
		}	
75
		}	
73
		$offset = ($page - 1) * $this->limit;			
-
 
74
		// $apideals = $this->Api->getDeals($this->Auth->User('id'),$page);
76
		// $apideals = $this->Api->getDeals($this->Auth->User('id'),$page);
75
		// $deals = $apideals['products'];
77
		// $deals = $apideals['products'];
76
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
78
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),0,$sort,$direction);
77
		$deals = $this->make_request($url,null);
79
		$deals = $this->make_request($url,null);
78
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
80
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
79
		if(!empty($myactions)) {
81
		if(!empty($myactions)) {
80
			foreach ($myactions['actions'] as $key => $value) {
82
			foreach ($myactions['actions'] as $key => $value) {
81
				if($value['UserAction']['action'] == 'like'){
83
				if($value['UserAction']['action'] == 'like'){
Line 85... Line 87...
85
				}
87
				}
86
			}
88
			}
87
		}
89
		}
88
		$title_for_layout = "Get Cashback on your favourite products";
90
		$title_for_layout = "Get Cashback on your favourite products";
89
		$description = "Get cashback on your favourite products. Mouth watering deals";
91
		$description = "Get cashback on your favourite products. Mouth watering deals";
90
		$this->set(compact('page', 'title_for_layout', 'description', 'deals', 'likedDeals','disLikedDeals'));
92
		$this->set(compact('page', 'title_for_layout', 'description', 'deals', 'likedDeals','disLikedDeals','sort','direction'));
91
		$this->render('/Elements/deals');
93
		$this->render('/Elements/deals');
92
	}	
94
	}	
93
/**
95
/**
94
 * index method
96
 * index method
95
 *
97
 *