Subversion Repositories SmartDukaan

Rev

Rev 18288 | Rev 18393 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18288 Rev 18390
Line 118... Line 118...
118
 * @throws NotFoundException
118
 * @throws NotFoundException
119
 * @param string $id
119
 * @param string $id
120
 * @return void
120
 * @return void
121
 */
121
 */
122
	public function view($id = null) {
122
	public function view($id = null) {
123
		$searchableSubCategories = array('20'=>'Tempered Glasses', '19^27'=>'Mobile Covers');
-
 
124
		$userId = $this->request->query('user_id');
-
 
125
		
-
 
126
		if(isset($userId) && !empty($userId)) {
123
		if(isset($userId) && !empty($userId)) {
127
			$this->loadModel('User');
124
			$this->loadModel('User');
128
			$dbuser = $this->User->findById($userId);
125
			$dbuser = $this->User->findById($userId);
129
			$this->Auth->login($dbuser['User']);
126
			$this->Auth->login($dbuser['User']);
130
		}				
127
		}				
-
 
128
		//Sort - type, ordering
-
 
129
		$sort = $this->request->query('sort');
-
 
130
		$direction = $this->request->query('direction');
-
 
131
		
-
 
132
		//Filter - brand/subcategory		
-
 
133
		$brands = $this->request->query('brands');
-
 
134
		$subcategories = $this->request->query('subcategories');
-
 
135
		
-
 
136
		$searchableSubCategories = array('20'=>'Tempered Glasses', '19^27'=>'Mobile Covers');
-
 
137
		$userId = $this->request->query('user_id');
-
 
138
		
131
		$page = $this->request->query('page');
139
		$page = $this->request->query('page');
132
		$searchfor = $this->request->query('searchFor');
140
		$searchfor = $this->request->query('searchFor');
133
		// echo "page=>",$page;
141
		// echo "page=>",$page;
134
		$error = $this->request->query('error');
142
		$error = $this->request->query('error');
135
		if(!isset($page)){
143
		if(!isset($page)){
136
			$page = 1;
144
			$page = 1;
137
		}
145
		}
138
 
146
 
139
		$sort = $this->request->query('sort');
-
 
140
		$direction = $this->request->query('direction');
-
 
141
		//$filter = $this->request->query('filter');
147
		//$filter = $this->request->query('filter');
142
		// $brands = $this->request->query('brands');
148
		// $brands = $this->request->query('brands');
143
		if($id != 2) {
149
		if($id != 2) {
144
			//Fetch deals
150
			//Fetch deals
145
			$likedDeals = $disLikedDeals = array();
151
			$likedDeals = $disLikedDeals = array();
146
			$brandschosen = $_COOKIE['brandschosen'];
-
 
147
			$subcategorieschosen = $_COOKIE['subcategorieschosen'];			
152
			if(!empty($brands) && !empty($subcategories)){
148
			
-
 
149
			// echo "Cookie val", $_COOKIE['old_id'];
-
 
150
			// echo "id val", $id;
153
				$filter = 'brand|subcategory';
151
 
-
 
152
			if(!empty($searchfor) || $searchfor != null)
-
 
153
			{
154
			}			
154
				unset($brandschosen);
155
			else if(!empty($brands)){
155
				setcookie('brandschosen', null, -1, '/');
-
 
156
				unset($subcategorieschosen);
156
				$filter = 'brand';
157
				setcookie('subcategorieschosen', null, -1, '/');
-
 
158
			}
157
			}
159
 
-
 
160
			if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
-
 
161
 
-
 
162
				
-
 
163
				unset($brandschosen);
-
 
164
				// setcookie('brandschosen', 1, time()-1, '/');
-
 
165
				// unset($_COOKIE['brandschosen']);
-
 
166
    			setcookie('brandschosen', null, -1, '/');
-
 
167
				unset($subcategorieschosen);
158
			else if(!empty($subcategories)){
168
				setcookie('subcategorieschosen', 1, time()-1, '/');
-
 
169
				
-
 
170
			}		
-
 
171
 
-
 
172
			if((isset($_COOKIE['brandschosen'])) && ($_COOKIE['old_cid'] != $id)) {
-
 
173
				
-
 
174
				unset($brandschosen);
-
 
175
				// setcookie('brandschosen', 1, time()-10, '/');
-
 
176
				// unset($_COOKIE['brandschosen']);
-
 
177
    			setcookie('brandschosen', null, -1, '/');
-
 
178
				unset($subcategorieschosen);
159
				$filter = 'subcategory';
179
				setcookie('subcategorieschosen', 1, time()-1, '/');
-
 
180
				
-
 
181
			}
160
			}
182
 
-
 
183
			setcookie('old_cid', $id, -1, '/');
-
 
184
			
-
 
185
			
161
			
-
 
162
			$sortlabel = 'recommended';
186
				if(!empty($brandschosen) && !empty($subcategorieschosen)){
163
			if	($sort=='bestSellerPoints'){
187
					$filter = 'brand|subcategory';
164
				$sortlabel  = 'bestseller';
188
				}			
165
			}
189
				else if(!empty($brandschosen) && empty($subcategorieschosen)){
166
			else if ($sort=='available_price' && $direction==-1){
190
					$filter = 'brand';
167
				$sortlabel  = 'pricehigh';
191
				}
168
			}
192
				if(!empty($subcategorieschosen) && empty($brandschosen)){
169
			else if ($sort=='available_price' && $direction==1){
193
					$filter = 'subcategory';
170
				$sortlabel  = 'pricelow';
194
				}
171
			}
195
			
172
			
196
			$brands = str_replace(',', '^', $brandschosen);
-
 
197
			$subcategories = str_replace(',', '^', $subcategorieschosen);
-
 
198
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
173
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
199
			// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
-
 
200
			$response = $this->make_request($url,null);
174
			$response = $this->make_request($url,null);
201
			$deals = array();
175
			$deals = array();
202
			
176
			
203
			$response_count =1;
177
			$response_count =1;
204
			if($response == '')
178
			if($response == '')
Line 234... Line 208...
234
		  	} 
208
		  	} 
235
		  	$get_url = "'".$_SERVER['REQUEST_URI']."'";
209
		  	$get_url = "'".$_SERVER['REQUEST_URI']."'";
236
		  	$urlArray = explode('=',$_SERVER['REQUEST_URI']);
210
		  	$urlArray = explode('=',$_SERVER['REQUEST_URI']);
237
		  	$last = $urlArray[sizeof($urlArray)-1];
211
		  	$last = $urlArray[sizeof($urlArray)-1];
238
		  	
212
		  	
239
		  	// <Code for url used after scrolling...>
-
 
240
		  	if(!isset($filter) && empty($filter)){
-
 
241
		  		if (strpos($get_url,'filter=brand&brands') !== false)
-
 
242
		  		{
-
 
243
		  			$filterstr= "&filter=brand&brands=".$last;
-
 
244
		  		}
-
 
245
		  		if (strpos($get_url,'filter=subcategory&subcategories') !== false)
-
 
246
		  		{
-
 
247
		  			$filterstr= "&filter=subcategory&subcategories=".$last;
-
 
248
		  		}
-
 
249
 
-
 
250
		  	}
-
 
251
 
-
 
252
		  
-
 
253
			if(!empty($subcategorieschosen) && isset($subcategorieschosen) && empty($brandschosen) && !isset($brandschosen)){	
-
 
254
					$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;				
-
 
255
			}
-
 
256
			
-
 
257
			$errorstr = '';
213
			$errorstr = '';
258
			
214
			
259
			if(isset($error)){
215
			if(isset($error)){
260
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
216
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
261
			}
217
			}
262
 
218
 
263
			
-
 
-
 
219
			$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;
264
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
220
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
-
 
221
			
265
			$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen','subcategories','subcategorieschosen','errorstr','nexturl','searchfor', 'searchableSubCategories'));
222
			$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','subcategories','errorstr','nexturl','searchfor', 'searchableSubCategories', 'sortlabel'));
266
		}else{
223
		}else{
267
			//Check for apk support of sharing
224
			//Check for apk support of sharing
268
			$sharable = 0;
225
			$sharable = 0;
269
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
226
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
270
				$sharable = 1;
227
				$sharable = 1;
Line 313... Line 270...
313
		}
