Subversion Repositories SmartDukaan

Rev

Rev 12228 | 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
			}
12229 anikendra 73
			if(isset($productName) && !empty($productName) && !isset($authorized['isPrivateDealUser'])) {
10582 lgm 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']);
12229 anikendra 80
				if(isset($productName)) {
81
					if(!isset($authorized['isPrivateDealUser'])) {
82
						setFileCache($data['response'], $productName,300);
83
					}
10582 lgm 84
				}
85
			}
86
		}else{
87
			$data['response']=$this->product_model->getProducts('',$this->input->post(),$configdata['module'], $itemcode,$_SERVER['QUERY_STRING']);
88
		}	
89
		//set cache to output or renew cache
90
		if(isset($cachemodule) and !empty($cachemodule))
91
		{
92
			foreach($cachemodule as $cm)
93
			{
94
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
95
				{
96
					$data['response'][$cm]=$configdata[$cm];
97
				}
98
			}
99
		}
100
		setCache($configdata['module'],$cachemodule,$data['response']);
101
		$this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
102
		$data['stylesheet'] = 'pd-list.css';
10910 lgm 103
		if($itemName != 'coming-soon' && $itemName !== 'best-deals'){
10917 lgm 104
			if(isset($data['response']['response'][$name][0]->result->title))
10910 lgm 105
			$title = $data['response']['response'][$name][0]->result->title;
106
			if(isset($title) && !empty($title)){
107
				$data['title'] = $title;
108
			}
10917 lgm 109
			if(isset($data['response']['response'][$name][0]->result->metaDescription))
10910 lgm 110
			$metaDescription = $data['response']['response'][$name][0]->result->metaDescription;
111
			if(isset($metaDescription) && !empty($metaDescription)){
112
				$data['metaDescription'] = $metaDescription;
113
			}
10917 lgm 114
			if(isset($data['response']['response'][$name][0]->result->metaKeywords))
10910 lgm 115
			$metaKeywords = $data['response']['response'][$name][0]->result->metaKeywords;
116
			if(isset($metaKeywords) && !empty($metaKeywords)){
117
				$data['metaKeywords'] = $metaKeywords;
118
			}
119
		}
10582 lgm 120
		//end of set cache
121
		$this->layout->view('products/products_view',$data);
122
	}
123
 
124
 
125
	public function getProductList($category,$page=null,$sort=null,$filter=null,$price=null)
126
	{
127
		 $value = intval($category);
128
         if(($value !== 0) && ($category == 1)){
129
         	$url = $this->config->item('coming_soon');
130
         }elseif(($value !== 0) && ($category !=1)){
131
         	$url = $this->config->item('product_list');
132
         }elseif($value == 0){
133
         	$url = $this->config->item('special_page');
134
         }
135
	  	 $url = $url['url'];
136
         $url = $this->config->item('curl_base_url').$url.'/'.$category;	
12162 anikendra 137
 
10582 lgm 138
         $params = array();
139
         $params['index'] = ($page-1)*10;
140
         $params['offset'] = 10;
141
         if(isset($sort) && $sort != 'null'){
142
         	$params['sortedBy'] = $sort;
143
         }
144
        if(isset($price) && $price != 'null'){
145
         	$price = explode('&', $price);
146
         	if(intval($price[0]) < intval($price[1])){
147
         		$params['minPrice'] = $price[0];
148
         		$params['maxPrice'] = $price[1];
149
         	}
150
         	else{
151
         		$params['minPrice'] = $price[1];
152
         		$params['maxPrice'] = $price[0];
153
         	}
154
         }
155
         if(isset($filter) && $filter != 'null'){
156
         	$url .= '?fq='.rawurldecode($filter);
157
         }	
12162 anikendra 158
        $authorized = $this->session->userdata('authorized');
159
 
10582 lgm 160
         $this->mcurl->add_call('appendlist','get',$url,$params);
161
         $response = $this->mcurl->execute($url);
162
         $data['response'] = $response['appendlist']['response'];
163
		 $response = $this->magento_model->product_list($data);
164
		 $count = $response[0]->result->totalCount;
165
		 $productListResponse ='';
166
		 $TotalPage = ceil($count/10);
167
		 if($TotalPage < $page) {$product_list='';}
168
		 else{$product_list = $response;}
10949 lgm 169
 
170
		if(isset($product_list) and !empty($product_list))
10582 lgm 171
		{
172
			foreach($product_list[0]->result->results as $pl)
173
			{
174
				if(isset($pl->image_url) and !empty($pl->image_url))
175
				{
12162 anikendra 176
					$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
177
      				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>';
12192 anikendra 178
  					if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)){
12162 anikendra 179
      					$productListResponse .= '<div class="pd-info">
180
        				<div class="pdt-name">'.$pl->title.'</div>
181
       			 		<div class="pdt-price">';
182
       			 		if(isset($pl->price) || isset($pl->mrp)){
183
       			 			$productListResponse .='<span class="pr">Rs</span>';
184
       			 			if(isset($pl->mrp) && $pl->mrp != 0){
185
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
186
       			 			}
187
       			 			if(isset($pl->price) && $pl->price != 0){
188
       			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
189
       			 			}		
190
       			 			$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';		
191
       			 		} 
192
   			 		} else {
193
   			 			$productListResponse .= '<div class="pd-info">
194
        				<div class="pdt-name">'.$pl->title.'</div>
195
       			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
196
       			 		if(isset($pl->price) || isset($pl->mrp)){
197
       			 			$productListResponse .='<span class="pr">Rs</span>';
198
       			 			if(isset($pl->mrp) && $pl->mrp != 0){
199
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
200
       			 			}
201
       			 			if(isset($pl->price) && $pl->price != 0){
202
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
203
       			 			}	
204
       			 		}
205
						if(isset($pl->dealprice) && $pl->dealprice != 0){
206
							$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>';
207
						}			
208
       			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
209
           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
210
           			 	}
211
						$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
212
 
213
						if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
214
							$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
215
						}
216
 
217
       			 		$productListResponse .= '</div></a>';
218
   			 		}       			 		
