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