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