Subversion Repositories SmartDukaan

Rev

Rev 12188 | Rev 12228 | 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
	{
12188 anikendra 89
		$authorized=$this->session->userdata('authorized');
10582 lgm 90
         $url = $this->config->item('search_list');
91
	  	 $url = $url['url'];
92
         $url = $this->config->item('curl_base_url').$url;	
93
         $params['q'] = rawurldecode($name);
94
         $params['index'] = ($page-1)*10;
95
         $params['offset'] = 10;
96
         if(isset($sort) && $sort != 'null'){
97
         	$params['sortedBy'] = $sort;
98
         }
99
         if(isset($price) && $price != 'null'){
100
         	$price = explode('&', $price);
101
         	if(intval($price[0]) < intval($price[1])){
102
         		$params['minPrice'] = $price[0];
103
         		$params['maxPrice'] = $price[1];
104
         	}
105
         	else{
106
         		$params['minPrice'] = $price[1];
107
         		$params['maxPrice'] = $price[0];
108
         	}
109
         }
110
         if(isset($filter) && $filter != 'null'){
111
         	$url .= '?fq='.rawurldecode($filter);
112
         }		
12188 anikendra 113
		if($authorized['Id'] > 0){
12223 anikendra 114
			if(strpos($url,'?')===false){
115
				$url .= '?userId='.$authorized['Id'].'&isLoggedIn=true';
116
			}else{
117
				$url .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
118
			}
12188 anikendra 119
		}
120
		if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
121
			$url .= '&privateDealUser=true';
122
		}
10582 lgm 123
         $this->mcurl->add_call('appendlist','get',$url,$params);
124
         $response = $this->mcurl->execute($url);
125
         $data['response'] = $response['appendlist']['response'];
126
		 $response = $this->magento_model->product_list($data);
127
		 $count = $response[0]->result->totalCount;
128
		 $productListResponse ='';
129
		 $TotalPage = ceil($count/10);
130
		 if($TotalPage < $page) {$product_list='';}
131
		 else{$product_list = $response;}
132
		 	if(isset($product_list) and !empty($product_list))
133
		{
134
			foreach($product_list[0]->result->results as $pl)
135
			{
10949 lgm 136
				if(isset($pl->image_url) and !empty($pl->image_url))
137
					{
10582 lgm 138
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
12188 anikendra 139
          				<div class="pd-image" style="background:url('.$pl->image_url.')no-repeat center center;background-size:contain;"></div>';
140
          				if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)) {
141
          					$productListResponse .= '<div class="pd-info">
10582 lgm 142
            				<div class="pdt-name">'.$pl->title.'</div>
10949 lgm 143
           			 		<div class="pdt-price">';
144
           			 		if(isset($pl->price) || isset($pl->mrp)){
145
           			 			$productListResponse .='<span class="pr">Rs</span>';
146
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
147
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
148
           			 			}
149
           			 			if(isset($pl->price) && $pl->price != 0){
150
           			 				$productListResponse .='<span class="pr-original">'. $pl->price.'</span>';
151
           			 			}			
152
           			 		}
153
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
12188 anikendra 154
						} else{
155
							$productListResponse .= '<div class="pd-info">
156
            				<div class="pdt-name">'.$pl->title.'</div>
157
           			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
158
           			 		if(isset($pl->price) || isset($pl->mrp)){
159
           			 			$productListResponse .='<span class="pr">Rs</span>';
160
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
161
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
162
           			 			}
163
           			 			if(isset($pl->price) && $pl->price != 0){
164
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
165
           			 			}	
166
           			 		}
167
							if(isset($pl->dealprice) && $pl->dealprice != 0){
168
								$productListResponse .='</div><div class="pdt-price pdeal-price"><span class="pricetype">Your Price</span><span class="pr">Rs</span> <span class="pr-original">'.$pl->dealprice.'</span></div>';
169
							}			
170
           			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
171
	           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
172
	           			 	}
173
							$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
174
 
175
							if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
176
								$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
177
							}
178
 
179
           			 		$productListResponse .= '</div></a>';
180
						}
10949 lgm 181
					}				
10582 lgm 182
 
183
			}
184
		}
185
		echo $productListResponse;
186
 
187
	}
188
	public function filter(){
189
		$configdata = $this->config->item('searchfilter');
190
		$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata);
191
		$this->layout->view('search/search_view',$data);
192
	}
193
 
194
 
195
 
196
}
197
 
198
/* End of file welcome.php */
12223 anikendra 199
/* Location: ./application/controllers/welcome.php */