Subversion Repositories SmartDukaan

Rev

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