Subversion Repositories SmartDukaan

Rev

Rev 12228 | Rev 12571 | 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');
12229 anikendra 45
			if(!isset($authorized['isPrivateDealUser'])) {
46
				$cache = getFileCache($searchName);
47
			}
10582 lgm 48
			if(isset($cache) && !empty($cache)){
49
				$data['response'] = $cache;
50
			}else{
51
				$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$_SERVER['QUERY_STRING']);
12229 anikendra 52
				if(!isset($authorized['isPrivateDealUser'])) {
53
					setFileCache($data['response'], $searchName,300);
54
				}
10582 lgm 55
			}
56
		}
57
		//set cache to output or renew cache
58
		if(isset($cachemodule) and !empty($cachemodule))
59
		{
60
			foreach($cachemodule as $cm)
61
			{
62
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
63
				{
64
					$data['response'][$cm]=$configdata[$cm];
65
				}
66
			}
67
		}
68
		setCache($configdata['module'],$cachemodule,$data['response']);
69
		$this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
11013 lgm 70
		if(isset($data['response']['response']['search_list'][0]->result->title))
71
		$title = $data['response']['response']['search_list'][0]->result->title;
72
		if(isset($title) && !empty($title)){
73
			$data['title'] = $title;
74
		}
75
		if(isset($data['response']['response']['search_list'][0]->result->metaDescription))
76
		$metaDescription = $data['response']['response']['search_list'][0]->result->metaDescription;
77
		if(isset($metaDescription) && !empty($metaDescription)){
78
			$data['metaDescription'] = $metaDescription;
79
		}
80
		if(isset($data['response']['response']['search_list'][0]->result->metaKeywords))
81
		$metaKeywords = $data['response']['response']['search_list'][0]->result->metaKeywords;
82
		if(isset($metaKeywords) && !empty($metaKeywords)){
83
			$data['metaKeywords'] = $metaKeywords;
84
		}
10582 lgm 85
		$data['stylesheet'] = 'pd-list.css';
86
		//end of set cache
87
		$this->layout->view('search/search_view',$data);
88
 
89
	}
90
 
91
	public function getSearchList($page,$name,$sort=null,$filter=null,$price=null)
92
	{
12188 anikendra 93
		$authorized=$this->session->userdata('authorized');
10582 lgm 94
         $url = $this->config->item('search_list');
95
	  	 $url = $url['url'];
96
         $url = $this->config->item('curl_base_url').$url;	
97
         $params['q'] = rawurldecode($name);
98
         $params['index'] = ($page-1)*10;
99
         $params['offset'] = 10;
100
         if(isset($sort) && $sort != 'null'){
101
         	$params['sortedBy'] = $sort;
102
         }
103
         if(isset($price) && $price != 'null'){
104
         	$price = explode('&', $price);
105
         	if(intval($price[0]) < intval($price[1])){
106
         		$params['minPrice'] = $price[0];
107
         		$params['maxPrice'] = $price[1];
108
         	}
109
         	else{
110
         		$params['minPrice'] = $price[1];
111
         		$params['maxPrice'] = $price[0];
112
         	}
113
         }
114
         if(isset($filter) && $filter != 'null'){
115
         	$url .= '?fq='.rawurldecode($filter);
116
         }		
12188 anikendra 117
		if($authorized['Id'] > 0){
12223 anikendra 118
			if(strpos($url,'?')===false){
119
				$url .= '?userId='.$authorized['Id'].'&isLoggedIn=true';
120
			}else{
121
				$url .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
122
			}
12188 anikendra 123
		}
124
		if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
125
			$url .= '&privateDealUser=true';
126
		}
10582 lgm 127
         $this->mcurl->add_call('appendlist','get',$url,$params);
128
         $response = $this->mcurl->execute($url);
129
         $data['response'] = $response['appendlist']['response'];
130
		 $response = $this->magento_model->product_list($data);
131
		 $count = $response[0]->result->totalCount;
132
		 $productListResponse ='';
133
		 $TotalPage = ceil($count/10);
134
		 if($TotalPage < $page) {$product_list='';}
135
		 else{$product_list = $response;}
136
		 	if(isset($product_list) and !empty($product_list))
137
		{
138
			foreach($product_list[0]->result->results as $pl)
139
			{
10949 lgm 140
				if(isset($pl->image_url) and !empty($pl->image_url))
141
					{
10582 lgm 142
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
12228 anikendra 143
          				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>';
12188 anikendra 144
          				if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)) {
145
          					$productListResponse .= '<div class="pd-info">
10582 lgm 146
            				<div class="pdt-name">'.$pl->title.'</div>
10949 lgm 147
           			 		<div class="pdt-price">';
148
           			 		if(isset($pl->price) || isset($pl->mrp)){
149
           			 			$productListResponse .='<span class="pr">Rs</span>';
150
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
151
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
152
           			 			}
153
           			 			if(isset($pl->price) && $pl->price != 0){
154
           			 				$productListResponse .='<span class="pr-original">'. $pl->price.'</span>';
155
           			 			}			
156
           			 		}
157
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
12188 anikendra 158
						} else{
159
							$productListResponse .= '<div class="pd-info">
160
            				<div class="pdt-name">'.$pl->title.'</div>
161
           			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
162
           			 		if(isset($pl->price) || isset($pl->mrp)){
163
           			 			$productListResponse .='<span class="pr">Rs</span>';
164
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
165
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
166
           			 			}
167
           			 			if(isset($pl->price) && $pl->price != 0){
168
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
169
           			 			}	
170
           			 		}
171
							if(isset($pl->dealprice) && $pl->dealprice != 0){
172
								$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>';
173
							}			
174
           			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
175
	           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
176
	           			 	}
177
							$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
178
 
179
							if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
180
								$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
181
							}
182
 
183
           			 		$productListResponse .= '</div></a>';
184
						}
10949 lgm 185
					}				
10582 lgm 186
 
187
			}
188
		}
189
		echo $productListResponse;
190
 
191
	}
192
	public function filter(){
193
		$configdata = $this->config->item('searchfilter');
194
		$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata);
195
		$this->layout->view('search/search_view',$data);
196
	}
197
 
198
 
199
 
200
}
201
 
202
/* End of file welcome.php */
12223 anikendra 203
/* Location: ./application/controllers/welcome.php */