Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12694 anikendra 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();
10
		$this->__fosauthorization();
11
		// $admin = $this->session->userdata('admin');
12
		// if(!isset($admin) || empty($admin)) {
13
		// 	redirect(base_url().'authorize');
14
		// }
15
		$this->layout->setlayout('layout/layout_main');
16
		$this->load->model('product_model');
17
		$this->load->model('magento_model');
18
		$this->layoutName= $this->layout->getLayout();
19
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
20
 
21
 
22
 
23
	}
24
	public function index()
25
	{
26
 
27
		$last = $this->uri->total_segments();		
28
		$itemcode = $this->uri->segment($last);
29
		$itemName = $this->uri->segment($last-1);
30
		//standard array
31
		$data = array();
32
		//get cache 
33
		$configdata =array();
34
		$configdata = $this->config->item('productlist');
35
		if(is_numeric($itemcode) && ($itemName == 'coming-soon')) {
36
			unset($configdata['response'][0]);
37
			unset($configdata['response'][1]);
38
			unset($configdata['response'][3]);
39
		}elseif(is_numeric($itemcode) && ($itemName == 'best-deals')){
40
			unset($configdata['response'][0]);
41
			unset($configdata['response'][1]);
42
			unset($configdata['response'][2]);
43
		}
44
		elseif(is_numeric($itemcode) && ($itemcode != 1)) {
45
			unset($configdata['response'][1]);
46
			unset($configdata['response'][2]);
47
			unset($configdata['response'][3]);
48
		}
49
		elseif(is_string($itemcode)) {
50
			unset($configdata['response'][0]);
51
			unset($configdata['response'][2]);
52
			unset($configdata['response'][3]);	
53
		}
54
		$name = $configdata['response'];
55
		foreach ($name as $key => $value) {
56
			$name = $value;
57
		}
58
		$cachemodule = array('header','footer');
59
		$configdata = getCache($configdata,$cachemodule);
60
		$authorized = $this->session->userdata('authorized');
61
		if($authorized['Id'] > 0){
62
			$_SERVER['QUERY_STRING'] .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
63
		}
64
		if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
65
			$_SERVER['QUERY_STRING'] .= '&privateDealUser=true';
66
		}
67
		//end of get cache
68
		if(empty($_GET)){
69
			if($itemName != 'coming-soon' && $itemName !== 'best-deals'){
70
				$productName = $itemcode;
71
			}elseif($itemName == 'coming-soon' || $itemName == 'best-deals') {
72
				$productName = $itemName;
73
			}
74
			if(isset($productName) && !empty($productName) && !isset($authorized['isPrivateDealUser'])) {
75
				$cache = getFileCache($productName);
76
			}
77
			if(isset($cache) && !empty($cache)){
78
				$data['response'] = $cache;
79
			}else{
80
				$data['response']=$this->product_model->getProducts('',$this->input->post(),$configdata['module'], $itemcode,$_SERVER['QUERY_STRING']);
81
				if(isset($productName)) {
82
					if(!isset($authorized['isPrivateDealUser'])) {
83
						setFileCache($data['response'], $productName,300);
84
					}
85
				}
86
			}
87
		}else{
88
			$data['response']=$this->product_model->getProducts('',$this->input->post(),$configdata['module'], $itemcode,$_SERVER['QUERY_STRING']);
89
		}	
90
		//set cache to output or renew cache
91
		if(isset($cachemodule) and !empty($cachemodule))
92
		{
93
			foreach($cachemodule as $cm)
94
			{
95
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
96
				{
97
					$data['response'][$cm]=$configdata[$cm];
98
				}
99
			}
100
		}
101
		setCache($configdata['module'],$cachemodule,$data['response']);
102
		$this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
103
		$data['stylesheet'] = 'pd-list.css';
