| Line 112... |
Line 112... |
| 112 |
$userId = $this->request->query('user_id');
|
112 |
$userId = $this->request->query('user_id');
|
| 113 |
if(isset($userId) && !empty($userId)) {
|
113 |
if(isset($userId) && !empty($userId)) {
|
| 114 |
$this->loadModel('User');
|
114 |
$this->loadModel('User');
|
| 115 |
$dbuser = $this->User->findById($userId);
|
115 |
$dbuser = $this->User->findById($userId);
|
| 116 |
$this->Auth->login($dbuser['User']);
|
116 |
$this->Auth->login($dbuser['User']);
|
| 117 |
}
|
117 |
}
|
| 118 |
$likedDeals = $disLikedDeals = array();
|
- |
|
| 119 |
// if (!$this->Category->exists($id)) {
|
- |
|
| 120 |
// throw new NotFoundException(__('Invalid category'));
|
- |
|
| 121 |
// }
|
- |
|
| 122 |
$page = $this->request->query('page');
|
118 |
$page = $this->request->query('page');
|
| 123 |
if(!isset($page)){
|
119 |
if(!isset($page)){
|
| 124 |
$page = 1;
|
120 |
$page = 1;
|
| 125 |
}
|
121 |
}
|
| - |
|
122 |
|
| 126 |
$sort = $this->request->query('sort');
|
123 |
$sort = $this->request->query('sort');
|
| 127 |
$direction = $this->request->query('direction');
|
124 |
$direction = $this->request->query('direction');
|
| 128 |
// $filter = $this->request->query('filter');
|
125 |
// $filter = $this->request->query('filter');
|
| 129 |
// $brands = $this->request->query('brands');
|
126 |
// $brands = $this->request->query('brands');
|
| - |
|
127 |
if($id != 2) {
|
| - |
|
128 |
//Fetch deals
|
| - |
|
129 |
$likedDeals = $disLikedDeals = array();
|
| 130 |
$brandschosen = $_COOKIE['brandschosen'];
|
130 |
$brandschosen = $_COOKIE['brandschosen'];
|
| 131 |
if(!empty($brandschosen)){
|
131 |
if(!empty($brandschosen)){
|
| 132 |
$filter = 'brand';
|
132 |
$filter = 'brand';
|
| 133 |
}
|
133 |
}
|
| 134 |
$brands = str_replace(',', '^', $brandschosen);
|
134 |
$brands = str_replace(',', '^', $brandschosen);
|
| 135 |
$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands);
|
135 |
$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands);
|
| 136 |
// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
|
136 |
// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
|
| 137 |
$response = $this->make_request($url,null);
|
137 |
$response = $this->make_request($url,null);
|
| 138 |
$deals = array();
|
138 |
$deals = array();
|
| 139 |
if(!empty($response)){
|
139 |
if(!empty($response)){
|
| 140 |
foreach ($response as $key => $value) {
|
140 |
foreach ($response as $key => $value) {
|
| 141 |
if(!empty($value)){
|
141 |
if(!empty($value)){
|
| 142 |
$deals[] = $value;
|
142 |
$deals[] = $value;
|
| - |
|
143 |
}
|
| 143 |
}
|
144 |
}
|
| 144 |
}
|
145 |
}
|
| 145 |
}
|
- |
|
| 146 |
$this->loadModel('Api');
|
146 |
$this->loadModel('Api');
|
| 147 |
// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
|
147 |
// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
|
| 148 |
// $deals = $apideals['products'];
|
148 |
// $deals = $apideals['products'];
|
| 149 |
$myactions = $this->Api->getMyActions($this->Auth->User('id'));
|
149 |
$myactions = $this->Api->getMyActions($this->Auth->User('id'));
|
| 150 |
if(!empty($myactions)) {
|
150 |
if(!empty($myactions)) {
|
| 151 |
foreach ($myactions['actions'] as $key => $value) {
|
151 |
foreach ($myactions['actions'] as $key => $value) {
|
| 152 |
if($value['UserAction']['action'] == 'like'){
|
152 |
if($value['UserAction']['action'] == 'like'){
|
| 153 |
$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
153 |
$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
| 154 |
}else{
|
154 |
}else{
|
| 155 |
$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
155 |
$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
| - |
|
156 |
}
|
| 156 |
}
|
157 |
}
|
| 157 |
}
|
158 |
}
|
| - |
|
159 |
$this->loadModel('NotificationRule');
|
| - |
|
160 |
$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));
|
| - |
|
161 |
$filterstr = '';
|
| - |
|
162 |
if(isset($filter) && !empty($filter)){
|
| - |
|
163 |
$filterstr = '&filter='.$filter.'&brands='.$brands;
|
| - |
|
164 |
}
|
| - |
|
165 |
$this->set(compact('deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen'));
|
| - |
|
166 |
}else{
|
| - |
|
167 |
//Fetch app offers
|
| - |
|
168 |
$this->loadModel('AppOffer');
|
| - |
|
169 |
$this->AppOffer->recursive = -1;
|
| - |
|
170 |
$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
|
| - |
|
171 |
$this->Paginator->settings = $options;
|
| - |
|
172 |
$this->set('appOffers', $this->Paginator->paginate('AppOffer'));
|
| - |
|
173 |
$this->set(compact('page','id'));
|
| - |
|
174 |
$this->render('viewapps');
|
| - |
|
175 |
}
|
| - |
|
176 |
}
|
| - |
|
177 |
|
| - |
|
178 |
public function getapps($id=null){
|
| - |
|
179 |
$this->layout = 'ajax';
|
| - |
|
180 |
$page = $this->request->query('page');
|
| - |
|
181 |
if(!isset($page)){
|
| - |
|
182 |
$page = 1;
|
| - |
|
183 |
}
|
| - |
|
184 |
$this->loadModel('AppOffer');
|
| - |
|
185 |
$this->AppOffer->recursive = -1;
|
| - |
|
186 |
$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
|
| - |
|
187 |
$this->Paginator->settings = $options;
|
| - |
|
188 |
try{
|
| - |
|
189 |
$appOffers = $this->Paginator->paginate('AppOffer');
|
| - |
|
190 |
} catch (NotFoundException $e) {
|
| - |
|
191 |
//get current page
|
| - |
|
192 |
$page = $this->request->params['named']['page'];
|
| - |
|
193 |
$appOffers = array();
|
| 158 |
}
|
194 |
}
|
| 159 |
$this->loadModel('NotificationRule');
|
195 |
debug($appOffers);
|
| 160 |
$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));
|
- |
|
| 161 |
$filterstr = '';
|
196 |
if(!empty($appOffers)){
|
| 162 |
if(isset($filter) && !empty($filter)){
|
197 |
$this->set(compact('page','id','appOffers'));
|
| 163 |
$filterstr = '&filter='.$filter.'&brands='.$brands;
|
198 |
$this->render('/Elements/appoffers');
|
| 164 |
}
|
199 |
}else{
|
| 165 |
$this->set(compact('deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen'));
|
200 |
$this->render('/Elements/nooffers');
|
| - |
|
201 |
}
|
| 166 |
}
|
202 |
}
|
| 167 |
|
203 |
|
| 168 |
public function getdeals($id = null) {
|
204 |
public function getdeals($id = null) {
|
| 169 |
$this->log('getdeal id '.$id,'api');
|
205 |
$this->log('getdeal id '.$id,'api');
|
| 170 |
$likedDeals = $disLikedDeals = array();
|
206 |
$likedDeals = $disLikedDeals = array();
|