Subversion Repositories SmartDukaan

Rev

Rev 11108 | Rev 12188 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
3
class Search extends MY_Controller {
4
 
5
public $layoutName ='';
6
	function __construct() {
7
 
8
		// Call the CI_controller constructor
9
		parent::__construct();
11108 lgm 10
		// $admin = $this->session->userdata('admin');
11
		// if(!isset($admin) || empty($admin)) {
12
		// 	redirect(base_url().'authorize');
13
		// }
10582 lgm 14
		$this->layout->setlayout('layout/layout_main');
15
		$this->load->model('search_model');
16
		$this->load->model('magento_model');
17
		$this->layoutName= $this->layout->getLayout();
18
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
19
 
20
 
21
 
22
	}
23
	public function index()
24
	{
25
 
26
		//standard array
27
		$data = array();
28
		//get cache 
29
		$configdata =array();
30
		$configdata = $this->config->item('searchlist');
31
		$cachemodule = array('header','footer');
32
		$configdata = getCache($configdata,$cachemodule);
12159 anikendra 33
		$authorized = $this->session->userdata('authorized');
34
		if($authorized['Id'] > 0){
35
			$_SERVER['QUERY_STRING'] .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
36
		}
37
		if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
38
			$_SERVER['QUERY_STRING'] .= '&privateDealUser=true';
39
		}
10582 lgm 40
		//end of get cache
41
		if(array_key_exists('fq', $_GET) || array_key_exists('sortedBy', $_GET) || array_key_exists('minPrice', $_GET)){
42
			$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$_SERVER['QUERY_STRING']);
43
		}else{
44
			$searchName = 'seacrh'.$this->input->get('q');
45
			$cache = getFileCache($searchName);
46
			if(isset($cache) && !empty($cache)){
47
				$data['response'] = $cache;
48
			}else{
49
				$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$_SERVER['QUERY_STRING']);
50
				setFileCache($data['response'], $searchName,300);
51
			}
52
		}
53
		//set cache to output or renew cache
54
		if(isset($cachemodule) and !empty($cachemodule))
55
		{
56
			foreach($cachemodule as $cm)
57
			{
58
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
59
				{
60
					$data['response'][$cm]=$configdata[$cm];
61
				}
62
			}
63
		}
64
		setCache($configdata['module'],$cachemodule,$data['response']);
65
		$this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
11013 lgm 66
		if(isset($data['response']['response']['search_list'][0]->result->title))
67
		$title = $data['response']['response']['search_list'][0]->result->title;
68
		if(isset($title) && !empty($title)){
69
			$data['title'] = $title;
70
		}
71
		if(isset($data['response']['response']['search_list'][0]->result->metaDescription))
72
		$metaDescription = $data['response']['response']['search_list'][0]->result->metaDescription;
73
		if(isset($metaDescription) && !empty($metaDescription)){
74
			$data['metaDescription'] = $metaDescription;
75
		}
76
		if(isset($data['response']['response']['search_list'][0]->result->metaKeywords))
77
		$metaKeywords = $data['response']['response']['search_list'][0]->result->metaKeywords;
78
		if(isset($metaKeywords) && !empty($metaKeywords)){
79
			$data['metaKeywords'] = $metaKeywords;
80
		}
10582 lgm 81
		$data['stylesheet'] = 'pd-list.css';
82
		//end of set cache
83
		$this->layout->view('search/search_view',$data);
84
 
85
	}
86
 
87
	public function getSearchList($page,$name,$sort=null,$filter=null,$price=null)
88
	{
89
         $url = $this->config->item('search_list');
90
	  	 $url = $url['url'];
91
         $url = $this->config->item('curl_base_url').$url;	
92
         $params['q'] = rawurldecode($name);
93
         $params['index'] = ($page-1)*10;
94
         $params['offset'] = 10;
95
         if(isset($sort) && $sort != 'null'){
96
         	$params['sortedBy'] = $sort;
97
         }
98
         if(isset($price) && $price != 'null'){
99
         	$price = explode('&', $price);
100
         	if(intval($price[0]) < intval($price[1])){
101
         		$params['minPrice'] = $price[0];
102
         		$params['maxPrice'] = $price[1];
103
         	}
104
         	else{
105
         		$params['minPrice'] = $price[1];
106
         		$params['maxPrice'] = $price[0];
107
         	}
108
         }
109
         if(isset($filter) && $filter != 'null'){
110
         	$url .= '?fq='.rawurldecode($filter);
111
         }		
112
         $this->mcurl->add_call('appendlist','get',$url,$params);
113
         $response = $this->mcurl->execute($url);
114
         $data['response'] = $response['appendlist']['response'];
115
		 $response = $this->magento_model->product_list($data);
116
		 $count = $response[0]->result->totalCount;
117
		 $productListResponse ='';
118
		 $TotalPage = ceil($count/10);
119
		 if($TotalPage < $page) {$product_list='';}
120
		 else{$product_list = $response;}
121
		 	if(isset($product_list) and !empty($product_list))
122
		{
123
			foreach($product_list[0]->result->results as $pl)
124
			{
10949 lgm 125
				if(isset($pl->image_url) and !empty($pl->image_url))
126
					{
10582 lgm 127
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
128
          				<div class="pd-image" style="background:url('.$pl->image_url.')no-repeat center center;background-size:contain;"></div>
129
          					<div class="pd-info">
130
            				<div class="pdt-name">'.$pl->title.'</div>
10949 lgm 131
           			 		<div class="pdt-price">';
132
           			 		if(isset($pl->price) || isset($pl->mrp)){
133
           			 			$productListResponse .='<span class="pr">Rs</span>';
134
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
135
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
136
           			 			}
137
           			 			if(isset($pl->price) && $pl->price != 0){
138
           			 				$productListResponse .='<span class="pr-original">'. $pl->price.'</span>';
139
           			 			}			
140
           			 		}
141
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
142
 
143
					}				
10582 lgm 144
 
145
			}
146
		}
147
		echo $productListResponse;
148
 
149
	}
150
	public function filter(){
151
		$configdata = $this->config->item('searchfilter');
152
		$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata);
153
		$this->layout->view('search/search_view',$data);
154
	}
155
 
156
 
157
 
158
}
159
 
160
/* End of file welcome.php */
161
/* Location: ./application/controllers/welcome.php */