Subversion Repositories SmartDukaan

Rev

Rev 11504 | Rev 12162 | 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 Products 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('product_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
 
12159 anikendra 26
		$last = $this->uri->total_segments();		
10582 lgm 27
		$itemcode = $this->uri->segment($last);
28
		$itemName = $this->uri->segment($last-1);
29
		//standard array
30
		$data = array();
31
		//get cache 
32
		$configdata =array();
33
		$configdata = $this->config->item('productlist');
34
		if(is_numeric($itemcode) && ($itemName == 'coming-soon')) {
35
			unset($configdata['response'][0]);
36
			unset($configdata['response'][1]);
37
			unset($configdata['response'][3]);
38
		}elseif(is_numeric($itemcode) && ($itemName == 'best-deals')){
39
			unset($configdata['response'][0]);
40
			unset($configdata['response'][1]);
41
			unset($configdata['response'][2]);
42
		}
43
		elseif(is_numeric($itemcode) && ($itemcode != 1)) {
44
			unset($configdata['response'][1]);
45
			unset($configdata['response'][2]);
46
			unset($configdata['response'][3]);
47
		}
48
		elseif(is_string($itemcode)) {
49
			unset($configdata['response'][0]);
50
			unset($configdata['response'][2]);
51
			unset($configdata['response'][3]);	
52
		}
10910 lgm 53
		$name = $configdata['response'];
54
		foreach ($name as $key => $value) {
55
			$name = $value;
56
		}
10582 lgm 57
		$cachemodule = array('header','footer');
58
		$configdata = getCache($configdata,$cachemodule);
12159 anikendra 59
		$authorized = $this->session->userdata('authorized');
60
		if($authorized['Id'] > 0){
61
			$_SERVER['QUERY_STRING'] .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
62
		}
63
		if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
64
			$_SERVER['QUERY_STRING'] .= '&privateDealUser=true';
65
		}
10582 lgm 66
		//end of get cache
67
		if(empty($_GET)){
68
			if($itemName != 'coming-soon' && $itemName !== 'best-deals'){
69
				$productName = $itemcode;
70
			}elseif($itemName == 'coming-soon' || $itemName == 'best-deals') {
71
				$productName = $itemName;
72
			}
73
			if(isset($productName) && !empty($productName)){
74
				$cache = getFileCache($productName);
75
			}
76
			if(isset($cache) && !empty($cache)){
77
				$data['response'] = $cache;
78
			}else{
79
				$data['response']=$this->product_model->getProducts('',$this->input->post(),$configdata['module'], $itemcode,$_SERVER['QUERY_STRING']);
80
				if(isset($productName)){
81
					setFileCache($data['response'], $productName,300);
82
				}
83
			}
84
		}else{
85
			$data['response']=$this->product_model->getProducts('',$this->input->post(),$configdata['module'], $itemcode,$_SERVER['QUERY_STRING']);
86
		}	
87
		//set cache to output or renew cache
88
		if(isset($cachemodule) and !empty($cachemodule))
89
		{
90
			foreach($cachemodule as $cm)
91
			{
92
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
93
				{
94
					$data['response'][$cm]=$configdata[$cm];
95
				}
96
			}
97
		}
98
		setCache($configdata['module'],$cachemodule,$data['response']);
99
		$this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
100
		$data['stylesheet'] = 'pd-list.css';
10910 lgm 101
		if($itemName != 'coming-soon' && $itemName !== 'best-deals'){
10917 lgm 102
			if(isset($data['response']['response'][$name][0]->result->title))
10910 lgm 103
			$title = $data['response']['response'][$name][0]->result->title;
104
			if(isset($title) && !empty($title)){
105
				$data['title'] = $title;
106
			}
10917 lgm 107
			if(isset($data['response']['response'][$name][0]->result->metaDescription))
10910 lgm 108
			$metaDescription = $data['response']['response'][$name][0]->result->metaDescription;
109
			if(isset($metaDescription) && !empty($metaDescription)){
110
				$data['metaDescription'] = $metaDescription;
111
			}
10917 lgm 112
			if(isset($data['response']['response'][$name][0]->result->metaKeywords))
10910 lgm 113
			$metaKeywords = $data['response']['response'][$name][0]->result->metaKeywords;
114
			if(isset($metaKeywords) && !empty($metaKeywords)){
115
				$data['metaKeywords'] = $metaKeywords;
116
			}
117
		}
10582 lgm 118
		//end of set cache
119
		$this->layout->view('products/products_view',$data);
120
	}
121
 
122
 
123
	public function getProductList($category,$page=null,$sort=null,$filter=null,$price=null)