270
		}
314
		$sort = $this->request->query('sort');
271
		$sort = $this->request->query('sort');
315
		$direction = $this->request->query('direction');
272
		$direction = $this->request->query('direction');
316
		// $filter = $this->request->query('filter');
273
		// $filter = $this->request->query('filter');
317
		// $brands = $this->request->query('brands');
274
		// $brands = $this->request->query('brands');
318
		$brandschosen = $_COOKIE['brandschosen'];	 
275
		$brands = $this->request->query('brands');
319
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 	
276
		$subcategories = $this->request->query('subcategories'); 	
320
		
-
 
321
		// Replace with the below content
-
 
322
		// if(!empty($brandschosen)){
-
 
323
		// 	$filter = 'brand';
-
 
324
		// }
-
 
325
 
277
 
326
		//I have replaced the above content
278
		$likedDeals = $disLikedDeals = array();
327
		if(!empty($brandschosen) && !empty($subcategorieschosen)){
279
		if(!empty($brands) && !empty($subcategories)){
328
			$filter = 'brand|subcategory';
280
			$filter = 'brand|subcategory';
329
		}			
281
		}
330
		else if(!empty($brandschosen) && empty($subcategorieschosen)){
282
		else if(!empty($brands)){
331
			$filter = 'brand';
283
			$filter = 'brand';
332
		}
284
		}
