| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Categories Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Category $Category
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class CategoriesController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
| 13794 |
anikendra |
17 |
public $apihost;
|
|
|
18 |
public $limit;
|
| 13532 |
anikendra |
19 |
|
| 13596 |
anikendra |
20 |
public function beforeFilter() {
|
|
|
21 |
parent::beforeFilter();
|
|
|
22 |
$this->Auth->allow('deals');
|
| 13794 |
anikendra |
23 |
$this->apihost = Configure::read('pythonapihost');
|
|
|
24 |
$this->limit = Configure::read('dealsperpage');
|
| 13596 |
anikendra |
25 |
}
|
|
|
26 |
|
| 13532 |
anikendra |
27 |
/**
|
|
|
28 |
* index method
|
|
|
29 |
*
|
|
|
30 |
* @return void
|
|
|
31 |
*/
|
|
|
32 |
public function index() {
|
|
|
33 |
// $this->Category->recursive = 0;
|
|
|
34 |
// $this->set('categories', $this->Paginator->paginate());
|
| 13541 |
anikendra |
35 |
$userId = $this->request->query('user_id');
|
|
|
36 |
$this->loadModel('UserCategory');
|
| 13689 |
anikendra |
37 |
$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);
|
| 13541 |
anikendra |
38 |
$userCategories = $this->UserCategory->find('all',$options);
|
| 13532 |
anikendra |
39 |
$this->response->type('json');
|
|
|
40 |
$this->layout = 'ajax';
|
| 13541 |
anikendra |
41 |
$conditions = array(array('Category.parent_id !='=>0));
|
|
|
42 |
if(!empty($userCategories)){
|
|
|
43 |
foreach ($userCategories as $key => $value) {
|
|
|
44 |
$categoryIds[] = $value['UserCategory']['category_id'];
|
|
|
45 |
}
|
|
|
46 |
array_push($conditions,array('Category.id'=>$categoryIds));
|
|
|
47 |
}
|
|
|
48 |
$this->Category->recursive = -1;
|
| 13532 |
anikendra |
49 |
$categories = $this->Paginator->paginate(null,$conditions);
|
|
|
50 |
$callback = $this->request->query('callback');
|
|
|
51 |
$result = array('categories' => $categories);
|
|
|
52 |
$this->set(array(
|
|
|
53 |
'result' => $result,
|
|
|
54 |
'callback' => $callback,
|
|
|
55 |
'_serialize' => array('result')
|
|
|
56 |
));
|
|
|
57 |
$this->render('/Elements/jsonp');
|
|
|
58 |
}
|
|
|
59 |
|
| 13567 |
anikendra |
60 |
public function deals(){
|
| 13591 |
anikendra |
61 |
$userId = $this->request->query('user_id');
|
| 17962 |
manish.sha |
62 |
$error = $this->request->query('error');
|
| 13591 |
anikendra |
63 |
if(isset($userId) && !empty($userId)){
|
| 13597 |
anikendra |
64 |
$this->loadModel('User');
|
|
|
65 |
$dbuser = $this->User->findById($userId);
|
|
|
66 |
$this->Auth->login($dbuser['User']);
|
| 13591 |
anikendra |
67 |
}
|
| 13583 |
anikendra |
68 |
$likedDeals = $disLikedDeals = array();
|
| 13794 |
anikendra |
69 |
// $this->loadModel('Api');
|
|
|
70 |
// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
|
|
|
71 |
// $categorydeals = $apideals['products'];
|
|
|
72 |
$page = $this->request->query('page');
|
|
|
73 |
if(!isset($page)){
|
|
|
74 |
$page = 1;
|
|
|
75 |
}
|
|
|
76 |
$offset = ($page - 1) * $this->limit;
|
|
|
77 |
$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
|
| 17683 |
naman |
78 |
//debug($url);
|
| 13794 |
anikendra |
79 |
$deals = $this->make_request($url,null);
|
| 13583 |
anikendra |
80 |
$myactions = $this->Api->getMyActions($this->Auth->User('id'));
|
|
|
81 |
if(!empty($myactions)) {
|
|
|
82 |
foreach ($myactions['actions'] as $key => $value) {
|
|
|
83 |
if($value['UserAction']['action'] == 'like'){
|
|
|
84 |
$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
85 |
}else{
|
|
|
86 |
$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
}
|
| 17962 |
manish.sha |
90 |
|
|
|
91 |
$errorstr = '';
|
|
|
92 |
|
|
|
93 |
if(isset($error)){
|
|
|
94 |
$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
|
|
|
95 |
}
|
| 13567 |
anikendra |
96 |
$rows = sizeof($categorydeals);
|
|
|
97 |
if($rows>=1){
|
|
|
98 |
$this->set('deals',$categorydeals);
|
| 13583 |
anikendra |
99 |
$this->set('likedDeals',$likedDeals);
|
|
|
100 |
$this->set('disLikedDeals',$disLikedDeals);
|
| 17962 |
manish.sha |
101 |
$this->set('errorstr',$errorstr);
|
| 13567 |
anikendra |
102 |
$this->render('categorydeals');
|
|
|
103 |
}else{
|
|
|
104 |
foreach ($categorydeals as $key => $dealarr) {
|
|
|
105 |
foreach ($dealarr as $key => $deal) {
|
|
|
106 |
$deals[] = $deal[0];
|
|
|
107 |
}
|
|
|
108 |
}
|
| 17962 |
manish.sha |
109 |
$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));
|
| 13567 |
anikendra |
110 |
}
|
|
|
111 |
}
|
|
|
112 |
/*
|
|
|
113 |
*
|
| 13532 |
anikendra |
114 |
* view method
|
|
|
115 |
*
|
|
|
116 |
* @throws NotFoundException
|
|
|
117 |
* @param string $id
|
|
|
118 |
* @return void
|
|
|
119 |
*/
|
|
|
120 |
public function view($id = null) {
|
| 14930 |
anikendra |
121 |
$userId = $this->request->query('user_id');
|
| 17683 |
naman |
122 |
|
| 15378 |
anikendra |
123 |
if(isset($userId) && !empty($userId)) {
|
| 14930 |
anikendra |
124 |
$this->loadModel('User');
|
|
|
125 |
$dbuser = $this->User->findById($userId);
|
|
|
126 |
$this->Auth->login($dbuser['User']);
|
| 16549 |
anikendra |
127 |
}
|
| 13583 |
anikendra |
128 |
$page = $this->request->query('page');
|
| 18063 |
naman |
129 |
$searchfor = $this->request->query('searchFor');
|
|
|
130 |
// echo "page=>",$page;
|
| 17810 |
manish.sha |
131 |
$error = $this->request->query('error');
|
| 13583 |
anikendra |
132 |
if(!isset($page)){
|
|
|
133 |
$page = 1;
|
| 16549 |
anikendra |
134 |
}
|
|
|
135 |
|
| 13808 |
anikendra |
136 |
$sort = $this->request->query('sort');
|
|
|
137 |
$direction = $this->request->query('direction');
|
| 15044 |
anikendra |
138 |
// $filter = $this->request->query('filter');
|
|
|
139 |
// $brands = $this->request->query('brands');
|
| 16549 |
anikendra |
140 |
if($id != 2) {
|
|
|
141 |
//Fetch deals
|
|
|
142 |
$likedDeals = $disLikedDeals = array();
|
| 17174 |
naman |
143 |
$brandschosen = $_COOKIE['brandschosen'];
|
| 17683 |
naman |
144 |
$subcategorieschosen = $_COOKIE['subcategorieschosen'];
|
| 17759 |
naman |
145 |
|
|
|
146 |
// echo "Cookie val", $_COOKIE['old_id'];
|
|
|
147 |
// echo "id val", $id;
|
| 17683 |
naman |
148 |
|
| 18063 |
naman |
149 |
if(!empty($searchfor) || $searchfor != null)
|
|
|
150 |
{
|
|
|
151 |
unset($brandschosen);
|
|
|
152 |
setcookie('brandschosen', null, -1, '/');
|
|
|
153 |
unset($subcategorieschosen);
|
|
|
154 |
setcookie('subcategorieschosen', null, -1, '/');
|
|
|
155 |
}
|
| 17759 |
naman |
156 |
|
| 18004 |
naman |
157 |
if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
|
| 17683 |
naman |
158 |
|
|
|
159 |
|
| 17174 |
naman |
160 |
unset($brandschosen);
|
| 17683 |
naman |
161 |
// setcookie('brandschosen', 1, time()-1, '/');
|
|
|
162 |
// unset($_COOKIE['brandschosen']);
|
|
|
163 |
setcookie('brandschosen', null, -1, '/');
|
|
|
164 |
unset($subcategorieschosen);
|
|
|
165 |
setcookie('subcategorieschosen', 1, time()-1, '/');
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
| 18004 |
naman |
169 |
if((isset($_COOKIE['brandschosen'])) && ($_COOKIE['old_cid'] != $id)) {
|
| 17683 |
naman |
170 |
|
|
|
171 |
unset($brandschosen);
|
|
|
172 |
// setcookie('brandschosen', 1, time()-10, '/');
|
|
|
173 |
// unset($_COOKIE['brandschosen']);
|
|
|
174 |
setcookie('brandschosen', null, -1, '/');
|
|
|
175 |
unset($subcategorieschosen);
|
|
|
176 |
setcookie('subcategorieschosen', 1, time()-1, '/');
|
|
|
177 |
|
| 16549 |
anikendra |
178 |
}
|
| 17683 |
naman |
179 |
|
| 18004 |
naman |
180 |
setcookie('old_cid', $id, -1, '/');
|
| 17683 |
naman |
181 |
|
|
|
182 |
|
|
|
183 |
if(!empty($brandschosen) && !empty($subcategorieschosen)){
|
|
|
184 |
$filter = 'brand|subcategory';
|
|
|
185 |
}
|
|
|
186 |
else if(!empty($brandschosen) && empty($subcategorieschosen)){
|
|
|
187 |
$filter = 'brand';
|
|
|
188 |
}
|
|
|
189 |
if(!empty($subcategorieschosen) && empty($brandschosen)){
|
|
|
190 |
$filter = 'subcategory';
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
/*if(!empty($brandschosen)){
|
|
|
194 |
$filter = 'brand';
|
|
|
195 |
}*/
|
|
|
196 |
|
| 16549 |
anikendra |
197 |
$brands = str_replace(',', '^', $brandschosen);
|
| 17683 |
naman |
198 |
$subcategories = str_replace(',', '^', $subcategorieschosen);
|
|
|
199 |
$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
|
| 16549 |
anikendra |
200 |
// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
|
|
|
201 |
$response = $this->make_request($url,null);
|
|
|
202 |
$deals = array();
|
| 17683 |
naman |
203 |
|
|
|
204 |
$response_count =1;
|
|
|
205 |
if($response == '')
|
|
|
206 |
{
|
|
|
207 |
$response_count = 0;
|
|
|
208 |
}
|
|
|
209 |
// debug($response_count);
|
| 16549 |
anikendra |
210 |
if(!empty($response)){
|
|
|
211 |
foreach ($response as $key => $value) {
|
|
|
212 |
if(!empty($value)){
|
|
|
213 |
$deals[] = $value;
|
|
|
214 |
}
|
| 16098 |
anikendra |
215 |
}
|
|
|
216 |
}
|
| 17683 |
naman |
217 |
#print_r($deals);
|
| 16549 |
anikendra |
218 |
$this->loadModel('Api');
|
|
|
219 |
$myactions = $this->Api->getMyActions($this->Auth->User('id'));
|
|
|
220 |
if(!empty($myactions)) {
|
|
|
221 |
foreach ($myactions['actions'] as $key => $value) {
|
|
|
222 |
if($value['UserAction']['action'] == 'like'){
|
|
|
223 |
$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
224 |
}else{
|
|
|
225 |
$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
226 |
}
|
| 13583 |
anikendra |
227 |
}
|
|
|
228 |
}
|
| 16549 |
anikendra |
229 |
$this->loadModel('NotificationRule');
|
|
|
230 |
$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));
|
|
|
231 |
$filterstr = '';
|
|
|
232 |
if(isset($filter) && !empty($filter)){
|
| 17759 |
naman |
233 |
|
| 17683 |
naman |
234 |
$filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
|
| 17695 |
naman |
235 |
}
|
|
|
236 |
|
| 17759 |
naman |
237 |
|
| 17695 |
naman |
238 |
$get_url = "'".$_SERVER['REQUEST_URI']."'";
|
|
|
239 |
$urlArray = explode('=',$_SERVER['REQUEST_URI']);
|
|
|
240 |
$last = $urlArray[sizeof($urlArray)-1];
|
|
|
241 |
|
| 17759 |
naman |
242 |
// <Code for url used after scrolling...>
|
| 17695 |
naman |
243 |
if(!isset($filter) && empty($filter)){
|
|
|
244 |
if (strpos($get_url,'filter=brand&brands') !== false)
|
|
|
245 |
{
|
|
|
246 |
$filterstr= "&filter=brand&brands=".$last;
|
|
|
247 |
}
|
|
|
248 |
if (strpos($get_url,'filter=subcategory&subcategories') !== false)
|
|
|
249 |
{
|
|
|
250 |
$filterstr= "&filter=subcategory&subcategories=".$last;
|
|
|
251 |
}
|
|
|
252 |
|
| 17759 |
naman |
253 |
}
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
if(!empty($subcategorieschosen) && isset($subcategorieschosen) && empty($brandschosen) && !isset($brandschosen)){
|
|
|
257 |
$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
|
|
|
258 |
}
|
| 17810 |
manish.sha |
259 |
|
|
|
260 |
$errorstr = '';
|
|
|
261 |
|
|
|
262 |
if(isset($error)){
|
|
|
263 |
$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
|
|
|
264 |
}
|
| 17759 |
naman |
265 |
|
| 18063 |
naman |
266 |
|
|
|
267 |
$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
|
|
|
268 |
$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen','subcategories','subcategorieschosen','errorstr','nexturl','searchfor'));
|
| 16549 |
anikendra |
269 |
}else{
|
| 16583 |
anikendra |
270 |
//Check for apk support of sharing
|
|
|
271 |
$sharable = 0;
|
|
|
272 |
if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
|
|
|
273 |
$sharable = 1;
|
| 17183 |
anikendra |
274 |
}
|
| 16704 |
anikendra |
275 |
$url = $this->apihost."appOffers/1";
|
|
|
276 |
$appOffers = $this->make_request($url,null);
|
|
|
277 |
$this->set(compact('page','id','sharable','appOffers'));
|
| 16549 |
anikendra |
278 |
$this->render('viewapps');
|
| 13583 |
anikendra |
279 |
}
|
| 13532 |
anikendra |
280 |
}
|
|
|
281 |
|
| 16549 |
anikendra |
282 |
public function getapps($id=null){
|
|
|
283 |
$this->layout = 'ajax';
|
|
|
284 |
$page = $this->request->query('page');
|
|
|
285 |
if(!isset($page)){
|
|
|
286 |
$page = 1;
|
|
|
287 |
}
|
|
|
288 |
$this->loadModel('AppOffer');
|
|
|
289 |
$this->AppOffer->recursive = -1;
|
|
|
290 |
$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
|
|
|
291 |
$this->Paginator->settings = $options;
|
|
|
292 |
try{
|
|
|
293 |
$appOffers = $this->Paginator->paginate('AppOffer');
|
|
|
294 |
} catch (NotFoundException $e) {
|
|
|
295 |
//get current page
|
|
|
296 |
$page = $this->request->params['named']['page'];
|
|
|
297 |
$appOffers = array();
|
|
|
298 |
}
|
|
|
299 |
debug($appOffers);
|
|
|
300 |
if(!empty($appOffers)){
|
|
|
301 |
$this->set(compact('page','id','appOffers'));
|
|
|
302 |
$this->render('/Elements/appoffers');
|
|
|
303 |
}else{
|
|
|
304 |
$this->render('/Elements/nooffers');
|
|
|
305 |
}
|
|
|
306 |
}
|
|
|
307 |
|
| 13579 |
anikendra |
308 |
public function getdeals($id = null) {
|
| 17695 |
naman |
309 |
|
| 13808 |
anikendra |
310 |
$this->log('getdeal id '.$id,'api');
|
| 13583 |
anikendra |
311 |
$likedDeals = $disLikedDeals = array();
|
| 13579 |
anikendra |
312 |
$this->layout = 'ajax';
|
|
|
313 |
$page = $this->request->query('page');
|
|
|
314 |
if(!isset($page)){
|
|
|
315 |
$page = 1;
|
|
|
316 |
}
|
| 13808 |
anikendra |
317 |
$sort = $this->request->query('sort');
|
|
|
318 |
$direction = $this->request->query('direction');
|
| 15044 |
anikendra |
319 |
// $filter = $this->request->query('filter');
|
|
|
320 |
// $brands = $this->request->query('brands');
|
| 17759 |
naman |
321 |
$brandschosen = $_COOKIE['brandschosen'];
|
|
|
322 |
$subcategorieschosen = $_COOKIE['subcategorieschosen'];
|
|
|
323 |
|
|
|
324 |
// Replace with the below content
|
|
|
325 |
// if(!empty($brandschosen)){
|
|
|
326 |
// $filter = 'brand';
|
|
|
327 |
// }
|
|
|
328 |
|
|
|
329 |
//I have replaced the above content
|
|
|
330 |
if(!empty($brandschosen) && !empty($subcategorieschosen)){
|
|
|
331 |
$filter = 'brand|subcategory';
|
|
|
332 |
}
|
|
|
333 |
else if(!empty($brandschosen) && empty($subcategorieschosen)){
|
| 15044 |
anikendra |
334 |
$filter = 'brand';
|
|
|
335 |
}
|
| 17759 |
naman |
336 |
if(!empty($subcategorieschosen) && empty($brandschosen)){
|
|
|
337 |
$filter = 'subcategory';
|
|
|
338 |
}
|
|
|
339 |
//Replaced end
|
|
|
340 |
|
| 15044 |
anikendra |
341 |
$brands = str_replace(',', '^', $brandschosen);
|
| 17759 |
naman |
342 |
$subcategories = str_replace(',', '^', $subcategorieschosen);
|
|
|
343 |
$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
|
| 16098 |
anikendra |
344 |
$response = $this->make_request($url,null);
|
|
|
345 |
$deals = array();
|
|
|
346 |
if(!empty($response)){
|
|
|
347 |
foreach ($response as $key => $value) {
|
|
|
348 |
if(!empty($value)){
|
|
|
349 |
$deals[] = $value;
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
}
|
| 13794 |
anikendra |
353 |
// if (!$this->Category->exists($id)) {
|
|
|
354 |
// throw new NotFoundException(__('Invalid category'));
|
|
|
355 |
// }
|
| 13579 |
anikendra |
356 |
$this->loadModel('Api');
|
| 13794 |
anikendra |
357 |
// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
|
|
|
358 |
// $deals = $apideals['products'];
|
| 13583 |
anikendra |
359 |
$myactions = $this->Api->getMyActions($this->Auth->User('id'));
|
|
|
360 |
if(!empty($myactions)) {
|
|
|
361 |
foreach ($myactions['actions'] as $key => $value) {
|
|
|
362 |
if($value['UserAction']['action'] == 'like'){
|
|
|
363 |
$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
364 |
}else{
|
|
|
365 |
$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
366 |
}
|
|
|
367 |
}
|
|
|
368 |
}
|
| 15026 |
anikendra |
369 |
$filterstr = '';
|
| 17695 |
naman |
370 |
|
|
|
371 |
$get_url = "'".$_SERVER['REQUEST_URI']."'";
|
|
|
372 |
$urlArray = explode('=',$_SERVER['REQUEST_URI']);
|
|
|
373 |
$last = $urlArray[sizeof($urlArray)-1];
|
|
|
374 |
|
|
|
375 |
if(!isset($filter) && empty($filter)){
|
|
|
376 |
if (strpos($get_url,'filter=brand&brands') !== false)
|
|
|
377 |
{
|
|
|
378 |
$filterstr= "&filter=brand&brands=".$last;
|
|
|
379 |
}
|
|
|
380 |
if (strpos($get_url,'filter=subcategory&subcategories') !== false)
|
|
|
381 |
{
|
|
|
382 |
$filterstr= "&filter=subcategory&subcategories=".$last;
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
}
|
|
|
386 |
|
| 15026 |
anikendra |
387 |
if(isset($filter) && !empty($filter)){
|
| 17759 |
naman |
388 |
// $filterstr = '&filter='.$filter.'&brands='.$brands;
|
|
|
389 |
$filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
|
| 15026 |
anikendra |
390 |
}
|
| 17759 |
naman |
391 |
|
|
|
392 |
if(!empty($subcategorieschosen) && isset($subcategorieschosen)&& empty($brandschosen) && !isset($brandschosen)){
|
|
|
393 |
|
|
|
394 |
$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
|
|
|
395 |
}
|
|
|
396 |
|
| 18063 |
naman |
397 |
$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
|
| 17759 |
naman |
398 |
|
| 18063 |
naman |
399 |
$this->set(compact('nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
|
| 16098 |
anikendra |
400 |
if(!empty($deals) && !empty($deals[0])){
|
| 15026 |
anikendra |
401 |
$this->render('/Elements/deals');
|
|
|
402 |
}else{
|
|
|
403 |
$this->render('/Elements/nodeals');
|
|
|
404 |
}
|
| 17695 |
naman |
405 |
|
|
|
406 |
|
|
|
407 |
|
| 13579 |
anikendra |
408 |
}
|
| 18063 |
naman |
409 |
|
|
|
410 |
|
|
|
411 |
public function getdealsforsearchterm($searchterm,$page = null){
|
|
|
412 |
$likedDeals = $disLikedDeals = array();
|
|
|
413 |
$this->layout = 'ajax';
|
|
|
414 |
$page = $this->request->query('page');
|
|
|
415 |
$brandschosen = $_COOKIE['brandschosen'];
|
|
|
416 |
$subcategorieschosen = $_COOKIE['subcategorieschosen'];
|
|
|
417 |
if(!isset($page)){
|
|
|
418 |
$page = 1;
|
|
|
419 |
$offset = 0;
|
|
|
420 |
$limit=10;
|
|
|
421 |
// $url= "http://45.79.106.95:8057/searchSubCategoryCount/?subCategoryId=".$subcategorieschosen."&searchTerm=".urlencode($searchterm);
|
|
|
422 |
// $count = $this->make_request($url,null);
|
|
|
423 |
// setcookie('countval', $count['count'], -1, '/');
|
|
|
424 |
}
|
|
|
425 |
else{
|
|
|
426 |
$offset = ($page*20) - 30;
|
|
|
427 |
$limit = 20;
|
|
|
428 |
}
|
|
|
429 |
$sort = $this->request->query('sort');
|
|
|
430 |
$direction = $this->request->query('direction');
|
|
|
431 |
if(!empty($brandschosen) && !empty($subcategorieschosen)){
|
|
|
432 |
$filter = 'brand|subcategory';
|
|
|
433 |
}
|
|
|
434 |
else if(!empty($brandschosen) && empty($subcategorieschosen)){
|
|
|
435 |
$filter = 'brand';
|
|
|
436 |
}
|
|
|
437 |
if(!empty($subcategorieschosen) && empty($brandschosen)){
|
|
|
438 |
$filter = 'subcategory';
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
$brands = str_replace(',', '^', $brandschosen);
|
|
|
442 |
$subcategories = str_replace(',', '^', $subcategorieschosen);
|
|
|
443 |
$url = "http://45.79.106.95:8057/searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategorieschosen;
|
|
|
444 |
$response = $this->make_request($url,null);
|
|
|
445 |
$deals = array();
|
|
|
446 |
if(!empty($response)){
|
|
|
447 |
foreach ($response as $key => $value) {
|
|
|
448 |
if(!empty($value)){
|
|
|
449 |
$deals[] = $value;
|
|
|
450 |
}
|
|
|
451 |
}
|
|
|
452 |
}
|
|
|
453 |
// if (!$this->Category->exists($id)) {
|
|
|
454 |
// throw new NotFoundException(__('Invalid category'));
|
|
|
455 |
// }
|
|
|
456 |
$this->loadModel('Api');
|
|
|
457 |
// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
|
|
|
458 |
// $deals = $apideals['products'];
|
|
|
459 |
$myactions = $this->Api->getMyActions($this->Auth->User('id'));
|
|
|
460 |
if(!empty($myactions)) {
|
|
|
461 |
foreach ($myactions['actions'] as $key => $value) {
|
|
|
462 |
if($value['UserAction']['action'] == 'like'){
|
|
|
463 |
$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
464 |
}else{
|
|
|
465 |
$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
|
|
|
466 |
}
|
|
|
467 |
}
|
|
|
468 |
}
|
|
|
469 |
|
|
|
470 |
$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1);
|
|
|
471 |
|
|
|
472 |
$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
|
|
|
473 |
if(!empty($deals) && !empty($deals[0])){
|
|
|
474 |
$this->render('/Elements/deals');
|
|
|
475 |
}else{
|
|
|
476 |
$this->render('/Elements/nodeals');
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
|
|
|
480 |
}
|
| 13532 |
anikendra |
481 |
/**
|
|
|
482 |
* add method
|
|
|
483 |
*
|
|
|
484 |
* @return void
|
|
|
485 |
*/
|
|
|
486 |
public function add() {
|
|
|
487 |
if ($this->request->is('post')) {
|
|
|
488 |
$this->Category->create();
|
|
|
489 |
if ($this->Category->save($this->request->data)) {
|
|
|
490 |
$this->Session->setFlash(__('The category has been saved.'));
|
|
|
491 |
return $this->redirect(array('action' => 'index'));
|
|
|
492 |
} else {
|
|
|
493 |
$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
|
|
|
494 |
}
|
|
|
495 |
}
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
/**
|
|
|
499 |
* edit method
|
|
|
500 |
*
|
|
|
501 |
* @throws NotFoundException
|
|
|
502 |
* @param string $id
|
|
|
503 |
* @return void
|
|
|
504 |
*/
|
|
|
505 |
public function edit($id = null) {
|
|
|
506 |
if (!$this->Category->exists($id)) {
|
|
|
507 |
throw new NotFoundException(__('Invalid category'));
|
|
|
508 |
}
|
|
|
509 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
510 |
if ($this->Category->save($this->request->data)) {
|
|
|
511 |
$this->Session->setFlash(__('The category has been saved.'));
|
|
|
512 |
return $this->redirect(array('action' => 'index'));
|
|
|
513 |
} else {
|
|
|
514 |
$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
|
|
|
515 |
}
|
|
|
516 |
} else {
|
|
|
517 |
$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
|
|
|
518 |
$this->request->data = $this->Category->find('first', $options);
|
|
|
519 |
}
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
/**
|
|
|
523 |
* delete method
|
|
|
524 |
*
|
|
|
525 |
* @throws NotFoundException
|
|
|
526 |
* @param string $id
|
|
|
527 |
* @return void
|
|
|
528 |
*/
|
|
|
529 |
public function delete($id = null) {
|
|
|
530 |
$this->Category->id = $id;
|
|
|
531 |
if (!$this->Category->exists()) {
|
|
|
532 |
throw new NotFoundException(__('Invalid category'));
|
|
|
533 |
}
|
|
|
534 |
$this->request->onlyAllow('post', 'delete');
|
|
|
535 |
if ($this->Category->delete()) {
|
|
|
536 |
$this->Session->setFlash(__('The category has been deleted.'));
|
|
|
537 |
} else {
|
|
|
538 |
$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
|
|
|
539 |
}
|
|
|
540 |
return $this->redirect(array('action' => 'index'));
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
/**
|
|
|
544 |
* admin_index method
|
|
|
545 |
*
|
|
|
546 |
* @return void
|
|
|
547 |
*/
|
|
|
548 |
public function admin_index() {
|
|
|
549 |
$this->Category->recursive = 0;
|
|
|
550 |
$this->set('categories', $this->Paginator->paginate());
|
|
|
551 |
}
|
|
|
552 |
|
|
|
553 |
/**
|
|
|
554 |
* admin_view method
|
|
|
555 |
*
|
|
|
556 |
* @throws NotFoundException
|
|
|
557 |
* @param string $id
|
|
|
558 |
* @return void
|
|
|
559 |
*/
|
|
|
560 |
public function admin_view($id = null) {
|
|
|
561 |
if (!$this->Category->exists($id)) {
|
|
|
562 |
throw new NotFoundException(__('Invalid category'));
|
|
|
563 |
}
|
|
|
564 |
$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
|
|
|
565 |
$this->set('category', $this->Category->find('first', $options));
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
/**
|
|
|
569 |
* admin_add method
|
|
|
570 |
*
|
|
|
571 |
* @return void
|
|
|
572 |
*/
|
|
|
573 |
public function admin_add() {
|
|
|
574 |
if ($this->request->is('post')) {
|
|
|
575 |
// print_r($this->request->data);die;
|
|
|
576 |
$this->Category->create();
|
|
|
577 |
if ($this->Category->save($this->request->data)) {
|
|
|
578 |
$this->Session->setFlash(__('The category has been saved.'));
|
|
|
579 |
return $this->redirect(array('action' => 'index'));
|
|
|
580 |
} else {
|
|
|
581 |
$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
|
|
|
582 |
}
|
|
|
583 |
}
|
|
|
584 |
$this->set('parent_id',$this->Category->find('list'));
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
/**
|
|
|
588 |
* admin_edit method
|
|
|
589 |
*
|
|
|
590 |
* @throws NotFoundException
|
|
|
591 |
* @param string $id
|
|
|
592 |
* @return void
|
|
|
593 |
*/
|
|
|
594 |
public function admin_edit($id = null) {
|
|
|
595 |
if (!$this->Category->exists($id)) {
|
|
|
596 |
throw new NotFoundException(__('Invalid category'));
|
|
|
597 |
}
|
|
|
598 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
599 |
if ($this->Category->save($this->request->data)) {
|
|
|
600 |
$this->Session->setFlash(__('The category has been saved.'));
|
|
|
601 |
return $this->redirect(array('action' => 'index'));
|
|
|
602 |
} else {
|
|
|
603 |
$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
|
|
|
604 |
}
|
|
|
605 |
} else {
|
|
|
606 |
$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
|
|
|
607 |
$this->request->data = $this->Category->find('first', $options);
|
|
|
608 |
}
|
|
|
609 |
}
|
|
|
610 |
|
|
|
611 |
/**
|
|
|
612 |
* admin_delete method
|
|
|
613 |
*
|
|
|
614 |
* @throws NotFoundException
|
|
|
615 |
* @param string $id
|
|
|
616 |
* @return void
|
|
|
617 |
*/
|
|
|
618 |
public function admin_delete($id = null) {
|
|
|
619 |
$this->Category->id = $id;
|
|
|
620 |
if (!$this->Category->exists()) {
|
|
|
621 |
throw new NotFoundException(__('Invalid category'));
|
|
|
622 |
}
|
|
|
623 |
$this->request->onlyAllow('post', 'delete');
|
|
|
624 |
if ($this->Category->delete()) {
|
|
|
625 |
$this->Session->setFlash(__('The category has been deleted.'));
|
|
|
626 |
} else {
|
|
|
627 |
$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
|
|
|
628 |
}
|
|
|
629 |
return $this->redirect(array('action' => 'index'));
|
|
|
630 |
}}
|