10582 lgm 219
				}		
220
 
221
			}
222
		}
223
		echo $productListResponse;
224
 
225
	}
226
	public function getSpecialProductList($category,$page=null){
227
		if(isset($category) && !empty($category)){
12162 anikendra 228
			$authorized=$this->session->userdata('authorized');
10582 lgm 229
			if($category == 'coming-soon'){
230
				$url = $this->config->item('coming_soon');
231
			}
232
			$url = $url['url'];
233
         	$url = $this->config->item('curl_base_url').$url.'/'.$page;
234
         	$params = array();
12162 anikendra 235
         	if($authorized['Id'] > 0){
236
				$url .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
237
			}
238
			if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
239
				$url .= '&privateDealUser=true';
240
			}
10582 lgm 241
         	$this->mcurl->add_call('appendlist','get',$url,$params);
242
         	$response = $this->mcurl->execute($url);
243
         	$data['response'] = $response['appendlist']['response'];
244
		 	$response = $this->magento_model->coming_soon($data);
245
		 	$count = $response[0]->response->count;
246
			$productListResponse ='';
247
			$count = $count-20;
248
			$TotalPage = ceil($count/10);
249
			if($TotalPage < $page) {$coming_soon='';}
250
			 else{$coming_soon = $response;}
251
			 	if(isset($coming_soon) and !empty($coming_soon))
252
			{
253
				foreach($coming_soon[0]->response->items as $pl)
254
				{
255
					if(isset($pl->image_url) and !empty($pl->image_url))
256
					{
10949 lgm 257
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
12228 anikendra 258
          				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>';
12192 anikendra 259
      					if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)){
12162 anikendra 260
          					$productListResponse .= '<div class="pd-info">
10949 lgm 261
            				<div class="pdt-name">'.$pl->title.'</div>
262
           			 		<div class="pdt-price">';
263
           			 		if(isset($pl->price) || isset($pl->mrp)){
264
           			 			$productListResponse .='<span class="pr">Rs</span>';
265
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
266
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
267
           			 			}
268
           			 			if(isset($pl->price) && $pl->price != 0){
269
           			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
270
           			 			}			
271
           			 		}
272
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
12162 anikendra 273
						}else{
274
							$productListResponse .= '<div class="pd-info">
275
            				<div class="pdt-name">'.$pl->title.'</div>
276
           			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
277
           			 		if(isset($pl->price) || isset($pl->mrp)){
278
           			 			$productListResponse .='<span class="pr">Rs</span>';
279
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
280
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
281
           			 			}
282
           			 			if(isset($pl->price) && $pl->price != 0){
283
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
284
           			 			}	
285
           			 		}
286
							if(isset($pl->dealprice) && $pl->dealprice != 0){
287
								$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>';
288
							}			
289
           			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
290
	           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
291
	           			 	}
292
							$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
293
 
294
							if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
295
								$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
296
							}
297
 
298
           			 		$productListResponse .= '</div></a>';
299
						}
10949 lgm 300
					}				
10582 lgm 301
 
302
				}
303
			}
304
			echo $productListResponse;
305
			}
306
	}
307
 
308
	public function filter(){
309
		$configdata = $this->config->item('filter');
310
		$data['response']=$this->product_model->getProducts($this->input->get(),$this->input->post(),$configdata);
311
		$this->layout->view('products/products_view',$data);
312
	}
313
 
314
 
315
}
316
 
317
/* End of file welcome.php */
11504 anikendra 318
/* Location: ./application/controllers/welcome.php */