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