Subversion Repositories SmartDukaan

Rev

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

Rev 18017 Rev 18063
Line 124... Line 124...
124
			$this->loadModel('User');
124
			$this->loadModel('User');
125
			$dbuser = $this->User->findById($userId);
125
			$dbuser = $this->User->findById($userId);
126
			$this->Auth->login($dbuser['User']);
126
			$this->Auth->login($dbuser['User']);
127
		}				
127
		}				
128
		$page = $this->request->query('page');
128
		$page = $this->request->query('page');
-
 
129
		$searchfor = $this->request->query('searchFor');
-
 
130
		// echo "page=>",$page;
129
		$error = $this->request->query('error');
131
		$error = $this->request->query('error');
130
		if(!isset($page)){
132
		if(!isset($page)){
131
			$page = 1;
133
			$page = 1;
132
		}
134
		}
133
 
135
 
Line 142... Line 144...
142
			$subcategorieschosen = $_COOKIE['subcategorieschosen'];			
144
			$subcategorieschosen = $_COOKIE['subcategorieschosen'];			
143
			
145
			
144
			// echo "Cookie val", $_COOKIE['old_id'];
146
			// echo "Cookie val", $_COOKIE['old_id'];
145
			// echo "id val", $id;
147
			// echo "id val", $id;
146
 
148
 
-
 
149
			if(!empty($searchfor) || $searchfor != null)
-
 
150
			{
-
 
151
				unset($brandschosen);
-
 
152
				setcookie('brandschosen', null, -1, '/');
-
 
153
				unset($subcategorieschosen);
-
 
154
				setcookie('subcategorieschosen', null, -1, '/');
-
 
155
			}
147
 
156
 
148
			if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
157
			if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
149
 
158
 
150
				
159
				
151
				unset($brandschosen);
160
				unset($brandschosen);
Line 252... Line 261...
252
			
261
			
253
			if(isset($error)){
262
			if(isset($error)){
254
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
263
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
255
			}
264
			}
256
 
265
 
-
 
266
			
-
 
267
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
257
			$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen','subcategories','subcategorieschosen','errorstr'));
268
			$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen','subcategories','subcategorieschosen','errorstr','nexturl','searchfor'));
258
		}else{
269
		}else{
259
			//Check for apk support of sharing
270
			//Check for apk support of sharing
260
			$sharable = 0;
271
			$sharable = 0;
261
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
272
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
262
				$sharable = 1;
273
				$sharable = 1;
Line 381... Line 392...
381
	  	if(!empty($subcategorieschosen) && isset($subcategorieschosen)&& empty($brandschosen) && !isset($brandschosen)){
392
	  	if(!empty($subcategorieschosen) && isset($subcategorieschosen)&& empty($brandschosen) && !isset($brandschosen)){
382
 
393
 
383
	  			$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
394
	  			$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
384
	  	}
395
	  	}
385
 
396
 
-
 
397
	  	$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
386
 
398
 
387
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
399
		$this->set(compact('nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
388
		if(!empty($deals) && !empty($deals[0])){
400
		if(!empty($deals) && !empty($deals[0])){
389
			$this->render('/Elements/deals');
401
			$this->render('/Elements/deals');
390
		}else{
402
		}else{
391
			$this->render('/Elements/nodeals');
403
			$this->render('/Elements/nodeals');
392
		}
404
		}
393
 
405
 
394
 
406
 
395
 
407
 
396
	}
408
	}
-
 
409
 
-
 
410
 
-
 
411
	public function getdealsforsearchterm($searchterm,$page = null){
-
 
412
		$likedDeals = $disLikedDeals = array();
-
 
413
		$this->layout = 'ajax';
-
 
414
		$page = $this->request->query('page');
-
 
415
		$brandschosen = $_COOKIE['brandschosen'];	 
-
 
416
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 
-
 
417
		if(!isset($page)){
-
 
418
			$page = 1;
-
 
419
			$offset = 0;
-
 
420
			$limit=10;
-
 
421
			// $url= "http://45.79.106.95:8057/searchSubCategoryCount/?subCategoryId=".$subcategorieschosen."&searchTerm=".urlencode($searchterm);
-
 
422
			// $count = $this->make_request($url,null);
-
 
423
			// setcookie('countval', $count['count'], -1, '/');
-
 
424
		}
-
 
425
		else{
-
 
426
			$offset = ($page*20) - 30;
-
 
427
			$limit = 20;
-
 
428
		}
-
 
429
		$sort = $this->request->query('sort');
-
 
430
		$direction = $this->request->query('direction');
-
 
431
		if(!empty($brandschosen) && !empty($subcategorieschosen)){
-
 
432
			$filter = 'brand|subcategory';
-
 
433
		}			
-
 
434
		else if(!empty($brandschosen) && empty($subcategorieschosen)){
-
 
435
			$filter = 'brand';
-
 
436
		}
-
 
437
		if(!empty($subcategorieschosen) && empty($brandschosen)){
-
 
438
			$filter = 'subcategory';
-
 
439
		}
-
 
440
 
-
 
441
		$brands = str_replace(',', '^', $brandschosen);
-
 
442
		$subcategories = str_replace(',', '^', $subcategorieschosen);
-
 
443
		$url = "http://45.79.106.95:8057/searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategorieschosen;
-
 
444
		$response = $this->make_request($url,null);
-
 
445
		$deals = array();
-
 
446
		if(!empty($response)){
-
 
447
			foreach ($response as $key => $value) {
-
 
448
				if(!empty($value)){
-
 
449
					$deals[] = $value;
-
 
450
				}
-
 
451
			}
-
 
452
		}
-
 
453
		// if (!$this->Category->exists($id)) {
-
 
454
			// throw new NotFoundException(__('Invalid category'));
-
 
455
		// }
-
 
456
		$this->loadModel('Api');
-
 
457
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
-
 
458
		// $deals = $apideals['products'];
-
 
459
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
-
 
460
		if(!empty($myactions)) {
-
 
461
			foreach ($myactions['actions'] as $key => $value) {
-
 
462
				if($value['UserAction']['action'] == 'like'){
-
 
463
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
-
 
464
				}else{
-
 
465
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
-
 
466
				}
-
 
467
			}
-
 
468
		}
-
 
469
		
-
 
470
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1);
-
 
471
	
-
 
472
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
-
 
473
		if(!empty($deals) && !empty($deals[0])){
-
 
474
			$this->render('/Elements/deals');
-
 
475
		}else{
-
 
476
			$this->render('/Elements/nodeals');
-
 
477
		}
-
 
478
 
-
 
479
 
-
 
480
	}
397
/**
481
/**
398
 * add method
482
 * add method
399
 *
483
 *
400
 * @return void
484
 * @return void
401
 */
485
 */