124
	{
125
		 $value = intval($category);
126
         if(($value !== 0) && ($category == 1)){
127
         	$url = $this->config->item('coming_soon');
128
         }elseif(($value !== 0) && ($category !=1)){
129
         	$url = $this->config->item('product_list');
130
         }elseif($value == 0){
131
         	$url = $this->config->item('special_page');
132
         }
133
	  	 $url = $url['url'];
134
         $url = $this->config->item('curl_base_url').$url.'/'.$category;	
135
         $params = array();
136
         $params['index'] = ($page-1)*10;
137
         $params['offset'] = 10;
138
         if(isset($sort) && $sort != 'null'){
139
         	$params['sortedBy'] = $sort;
140
         }
141
        if(isset($price) && $price != 'null'){
142
         	$price = explode('&', $price);
143
         	if(intval($price[0]) < intval($price[1])){
144
         		$params['minPrice'] = $price[0];
145
         		$params['maxPrice'] = $price[1];
146
         	}
147
         	else{
148
         		$params['minPrice'] = $price[1];
149
         		$params['maxPrice'] = $price[0];
150
         	}
151
         }
152
         if(isset($filter) && $filter != 'null'){
153
         	$url .= '?fq='.rawurldecode($filter);
154
         }	
155
         $this->mcurl->add_call('appendlist','get',$url,$params);
156
         $response = $this->mcurl->execute($url);
157
         $data['response'] = $response['appendlist']['response'];
158
		 $response = $this->magento_model->product_list($data);
159
		 $count = $response[0]->result->totalCount;
160
		 $productListResponse ='';
161
		 $TotalPage = ceil($count/10);
162
		 if($TotalPage < $page) {$product_list='';}
163
		 else{$product_list = $response;}
10949 lgm 164
 
165
		if(isset($product_list) and !empty($product_list))
10582 lgm 166
		{
167
			foreach($product_list[0]->result->results as $pl)
168
			{
169
				if(isset($pl->image_url) and !empty($pl->image_url))
170
				{
171
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
11504 anikendra 172
          				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>
10582 lgm 173
          					<div class="pd-info">
174
            				<div class="pdt-name">'.$pl->title.'</div>
10949 lgm 175
           			 		<div class="pdt-price">';
176
           			 		if(isset($pl->price) || isset($pl->mrp)){
177
           			 			$productListResponse .='<span class="pr">Rs</span>';
178
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
179
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
180
           			 			}
181
           			 			if(isset($pl->price) && $pl->price != 0){
182
           			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
183
           			 			}			
184
           			 		}
185
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
10582 lgm 186
 
187
				}		
188
 
189
			}
190
		}
191
		echo $productListResponse;
192
 
193
	}
194
	public function getSpecialProductList($category,$page=null){
195
		if(isset($category) && !empty($category)){
196
			if($category == 'coming-soon'){
197
				$url = $this->config->item('coming_soon');
198
			}
199
			$url = $url['url'];
200
         	$url = $this->config->item('curl_base_url').$url.'/'.$page;
201
         	$params = array();
202
         	$this->mcurl->add_call('appendlist','get',$url,$params);
203
         	$response = $this->mcurl->execute($url);
204
         	$data['response'] = $response['appendlist']['response'];
205
		 	$response = $this->magento_model->coming_soon($data);
206
		 	$count = $response[0]->response->count;
207
			$productListResponse ='';
208
			$count = $count-20;
209
			$TotalPage = ceil($count/10);
210
			if($TotalPage < $page) {$coming_soon='';}
211
			 else{$coming_soon = $response;}
212
			 	if(isset($coming_soon) and !empty($coming_soon))
213
			{
214
				foreach($coming_soon[0]->response->items as $pl)
215
				{
216
					if(isset($pl->image_url) and !empty($pl->image_url))
217
					{
10949 lgm 218
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
219
          				<div class="pd-image" style="background:url('.$pl->image_url.')no-repeat center center;background-size:contain;"></div>
220
          					<div class="pd-info">
221
            				<div class="pdt-name">'.$pl->title.'</div>
222
           			 		<div class="pdt-price">';
223
           			 		if(isset($pl->price) || isset($pl->mrp)){
224
           			 			$productListResponse .='<span class="pr">Rs</span>';
225
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
226
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
227
           			 			}
228
           			 			if(isset($pl->price) && $pl->price != 0){
229
           			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
230
           			 			}			
231
           			 		}
232
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
233
 
234
					}				
10582 lgm 235
 
236
				}
237
			}
238
			echo $productListResponse;
239
			}
240
	}
241
 
242
	public function filter(){
243
		$configdata = $this->config->item('filter');
244
		$data['response']=$this->product_model->getProducts($this->input->get(),$this->input->post(),$configdata);
245
		$this->layout->view('products/products_view',$data);
246
	}
247
 
248
 
249
}
250
 
251
/* End of file welcome.php */
11504 anikendra 252
/* Location: ./application/controllers/welcome.php */