Subversion Repositories SmartDukaan

Rev

Rev 10691 | Go to most recent revision | Details | 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();
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('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) {
58
			$sellingPrice = $item->sellingPrice;
59
			$mrp = $item->mrp;
60
			if(isset($mrp) && $mrp != 0){
61
				$discount = (($mrp - $sellingPrice)/$mrp);
62
    			$discount = round($discount*100);
63
    			$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
64
    			$i++;
65
			}
66
		}
67
		if(!isset($id) || empty($id)){
68
			redirect(base_url());
69
		}
70
		$title = str_replace(' ', '-', $data['response']['response']['product_details'][0]->entity->title);
71
		$apiCode = strtolower($title.'-'.$id);
72
		$apicode = str_replace('-','',$apiCode);
73
		$originalCode = str_replace('-','',$originalCode);
74
		//echo $originalCode;
75
		if($itemcode == $id){
76
			//set cache to output or renew cache
77
			if(isset($cachemodule) and !empty($cachemodule))
78
			{
79
				foreach($cachemodule as $cm)
80
				{
81
					if(isset($configdata[$cm]) and !empty($configdata[$cm]))
82
					{
83
						$data['response'][$cm]=$configdata[$cm];
84
					}
85
				}
86
			}
87
			setCache($configdata['module'],$cachemodule,$data['response']);
88
			$this->lessphp->object()->ccompile('assets/css/pd-detail.less','assets/css/pd-detail.css');
89
			$data['stylesheet'] = 'pd-detail.css';
90
			//end of set cache
91
			$this->layout->view('productinfo/productinfo_view',$data);
92
		}
93
		else{
94
			$url = base_url().strtolower(get_class()).'/'.$apiCode;
95
			redirect($url);
96
		}
97
 
98
	}
99
 
100
	function getDeliveryDetails($itemId,$pinCode){
101
 
102
		$url = $this->config->item('estimate_delivery');
103
		$url = $url['url'];
104
        $url = $this->config->item('curl_base_url').$url;	
105
        $params = array();
106
        $params['itemId'] = $itemId;
107
        $params['pinCode'] = $pinCode;	
108
        $this->mcurl->add_call('delivery','get',$url,$params);
109
        $response = $this->mcurl->execute($url);
110
        $data['response'] = $response['delivery']['response'];
111
        echo($data['response']);
112
	}
113
 
114
	function removeStuff($string) {
115
    	return preg_replace('/[^a-zA-Z0-9]/', '', $string);
116
	}
117
}
118
 
119
/* End of file welcome.php */
120
/* Location: ./application/controllers/welcome.php */