Subversion Repositories SmartDukaan

Rev

Rev 16728 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16609 amit.gupta 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
		$authorized=$this->session->userdata('authorized');
26
		//standard array
27
		$data = array();
28
		//get cache 
29
		$configdata =array();
30
		$configdata = $this->config->item('productinfo');
31
		$cachemodule = array('header','footer');
32
		$configdata = getCache($configdata,$cachemodule);
33
		//end of get cache
34
		//echo $this->uri->segment(2);
35
		$last = $this->uri->total_segments();
36
		$itemcode = $this->uri->segment($last);
37
		$originalCode = $itemcode;
38
		if (strpos($itemcode,'-') !== false) {
39
		    $itemcode = explode('-', $itemcode);
40
			$itemcode = end($itemcode);
41
		}
42
		//print_r($itemcode);
43
		if(!is_numeric($itemcode)){
44
			redirect(base_url());
45
		}
46
		$productinfo = 'productinfo'.$itemcode;
20496 amit.gupta 47
		log_message('debug', "File cache called");
48
		$cache = getFileCache($productinfo);
16609 amit.gupta 49
		if(isset($cache) && !empty($cache)){
50
			$data['response'] = $cache;
51
		}else{
52
			$data['response']=$this->productinfo_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$itemcode);
53
			if(isset($data['response']['response']['product_details']) && !empty($data['response']['response']['product_details']))
54
			setFileCache($data['response'], $productinfo,300);
55
		}
56
		$entity = $data['response']['response']['product_details'][0]->entity;
57
		if(!isset($entity)) {
58
			redirect(base_url());
59
		}elseif(isset($entity) && !empty($entity)){
60
			$id = $data['response']['response']['product_details'][0]->entity->id;
61
			$items = $data['response']['response']['product_details'][0]->entity->items;
62
			$i=0;
63
			foreach ($items as $item) {
64
				if(isset($item->sellingPrice) && !empty($item->sellingPrice)){
65
					$sellingPrice = $item->sellingPrice;
66
				}
67
				if(isset($item->mrp) && $item->mrp != 0){
68
					$mrp = $item->mrp;
69
					$discount = (($mrp - $sellingPrice)/$mrp);
70
	    			$discount = round($discount*100);
71
	    			$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
72
				}
73
				if(isset($item->dealPojo) && !empty($authorized['isPrivateDealUser'])) {
74
					$mrp = $item->mrp;
75
					$discount = (($mrp - $item->dealPojo->dealPrice)/$mrp);
76
					$discount = round($discount*100);
77
					$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
78
					$data['response']['response']['product_details'][0]->entity->items[$i]->dealPrice = $item->dealPojo->dealPrice;
79
					$data['response']['response']['product_details'][0]->entity->items[$i]->dealText = $item->dealPojo->dealText;
80
				}
81
	    			$i++;
82
			}
83
			if(!isset($id) || empty($id)){
84
				redirect(base_url());
85
			}
86
			$name = str_replace(' ', '-', $data['response']['response']['product_details'][0]->entity->name);
87
			$apiCode = strtolower($name.'-'.$id);
88
			$apicode = str_replace('-','',$apiCode);
89
			$originalCode = str_replace('-','',$originalCode);
90
			//echo $originalCode;
91
			if($itemcode == $id){
92
				//set cache to output or renew cache
93
				if(isset($cachemodule) and !empty($cachemodule))
94
				{
95
					foreach($cachemodule as $cm)
96
					{
97
						if(isset($configdata[$cm]) and !empty($configdata[$cm]))
98
						{
99
							$data['response'][$cm]=$configdata[$cm];
100
						}
101
					}
102
				}
103
				setCache($configdata['module'],$cachemodule,$data['response']);
104
				$this->lessphp->object()->ccompile('assets/css/pd-detail.less','assets/css/pd-detail.css');
105
				$data['stylesheet'] = 'pd-detail.css';
106
				$title = $data['response']['response']['product_details'][0]->entity->title;
107
				if(isset($title) && !empty($title)){
108
					$data['title'] = $title;
109
				}
110
				$metaDescription = $data['response']['response']['product_details'][0]->entity->metaDescription;
111
				if(isset($metaDescription) && !empty($metaDescription)){
112
					$data['metaDescription'] = $metaDescription;
113
				}
114
				$data['subView'] = 'b';
115
				if(!empty($entity->exclusiveAffiliateInfo[0])) {
116
					$data['subView'] = 'c';
16620 amit.gupta 117
				}elseif(!empty($entity->dtrAffiliateJSON) && !empty($entity->dtrAffiliateJSON->map->products) && !empty($entity->dtrAffiliateJSON->map->products->myArrayList)){
16609 amit.gupta 118
					$data['subView'] = 'd';
119
				}
120
				$this->layout->view('productinfo/productinfo_view',$data);
121
			}
122
			else{
123
				$url = base_url().strtolower(get_class()).'/'.$apiCode;
124
				redirect($url);
125
			}
126
		}
127
 
128
	}
129
 
130
	function clicks(){
16652 amit.gupta 131
		$authorized = $this->session->userdata('authorized');
132
		$userId = -1;
16728 amit.gupta 133
		$isLoggedIn = "false";
16652 amit.gupta 134
		if(isset($authorized) && $authorized['isLoggedIn'] == 1){
135
			$userId = $authorized['Id'];
16728 amit.gupta 136
			$isLoggedIn = "true";
16652 amit.gupta 137
		}
16609 amit.gupta 138
		$url = $this->config->item('curl_base_url').'/clicks';
139
		$params = array();
140
		$params['source_id'] = $this->input->get('source_id');
141
		$params['url'] = $this->input->get('click_url');
16668 amit.gupta 142
		$params['isLoggedIn'] = $isLoggedIn;
143
		$params['userId'] = $userId;
16609 amit.gupta 144
		$this->mcurl->add_call('clicks','get',$url,$params);
145
        $response = $this->mcurl->execute($url);
146
		echo ($response['clicks']['response']);
147
	}
148
 
149
	function getDeliveryDetails($itemId,$pinCode){
150
 
151
		$url = $this->config->item('estimate_delivery');
152
		$url = $url['url'];
153
        $url = $this->config->item('curl_base_url').$url;	
154
        $params = array();
155
        $params['itemId'] = $itemId;
156
        $params['pinCode'] = $pinCode;	
157
        $this->mcurl->add_call('delivery','get',$url,$params);
158
        $response = $this->mcurl->execute($url);
159
        $data['response'] = $response['delivery']['response'];
160
        echo($data['response']);
161
	}
162
 
163
	function removeStuff($string) {
164
    	return preg_replace('/[^a-zA-Z0-9]/', '', $string);
165
	}
166
}
167
 
168
/* End of file welcome.php */
169
/* Location: ./application/controllers/welcome.php */