Subversion Repositories SmartDukaan

Rev

Rev 10907 | Rev 11532 | 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 Productinfo extends MY_Controller {
4
 
5
public $layoutName ='';
6
 
7
	function __construct() {
8
 
9
		// Call the CI_controller constructor
10
		parent::__construct();
11108 lgm 11
		// $admin = $this->session->userdata('admin');
12
		// if(!isset($admin) || empty($admin)) {
13
		// 	redirect(base_url().'authorize');
14
		// }
10582 lgm 15
		$this->layout->setlayout('layout/layout_main');
16
		$this->load->model('productinfo_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
		//standard array
26
		$data = array();
27
		//get cache 
28
		$configdata =array();
29
		$configdata = $this->config->item('productinfo');
30
		$cachemodule = array('header','footer');
31
		$configdata = getCache($configdata,$cachemodule);
32
		//end of get cache
33
		//echo $this->uri->segment(2);
34
		$last = $this->uri->total_segments();
35
		$itemcode = $this->uri->segment($last);
36
		$originalCode = $itemcode;
37
		if (strpos($itemcode,'-') !== false) {
38
		    $itemcode = explode('-', $itemcode);
39
			$itemcode = end($itemcode);
40
		}
41
		//print_r($itemcode);
42
		if(!is_numeric($itemcode)){
43
			redirect(base_url());
44
		}
45
		$productinfo = 'productinfo'.$itemcode;
46
		$cache = getFIleCache($productinfo);
47
		if(isset($cache) && !empty($cache)){
48
			$data['response'] = $cache;
49
		}else{
50
			$data['response']=$this->productinfo_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$itemcode);
51
			if(isset($data['response']['response']['product_details']) && !empty($data['response']['response']['product_details']))
52
			setFileCache($data['response'], $productinfo,60);
53
		}
54
		$id = $data['response']['response']['product_details'][0]->entity->id;
55
		$items = $data['response']['response']['product_details'][0]->entity->items;
56
		$i=0;
57
		foreach ($items as $item) {
10691 lgm 58
			if(isset($item->sellingPrice) && !empty($item->sellingPrice)){
59
				$sellingPrice = $item->sellingPrice;
60
			}
61
			if(isset($item->mrp) && $item->mrp != 0){
62
				$mrp = $item->mrp;
10582 lgm 63
				$discount = (($mrp - $sellingPrice)/$mrp);
64
    			$discount = round($discount*100);
65
    			$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
66
    			$i++;
67
			}
68
		}
69
		if(!isset($id) || empty($id)){
70
			redirect(base_url());
71
		}
10907 lgm 72
		$name = str_replace(' ', '-', $data['response']['response']['product_details'][0]->entity->name);
73
		$apiCode = strtolower($name.'-'.$id);
10582 lgm 74
		$apicode = str_replace('-','',$apiCode);
75
		$originalCode = str_replace('-','',$originalCode);
76
		//echo $originalCode;
77
		if($itemcode == $id){
78
			//set cache to output or renew cache
79
			if(isset($cachemodule) and !empty($cachemodule))
80
			{
81
				foreach($cachemodule as $cm)
82
				{
83
					if(isset($configdata[$cm]) and !empty($configdata[$cm]))
84
					{
85
						$data['response'][$cm]=$configdata[$cm];
86
					}
87
				}
88
			}
89
			setCache($configdata['module'],$cachemodule,$data['response']);
90
			$this->lessphp->object()->ccompile('assets/css/pd-detail.less','assets/css/pd-detail.css');
91
			$data['stylesheet'] = 'pd-detail.css';
10907 lgm 92
			$title = $data['response']['response']['product_details'][0]->entity->title;
93
			if(isset($title) && !empty($title)){
94
				$data['title'] = $title;
95
			}
96
			$metaDescription = $data['response']['response']['product_details'][0]->entity->metaDescription;
97
			if(isset($metaDescription) && !empty($metaDescription)){
98
				$data['metaDescription'] = $metaDescription;
99
			}
10582 lgm 100
			//end of set cache
101
			$this->layout->view('productinfo/productinfo_view',$data);
102
		}
103
		else{
104
			$url = base_url().strtolower(get_class()).'/'.$apiCode;
105
			redirect($url);
106
		}
107
 
108
	}
109
 
110
	function getDeliveryDetails($itemId,$pinCode){
111
 
112
		$url = $this->config->item('estimate_delivery');
113
		$url = $url['url'];
114
        $url = $this->config->item('curl_base_url').$url;	
115
        $params = array();
116
        $params['itemId'] = $itemId;
117
        $params['pinCode'] = $pinCode;	
118
        $this->mcurl->add_call('delivery','get',$url,$params);
119
        $response = $this->mcurl->execute($url);
120
        $data['response'] = $response['delivery']['response'];
121
        echo($data['response']);
122
	}
123
 
124
	function removeStuff($string) {
125
    	return preg_replace('/[^a-zA-Z0-9]/', '', $string);
126
	}
127
}
128
 
129
/* End of file welcome.php */
130
/* Location: ./application/controllers/welcome.php */