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