Subversion Repositories SmartDukaan

Rev

Rev 12192 | 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;	
12162 anikendra 135
 
10582 lgm 136
         $params = array();
137
         $params['index'] = ($page-1)*10;
138
         $params['offset'] = 10;
139
         if(isset($sort) && $sort != 'null'){
140
         	$params['sortedBy'] = $sort;
141
         }
142
        if(isset($price) && $price != 'null'){
143
         	$price = explode('&', $price);
144
         	if(intval($price[0]) < intval($price[1])){
145
         		$params['minPrice'] = $price[0];
146
         		$params['maxPrice'] = $price[1];
147
         	}
148
         	else{
149
         		$params['minPrice'] = $price[1];
150
         		$params['maxPrice'] = $price[0];
151
         	}
152
         }
153
         if(isset($filter) && $filter != 'null'){
154
         	$url .= '?fq='.rawurldecode($filter);
155
         }	
12162 anikendra 156
        $authorized = $this->session->userdata('authorized');
157
 
10582 lgm 158
         $this->mcurl->add_call('appendlist','get',$url,$params);
159
         $response = $this->mcurl->execute($url);
160
         $data['response'] = $response['appendlist']['response'];
161
		 $response = $this->magento_model->product_list($data);
162
		 $count = $response[0]->result->totalCount;
163
		 $productListResponse ='';
164
		 $TotalPage = ceil($count/10);
165
		 if($TotalPage < $page) {$product_list='';}
166
		 else{$product_list = $response;}
10949 lgm 167
 
168
		if(isset($product_list) and !empty($product_list))
10582 lgm 169
		{
170
			foreach($product_list[0]->result->results as $pl)
171
			{
172
				if(isset($pl->image_url) and !empty($pl->image_url))
173
				{
12162 anikendra 174
					$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
175
      				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>';
12192 anikendra 176
  					if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)){
12162 anikendra 177
      					$productListResponse .= '<div class="pd-info">
178
        				<div class="pdt-name">'.$pl->title.'</div>
179
       			 		<div class="pdt-price">';
180
       			 		if(isset($pl->price) || isset($pl->mrp)){
181
       			 			$productListResponse .='<span class="pr">Rs</span>';
182
       			 			if(isset($pl->mrp) && $pl->mrp != 0){
183
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
184
       			 			}
185
       			 			if(isset($pl->price) && $pl->price != 0){
186
       			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
187
       			 			}		
188
       			 			$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';		
189
       			 		} 
190
   			 		} else {
191
   			 			$productListResponse .= '<div class="pd-info">
192
        				<div class="pdt-name">'.$pl->title.'</div>
193
       			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
194
       			 		if(isset($pl->price) || isset($pl->mrp)){
195
       			 			$productListResponse .='<span class="pr">Rs</span>';
196
       			 			if(isset($pl->mrp) && $pl->mrp != 0){
197
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
198
       			 			}
199
       			 			if(isset($pl->price) && $pl->price != 0){
200
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
201
       			 			}	
202
       			 		}
203
						if(isset($pl->dealprice) && $pl->dealprice != 0){
204
							$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>';
205
						}			
206
       			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
207
           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
208
           			 	}
209
						$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
210
 
211
						if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
212
							$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
213
						}
214
 
215
       			 		$productListResponse .= '</div></a>';
216
   			 		}       			 		
10582 lgm 217
				}		
218
 
219
			}
220
		}
221
		echo $productListResponse;
222
 
223
	}
224
	public function getSpecialProductList($category,$page=null){
225
		if(isset($category) && !empty($category)){
12162 anikendra 226
			$authorized=$this->session->userdata('authorized');
10582 lgm 227
			if($category == 'coming-soon'){
228
				$url = $this->config->item('coming_soon');
229
			}
230
			$url = $url['url'];
231
         	$url = $this->config->item('curl_base_url').$url.'/'.$page;
232
         	$params = array();
12162 anikendra 233
         	if($authorized['Id'] > 0){
234
				$url .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
235
			}
236
			if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
237
				$url .= '&privateDealUser=true';
238
			}
10582 lgm 239
         	$this->mcurl->add_call('appendlist','get',$url,$params);
240
         	$response = $this->mcurl->execute($url);
241
         	$data['response'] = $response['appendlist']['response'];
242
		 	$response = $this->magento_model->coming_soon($data);
243
		 	$count = $response[0]->response->count;
244
			$productListResponse ='';
245
			$count = $count-20;
246
			$TotalPage = ceil($count/10);
247
			if($TotalPage < $page) {$coming_soon='';}
248
			 else{$coming_soon = $response;}
249
			 	if(isset($coming_soon) and !empty($coming_soon))
250
			{
251
				foreach($coming_soon[0]->response->items as $pl)
252
				{
253
					if(isset($pl->image_url) and !empty($pl->image_url))
254
					{
10949 lgm 255
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
12228 anikendra 256
          				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>';
12192 anikendra 257
      					if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)){
12162 anikendra 258
          					$productListResponse .= '<div class="pd-info">
10949 lgm 259
            				<div class="pdt-name">'.$pl->title.'</div>
260
           			 		<div class="pdt-price">';
261
           			 		if(isset($pl->price) || isset($pl->mrp)){
262
           			 			$productListResponse .='<span class="pr">Rs</span>';
263
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
264
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
265
           			 			}
266
           			 			if(isset($pl->price) && $pl->price != 0){
267
           			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
268
           			 			}			
269
           			 		}
270
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
12162 anikendra 271
						}else{
272
							$productListResponse .= '<div class="pd-info">
273
            				<div class="pdt-name">'.$pl->title.'</div>
274
           			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
275
           			 		if(isset($pl->price) || isset($pl->mrp)){
276
           			 			$productListResponse .='<span class="pr">Rs</span>';
277
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
278
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
279
           			 			}
280
           			 			if(isset($pl->price) && $pl->price != 0){
281
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
282
           			 			}	
283
           			 		}
284
							if(isset($pl->dealprice) && $pl->dealprice != 0){
285
								$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>';
286
							}			
287
           			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
288
	           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
289
	           			 	}
290
							$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
291
 
292
							if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
293
								$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
294
							}
295
 
296
           			 		$productListResponse .= '</div></a>';
297
						}
10949 lgm 298
					}				
10582 lgm 299
 
300
				}
301
			}
302
			echo $productListResponse;
303
			}
304
	}
305
 
306
	public function filter(){
307
		$configdata = $this->config->item('filter');
308
		$data['response']=$this->product_model->getProducts($this->input->get(),$this->input->post(),$configdata);
309
		$this->layout->view('products/products_view',$data);
310
	}
311
 
312
 
313
}
314
 
315
/* End of file welcome.php */
11504 anikendra 316
/* Location: ./application/controllers/welcome.php */