Subversion Repositories SmartDukaan

Rev

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

Rev 13815 Rev 13901
Line 16... Line 16...
16
	public $components = array('Paginator');
16
	public $components = array('Paginator');
17
	public $apihost;	
17
	public $apihost;	
18
 
18
 
19
	public function beforeFilter() {
19
	public function beforeFilter() {
20
		parent::beforeFilter();
20
		parent::beforeFilter();
21
		$this->Auth->allow('bycategory','category','mine','getdeals');
21
		$this->Auth->allow('bycategory','category','mine','getdeals','getliveprice','search');
22
		$callback = $this->request->query('callback');		
22
		$callback = $this->request->query('callback');		
23
	}
23
	}
24
 
24
 
25
	public function search() {
25
	public function search() {
26
		$this->layout = 'innerpages';
26
		$this->layout = 'innerpages';
27
		$q = $this->request->query('q');
27
		$q = $this->request->query('q');
-
 
28
		$page = $this->request->query('page');
-
 
29
		if(!isset($page)){
-
 
30
			$page = 1;
-
 
31
		}
-
 
32
		$dealsperpage = Configure::read('dealsperpage');
-
 
33
		$offset = ($page - 1)*$dealsperpage;
28
		if(isset($q) && !empty($q)){
34
		if(isset($q) && !empty($q)){
29
			if (Configure::read('log_solr_queries') === true) {
35
			if (Configure::read('log_solr_queries') === true) {
30
				$this->loadModel('SearchTerm');
36
				$this->loadModel('SearchTerm');
31
				$data = array('user_id' => $this->Auth->User('id'),'search_term' => $q);
37
				$data = array('user_id' => $this->Auth->User('id'),'search_term' => $q);
32
				$this->SearchTerm->create();
38
				$this->SearchTerm->create();
33
				$this->SearchTerm->save($data);					
39
				$this->SearchTerm->save($data);					
34
			}
40
			}
35
			//Handle with solr
41
			$result = $this->get_solr_result($q,$page);
36
			$cond = "q=$q";
42
			$this->set(compact('result','q','page'));
37
		 	$sort = "store desc";
43
		}
-
 
44
	}
38
 
45
 
39
			$params = array(
46
	public function getsearchresults() {
40
				'conditions' =>array(
47
		$this->layout = 'ajax';
41
			 	'solr_query' => $cond
48
		$q = $this->request->query('q');
42
		 	),
-
 
43
			 	'order' => $sort,
49
		$page = $this->request->query('page');
44
			 	'offset' => 0,
50
		if(!isset($page)){
45
			 	'limit' => 20
51
			$page = 1;
46
		 	);
52
		}		
47
			$this->loadModel('Solr');
53
		if(isset($q) && !empty($q)){			
48
			$result = $this->Solr->find('all', $params);
54
			$result = $this->get_solr_result($q,$page);
49
			// debug($result);
55
			$this->set(compact('result','q','page'));
50
			$this->set(compact('result','q'));
56
			$this->render('/Elements/searchresult');
51
		}
57
		}
52
	}
58
	}
53
 
59
 
54
	public function mine() {		
60
	public function mine() {		
55
		$userId = $this->request->query('user_id');
61
		$userId = $this->request->query('user_id');
Line 206... Line 212...
206
 *
212
 *
207
 * @throws NotFoundException
213
 * @throws NotFoundException
208
 * @param string $id
214
 * @param string $id
209
 * @return void
215
 * @return void
210
 */
216
 */
211
	public function view($id = null) {
217
	public function view($id = null,$bundleId=null) {
-
 
218
		$this->layout = "innerpages";
212
		if (!$this->StoreProduct->exists($id)) {
219
		$cachekey = 'storeproduct-'.$id;
-
 
220
		$product = Cache::read($cachekey,'month');
-
 
221
		if(empty($product)) {
213
			throw new NotFoundException(__('Invalid store product'));
222
			$url = $this->apihost.'masterData/getSkuById/'.$id;
-
 
223
			$product = $this->make_request($url,null);
-
 
224
			Cache::write($cachekey,$product,'month');			
214
		}
225
		}
-
 
226
		$storeProduct = json_decode($product[0],1);
215
		$options = array('conditions' => array('StoreProduct.' . $this->StoreProduct->primaryKey => $id));
227
		$activestores = Configure::read('activestores');
216
		$this->set('storeProduct', $this->StoreProduct->find('first', $options));
228
		$this->set(compact('storeProduct','activestores'));
-
 
229
	}
-
 
230
 
-
 
231
	public function getliveprice($bundleId=null,$storeId=null) {
-
 
232
		$cachekey = 'liveprice-'.$bundleId.'-'.$storeId;
-
 
233
		$products = Cache::read($cachekey,'fivemin');
-
 
234
		if(empty($products)) {
-
 
235
			$result = array();
-
 
236
			$this->response->type('json');
-
 
237
			$this->layout = 'ajax';
-
 
238
			$url = $this->apihost."Catalog/fetchLivePrices/?skuBundleId=$bundleId&source_id=$storeId";
-
 
239
			$products = $this->make_request($url,null);
-
 
240
			Cache::write($cachekey,$products,'fivemin');			
-
 
241
		}
-
 
242
		if(!empty($products)){
-
 
243
			$result['products'] = array();
-
 
244
			foreach($products AS $product) {
-
 
245
				array_push($result['products'],(json_decode($product)));
-
 
246
			}
-
 
247
			$products = json_decode(stripslashes(json_encode($products)));
-
 
248
			$result['success'] = true;
-
 
249
			// $result['products'] = $products;
-
 
250
		}else{
-
 
251
			$result['success'] = false;
-
 
252
		}
-
 
253
		$this->response->type('json');
-
 
254
		$this->layout = 'ajax';
-
 
255
		$this->set(array(
-
 
256
		    'result' => $result,
-
 
257
		    '_serialize' => array('result')
-
 
258
		));
-
 
259
		$this->render('/Elements/json');
217
	}
260
	}
218
 
261
 
219
/**
262
/**
220
 * add method
263
 * add method
221
 *
264
 *