Subversion Repositories SmartDukaan

Rev

Rev 10582 | Rev 11013 | 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();
10
		$admin = $this->session->userdata('admin');
11
		if(!isset($admin) || empty($admin)) {
12
			redirect(base_url().'authorize');
13
		}
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');
59
		$data['stylesheet'] = 'pd-list.css';
60
		//end of set cache
61
		$this->layout->view('search/search_view',$data);
62
 
63
	}
64
 
65
	public function getSearchList($page,$name,$sort=null,$filter=null,$price=null)
66
	{
67
         $url = $this->config->item('search_list');
68
	  	 $url = $url['url'];
69
         $url = $this->config->item('curl_base_url').$url;	
70
         $params['q'] = rawurldecode($name);
71
         $params['index'] = ($page-1)*10;
72
         $params['offset'] = 10;
73
         if(isset($sort) && $sort != 'null'){
74
         	$params['sortedBy'] = $sort;
75
         }
76
         if(isset($price) && $price != 'null'){
77
         	$price = explode('&', $price);
78
         	if(intval($price[0]) < intval($price[1])){
79
         		$params['minPrice'] = $price[0];
80
         		$params['maxPrice'] = $price[1];
81
         	}
82
         	else{
83
         		$params['minPrice'] = $price[1];
84
         		$params['maxPrice'] = $price[0];
85
         	}
86
         }
87
         if(isset($filter) && $filter != 'null'){
88
         	$url .= '?fq='.rawurldecode($filter);
89
         }		
90
         $this->mcurl->add_call('appendlist','get',$url,$params);
91
         $response = $this->mcurl->execute($url);
92
         $data['response'] = $response['appendlist']['response'];
93
		 $response = $this->magento_model->product_list($data);
94
		 $count = $response[0]->result->totalCount;
95
		 $productListResponse ='';
96
		 $TotalPage = ceil($count/10);
97
		 if($TotalPage < $page) {$product_list='';}
98
		 else{$product_list = $response;}
99
		 	if(isset($product_list) and !empty($product_list))
100
		{
101
			foreach($product_list[0]->result->results as $pl)
102
			{
10949 lgm 103
				if(isset($pl->image_url) and !empty($pl->image_url))
104
					{
10582 lgm 105
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
106
          				<div class="pd-image" style="background:url('.$pl->image_url.')no-repeat center center;background-size:contain;"></div>
107
          					<div class="pd-info">
108
            				<div class="pdt-name">'.$pl->title.'</div>
10949 lgm 109
           			 		<div class="pdt-price">';
110
           			 		if(isset($pl->price) || isset($pl->mrp)){
111
           			 			$productListResponse .='<span class="pr">Rs</span>';
112
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
113
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
114
           			 			}
115
           			 			if(isset($pl->price) && $pl->price != 0){
116
           			 				$productListResponse .='<span class="pr-original">'. $pl->price.'</span>';
117
           			 			}			
118
           			 		}
119
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
120
 
121
					}				
10582 lgm 122
 
123
			}
124
		}
125
		echo $productListResponse;
126
 
127
	}
128
	public function filter(){
129
		$configdata = $this->config->item('searchfilter');
130
		$data['response']=$this->search_model->getProducts($this->input->get(),$this->input->post(),$configdata);
131
		$this->layout->view('search/search_view',$data);
132
	}
133
 
134
 
135
 
136
}
137
 
138
/* End of file welcome.php */
139
/* Location: ./application/controllers/welcome.php */