333
		if(!empty($subcategorieschosen) && empty($brandschosen)){
285
		else if(!empty($subcategories)){
334
			$filter = 'subcategory';
286
			$filter = 'subcategory';
335
		}
287
		}
336
		//Replaced end
-
 
337
 
288
		
338
		$brands = str_replace(',', '^', $brandschosen);
-
 
339
		$subcategories = str_replace(',', '^', $subcategorieschosen);
-
 
340
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
289
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
341
		$response = $this->make_request($url,null);
290
		$response = $this->make_request($url,null);
342
		$deals = array();
291
		$deals = array();
343
		if(!empty($response)){
292
		if(!empty($response)){
344
			foreach ($response as $key => $value) {
293
			foreach ($response as $key => $value) {
Line 361... Line 310...
361
				}else{
310
				}else{
362
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
311
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
363
				}
312
				}
364
			}
313
			}
365
		}
314
		}
366
		$filterstr = '';
-
 
367
 
-
 
368
		$get_url = "'".$_SERVER['REQUEST_URI']."'";
-
 
369
		$urlArray = explode('=',$_SERVER['REQUEST_URI']);
-
 
370
		$last = $urlArray[sizeof($urlArray)-1];
-
 
371
 
-
 
372
		if(!isset($filter) && empty($filter)){
-
 
373
			if (strpos($get_url,'filter=brand&brands') !== false)
-
 
374
			{
315
		
375
				$filterstr= "&filter=brand&brands=".$last;
-
 
376
			}
-
 
377
			if (strpos($get_url,'filter=subcategory&subcategories') !== false)
-
 
378
			{
-
 
379
				$filterstr= "&filter=subcategory&subcategories=".$last;
-
 
380
			}
-
 
381
 
-
 
382
		} 	  	
-
 
383
 
-
 
384
		if(isset($filter) && !empty($filter)){
-
 
385
		    // $filterstr = '&filter='.$filter.'&brands='.$brands;
-
 
386
		    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
316
		$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;
387
	  	} 
-
 
388
 
-
 
389
	  	if(!empty($subcategorieschosen) && isset($subcategorieschosen)&& empty($brandschosen) && !isset($brandschosen)){
-
 
390
 
-
 
391
	  			$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
-
 
392
	  	}
-
 
393
 
-
 
394
	  	$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
317
		$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
395
 
318
 
396
		$this->set(compact('nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
319
		$this->set(compact('nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
397
		if(!empty($deals) && !empty($deals[0])){
320
		if(!empty($deals) && !empty($deals[0])){
398
			$this->render('/Elements/deals');
321
			$this->render('/Elements/deals');
399
		}else{
322
		}else{
Line 452... Line 375...
452
	
375
	
453
	public function getdealsforsearchterm($searchterm,$page = null){
376
	public function getdealsforsearchterm($searchterm,$page = null){
454
		$likedDeals = $disLikedDeals = array();
377
		$likedDeals = $disLikedDeals = array();
455
		$this->layout = 'ajax';
378
		$this->layout = 'ajax';
456
		$page = $this->request->query('page');
379
		$page = $this->request->query('page');
457
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 
380
		$subcategories = $this->request->query('subcategories'); 
458
		if(!isset($page)){
381
		if(!isset($page)){
459
			$page = 1;
382
			$page = 1;
460
			$offset = 0;
383
			$offset = 0;
461
			$limit=10;
384
			$limit=10;
462
		}
385
		}
Line 465... Line 388...
465
			$limit = 20;
388
			$limit = 20;
466
		}
389
		}
467
		$sort = $this->request->query('sort');
390
		$sort = $this->request->query('sort');
468
		$direction = $this->request->query('direction');
391
		$direction = $this->request->query('direction');
469
 
392
 
470
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategorieschosen;
393
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategories;
471
		$response = $this->make_request($url,null);
394
		$response = $this->make_request($url,null);
472
		$deals = array();
395
		$deals = array();
473
		if(!empty($response)){
396
		if(!empty($response)){
474
			foreach ($response as $key => $value) {
397
			foreach ($response as $key => $value) {
475
				if(!empty($value)){
398
				if(!empty($value)){
Line 489... Line 412...
489
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
412
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
490
				}
413
				}
491
			}
414
			}
492
		}
415
		}
493
		
416
		
494
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1);
417
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1).'&subcategories='.$subcategories;
495
	
418
	
496
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
419
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
497
		if(!empty($deals) && !empty($deals[0])){
420
		if(!empty($deals) && !empty($deals[0])){
498
			$this->render('/Elements/deals');
421
			$this->render('/Elements/deals');
499
		}else{
422
		}else{