Subversion Repositories SmartDukaan

Rev

Rev 11532 | Rev 12056 | 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
		}
11532 lgm 54
		$entity = $data['response']['response']['product_details'][0]->entity;
55
		if(!isset($entity)) {
56
			redirect(base_url());
57
		}elseif(isset($entity) && !empty($entity)){
58
			$id = $data['response']['response']['product_details'][0]->entity->id;
59
			$items = $data['response']['response']['product_details'][0]->entity->items;
60
			$i=0;
61
			foreach ($items as $item) {
62
				if(isset($item->sellingPrice) && !empty($item->sellingPrice)){
63
					$sellingPrice = $item->sellingPrice;
64
				}
65
				if(isset($item->mrp) && $item->mrp != 0){
66
					$mrp = $item->mrp;
67
					$discount = (($mrp - $sellingPrice)/$mrp);
68
	    			$discount = round($discount*100);
69
	    			$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
70
	    			$i++;
71
				}
10691 lgm 72
			}
11532 lgm 73
			if(!isset($id) || empty($id)){
74
				redirect(base_url());
10582 lgm 75
			}
11532 lgm 76
			$name = str_replace(' ', '-', $data['response']['response']['product_details'][0]->entity->name);
77
			$apiCode = strtolower($name.'-'.$id);
78
			$apicode = str_replace('-','',$apiCode);
79
			$originalCode = str_replace('-','',$originalCode);
80
			//echo $originalCode;
81
			if($itemcode == $id){
82
				//set cache to output or renew cache
83
				if(isset($cachemodule) and !empty($cachemodule))
10582 lgm 84
				{
11532 lgm 85
					foreach($cachemodule as $cm)
10582 lgm 86
					{
11532 lgm 87
						if(isset($configdata[$cm]) and !empty($configdata[$cm]))
88
						{
89
							$data['response'][$cm]=$configdata[$cm];
90
						}
10582 lgm 91
					}
92
				}
11532 lgm 93
				setCache($configdata['module'],$cachemodule,$data['response']);
94
				$this->lessphp->object()->ccompile('assets/css/pd-detail.less','assets/css/pd-detail.css');
95
				$data['stylesheet'] = 'pd-detail.css';
96
				$title = $data['response']['response']['product_details'][0]->entity->title;
97
				if(isset($title) && !empty($title)){
98
					$data['title'] = $title;
99
				}
100
				$metaDescription = $data['response']['response']['product_details'][0]->entity->metaDescription;
101
				if(isset($metaDescription) && !empty($metaDescription)){
102
					$data['metaDescription'] = $metaDescription;
103
				}
11752 lgm 104
				$subView = $this->session->userdata('subView');
105
				if(isset($subView) && !empty($subView))
106
				{
107
				    $data['subView'] = $subView;
108
				}
109
				elseif(mt_rand(1,2) % 2)
110
				{
111
				    $data['subView'] = 'a';
112
				    $this->session->set_userdata('subView','a');
113
				}
114
				else
115
				{
116
				    $data['subView'] = 'b';
117
				    $this->session->set_userdata('subView','b');
118
				}
11532 lgm 119
				//end of set cache
120
				$this->layout->view('productinfo/productinfo_view',$data);
10582 lgm 121
			}
11532 lgm 122
			else{
123
				$url = base_url().strtolower(get_class()).'/'.$apiCode;
124
				redirect($url);
10907 lgm 125
			}
10582 lgm 126
		}
127
 
128
	}
129
 
130
	function getDeliveryDetails($itemId,$pinCode){
131
 
132
		$url = $this->config->item('estimate_delivery');
133
		$url = $url['url'];
134
        $url = $this->config->item('curl_base_url').$url;	
135
        $params = array();
136
        $params['itemId'] = $itemId;
137
        $params['pinCode'] = $pinCode;	
138
        $this->mcurl->add_call('delivery','get',$url,$params);
139
        $response = $this->mcurl->execute($url);
140
        $data['response'] = $response['delivery']['response'];
141
        echo($data['response']);
142
	}
143
 
144
	function removeStuff($string) {
145
    	return preg_replace('/[^a-zA-Z0-9]/', '', $string);
146
	}
147
}
148
 
149
/* End of file welcome.php */
150
/* Location: ./application/controllers/welcome.php */