104
		if($itemName != 'coming-soon' && $itemName !== 'best-deals'){
105
			if(isset($data['response']['response'][$name][0]->result->title))
106
			$title = $data['response']['response'][$name][0]->result->title;
107
			if(isset($title) && !empty($title)){
108
				$data['title'] = $title;
109
			}
110
			if(isset($data['response']['response'][$name][0]->result->metaDescription))
111
			$metaDescription = $data['response']['response'][$name][0]->result->metaDescription;
112
			if(isset($metaDescription) && !empty($metaDescription)){
113
				$data['metaDescription'] = $metaDescription;
114
			}
115
			if(isset($data['response']['response'][$name][0]->result->metaKeywords))
116
			$metaKeywords = $data['response']['response'][$name][0]->result->metaKeywords;
117
			if(isset($metaKeywords) && !empty($metaKeywords)){
118
				$data['metaKeywords'] = $metaKeywords;
119
			}
120
		}
121
		//end of set cache
122
		$this->layout->view('products/products_view',$data);
123
	}
124
 
125
 
126
	public function getProductList($category,$page=null,$sort=null,$filter=null,$price=null)
127
	{
128
		 $value = intval($category);
129
         if(($value !== 0) && ($category == 1)){
130
         	$url = $this->config->item('coming_soon');
131
         }elseif(($value !== 0) && ($category !=1)){
132
         	$url = $this->config->item('product_list');
133
         }elseif($value == 0){
134
         	$url = $this->config->item('special_page');
135
         }
136
	  	 $url = $url['url'];
137
         $url = $this->config->item('curl_base_url').$url.'/'.$category;	
138
 
139
         $params = array();
140
         $params['index'] = ($page-1)*10;
141
         $params['offset'] = 10;
142
         if(isset($sort) && $sort != 'null'){
143
         	$params['sortedBy'] = $sort;
144
         }
145
        if(isset($price) && $price != 'null'){
146
         	$price = explode('&', $price);
147
         	if(intval($price[0]) < intval($price[1])){
148
         		$params['minPrice'] = $price[0];
149
         		$params['maxPrice'] = $price[1];
150
         	}
151
         	else{
152
         		$params['minPrice'] = $price[1];
153
         		$params['maxPrice'] = $price[0];
154
         	}
155
         }
156
         if(isset($filter) && $filter != 'null'){
157
         	$url .= '?fq='.rawurldecode($filter);
158
         }	
159
        $authorized = $this->session->userdata('authorized');
160
 
161
         $this->mcurl->add_call('appendlist','get',$url,$params);
162
         $response = $this->mcurl->execute($url);
163
         $data['response'] = $response['appendlist']['response'];
164
		 $response = $this->magento_model->product_list($data);
165
		 $count = $response[0]->result->totalCount;
166
		 $productListResponse ='';
167
		 $TotalPage = ceil($count/10);
168
		 if($TotalPage < $page) {$product_list='';}
169
		 else{$product_list = $response;}
170
 
171
		if(isset($product_list) and !empty($product_list))
172
		{
173
			foreach($product_list[0]->result->results as $pl)
174
			{
175
				if(isset($pl->image_url) and !empty($pl->image_url))
176
				{
177
					$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
178
      				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>';
179
  					if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)){
180
      					$productListResponse .= '<div class="pd-info">
181
        				<div class="pdt-name">'.$pl->title.'</div>
182
       			 		<div class="pdt-price">';
183
       			 		if(isset($pl->price) || isset($pl->mrp)){
184
       			 			$productListResponse .='<span class="pr">Rs</span>';
185
       			 			if(isset($pl->mrp) && $pl->mrp != 0){
186
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
187
       			 			}
188
       			 			if(isset($pl->price) && $pl->price != 0){
189
       			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
190
       			 			}		
191
       			 			$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';		
192
       			 		} 
193
   			 		} else {
194
   			 			$productListResponse .= '<div class="pd-info">
195
        				<div class="pdt-name">'.$pl->title.'</div>
196
       			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
197
       			 		if(isset($pl->price) || isset($pl->mrp)){
198
       			 			$productListResponse .='<span class="pr">Rs</span>';
199
       			 			if(isset($pl->mrp) && $pl->mrp != 0){
200
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
201
       			 			}
202
       			 			if(isset($pl->price) && $pl->price != 0){
203
       			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
204
       			 			}	
205
       			 		}
206
						if(isset($pl->dealprice) && $pl->dealprice != 0){
207
							$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>';
208
						}			
209
       			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
210
           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
211
           			 	}
212
						$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
213
 
214
						if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
215
							$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
216
						}
217
 
218
       			 		$productListResponse .= '</div></a>';
219
   			 		}       			 		
