Subversion Repositories SmartDukaan

Rev

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