Subversion Repositories SmartDukaan

Rev

Rev 11013 | Rev 12159 | 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);
33
		//end of get cache
34
		if(array_key_exists('fq', $_GET) || array_key_exists('sortedBy', $_GET) || array_key_exists('minPrice', $_GET)){
35
			$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$_SERVER['QUERY_STRING']);
36
		}else{
37
			$searchName = 'seacrh'.$this->input->get('q');
38
			$cache = getFileCache($searchName);
39
			if(isset($cache) && !empty($cache)){
40
				$data['response'] = $cache;
41
			}else{
42
				$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$_SERVER['QUERY_STRING']);
43
				setFileCache($data['response'], $searchName,300);
44
			}
45
		}
46
		//set cache to output or renew cache
47
		if(isset($cachemodule) and !empty($cachemodule))
48
		{
49
			foreach($cachemodule as $cm)
50
			{
51
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
52
				{
53
					$data['response'][$cm]=$configdata[$cm];
54
				}
55
			}
56
		}
57
		setCache($configdata['module'],$cachemodule,$data['response']);
58
		$this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
11013 lgm 59
		if(isset($data['response']['response']['search_list'][0]->result->title))
60
		$title = $data['response']['response']['search_list'][0]->result->title;
61
		if(isset($title) && !empty($title)){
62
			$data['title'] = $title;
63
		}
64
		if(isset($data['response']['response']['search_list'][0]->result->metaDescription))
65
		$metaDescription = $data['response']['response']['search_list'][0]->result->metaDescription;
66
		if(isset($metaDescription) && !empty($metaDescription)){
67
			$data['metaDescription'] = $metaDescription;
68
		}
69
		if(isset($data['response']['response']['search_list'][0]->result->metaKeywords))
70
		$metaKeywords = $data['response']['response']['search_list'][0]->result->metaKeywords;
71
		if(isset($metaKeywords) && !empty($metaKeywords)){
72
			$data['metaKeywords'] = $metaKeywords;
73
		}
10582 lgm 74
		$data['stylesheet'] = 'pd-list.css';
75
		//end of set cache
76
		$this->layout->view('search/search_view',$data);
77
 
78
	}
79
 
80
	public function getSearchList($page,$name,$sort=null,$filter=null,$price=null)
81
	{
82
         $url = $this->config->item('search_list');
83
	  	 $url = $url['url'];
84
         $url = $this->config->item('curl_base_url').$url;	
85
         $params['q'] = rawurldecode($name);
86
         $params['index'] = ($page-1)*10;
87
         $params['offset'] = 10;
88
         if(isset($sort) && $sort != 'null'){
89
         	$params['sortedBy'] = $sort;
90
         }
91
         if(isset($price) && $price != 'null'){
92
         	$price = explode('&', $price);
93
         	if(intval($price[0]) < intval($price[1])){
94
         		$params['minPrice'] = $price[0];
95
         		$params['maxPrice'] = $price[1];
96
         	}
97
         	else{
98
         		$params['minPrice'] = $price[1];
99
         		$params['maxPrice'] = $price[0];
100
         	}
101
         }
102
         if(isset($filter) && $filter != 'null'){
103
         	$url .= '?fq='.rawurldecode($filter);
104
         }		
105
         $this->mcurl->add_call('appendlist','get',$url,$params);
106
         $response = $this->mcurl->execute($url);
107
         $data['response'] = $response['appendlist']['response'];
108
		 $response = $this->magento_model->product_list($data);
109
		 $count = $response[0]->result->totalCount;
110
		 $productListResponse ='';
111
		 $TotalPage = ceil($count/10);
112
		 if($TotalPage < $page) {$product_list='';}
113
		 else{$product_list = $response;}
114
		 	if(isset($product_list) and !empty($product_list))
115
		{
116
			foreach($product_list[0]->result->results as $pl)
117
			{
10949 lgm 118
				if(isset($pl->image_url) and !empty($pl->image_url))
119
					{
10582 lgm 120
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
121
          				<div class="pd-image" style="background:url('.$pl->image_url.')no-repeat center center;background-size:contain;"></div>
122
          					<div class="pd-info">
123
            				<div class="pdt-name">'.$pl->title.'</div>
10949 lgm 124
           			 		<div class="pdt-price">';
125
           			 		if(isset($pl->price) || isset($pl->mrp)){
126
           			 			$productListResponse .='<span class="pr">Rs</span>';
127
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
128
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
129
           			 			}
130
           			 			if(isset($pl->price) && $pl->price != 0){
131
           			 				$productListResponse .='<span class="pr-original">'. $pl->price.'</span>';
132
           			 			}			
133
           			 		}
134
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
135
 
136
					}				
10582 lgm 137
 
138
			}
139
		}
140
		echo $productListResponse;
141
 
142
	}
143
	public function filter(){
144
		$configdata = $this->config->item('searchfilter');
145
		$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata);
146
		$this->layout->view('search/search_view',$data);
147
	}
148
 
149
 
150
 
151
}
152
 
153
/* End of file welcome.php */
154
/* Location: ./application/controllers/welcome.php */