220
				}		
221
 
222
			}
223
		}
224
		echo $productListResponse;
225
 
226
	}
227
	public function getSpecialProductList($category,$page=null){
228
		if(isset($category) && !empty($category)){
229
			$authorized=$this->session->userdata('authorized');
230
			if($category == 'coming-soon'){
231
				$url = $this->config->item('coming_soon');
232
			}
233
			$url = $url['url'];
234
         	$url = $this->config->item('curl_base_url').$url.'/'.$page;
235
         	$params = array();
236
         	if($authorized['Id'] > 0){
237
				$url .= '&userId='.$authorized['Id'].'&isLoggedIn=true';
238
			}
239
			if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
240
				$url .= '&privateDealUser=true';
241
			}
242
         	$this->mcurl->add_call('appendlist','get',$url,$params);
243
         	$response = $this->mcurl->execute($url);
244
         	$data['response'] = $response['appendlist']['response'];
245
		 	$response = $this->magento_model->coming_soon($data);
246
		 	$count = $response[0]->response->count;
247
			$productListResponse ='';
248
			$count = $count-20;
249
			$TotalPage = ceil($count/10);
250
			if($TotalPage < $page) {$coming_soon='';}
251
			 else{$coming_soon = $response;}
252
			 	if(isset($coming_soon) and !empty($coming_soon))
253
			{
254
				foreach($coming_soon[0]->response->items as $pl)
255
				{
256
					if(isset($pl->image_url) and !empty($pl->image_url))
257
					{
258
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
259
          				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>';
260
      					if(!isset($authorized['isPrivateDealUser']) || !isset($pl->dealprice)){
261
          					$productListResponse .= '<div class="pd-info">
262
            				<div class="pdt-name">'.$pl->title.'</div>
263
           			 		<div class="pdt-price">';
264
           			 		if(isset($pl->price) || isset($pl->mrp)){
265
           			 			$productListResponse .='<span class="pr">Rs</span>';
266
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
267
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
268
           			 			}
269
           			 			if(isset($pl->price) && $pl->price != 0){
270
           			 				$productListResponse .='<span class="pr-original">'.$pl->price.'</span>';
271
           			 			}			
272
           			 		}
273
           			 		$productListResponse .='</div><div class="pdt-spec">'. $pl->description.' </div></div></a>';	
274
						}else{
275
							$productListResponse .= '<div class="pd-info">
276
            				<div class="pdt-name">'.$pl->title.'</div>
277
           			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
278
           			 		if(isset($pl->price) || isset($pl->mrp)){
279
           			 			$productListResponse .='<span class="pr">Rs</span>';
280
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
281
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
282
           			 			}
283
           			 			if(isset($pl->price) && $pl->price != 0){
284
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
285
           			 			}	
286
           			 		}
287
							if(isset($pl->dealprice) && $pl->dealprice != 0){
288
								$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>';
289
							}			
290
           			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
291
	           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
292
	           			 	}
293
							$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
294
 
295
							if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
296
								$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
297
							}
298
 
299
           			 		$productListResponse .= '</div></a>';
300
						}
301
					}				
302
 
303
				}
304
			}
305
			echo $productListResponse;
306
			}
307
	}
308
 
309
	public function filter(){
310
		$configdata = $this->config->item('filter');
311
		$data['response']=$this->product_model->getProducts($this->input->get(),$this->input->post(),$configdata);
312
		$this->layout->view('products/products_view',$data);
313
	}
314
 
315
 
316
}
317
 
318
/* End of file welcome.php */
319
/* Location: ./application/controllers/welcome.php */