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