Subversion Repositories SmartDukaan

Rev

Rev 12624 | Rev 16620 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12624 Rev 16609
Line 1... Line 1...
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
2
 
3
class Productinfo extends MY_Controller {
3
class Productinfo extends MY_Controller {
4
 
4
 
5
public $layoutName ='';
5
public $layoutName ='';
6
	
6
	
7
	function __construct() {
7
	function __construct() {
8
 
8
 
9
		// Call the CI_controller constructor
9
		// Call the CI_controller constructor
10
		parent::__construct();
10
		parent::__construct();
11
		// $admin = $this->session->userdata('admin');
11
		// $admin = $this->session->userdata('admin');
12
		// if(!isset($admin) || empty($admin)) {
12
		// if(!isset($admin) || empty($admin)) {
13
		// 	redirect(base_url().'authorize');
13
		// 	redirect(base_url().'authorize');
14
		// }
14
		// }
15
		$this->layout->setlayout('layout/layout_main');
15
		$this->layout->setlayout('layout/layout_main');
16
		$this->load->model('productinfo_model');
16
		$this->load->model('productinfo_model');
17
		$this->layoutName= $this->layout->getLayout();
17
		$this->layoutName= $this->layout->getLayout();
18
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
18
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
19
		
19
		
20
		
20
		
21
 
21
 
22
	}
22
	}
23
	public function index()
23
	public function index()
24
	{
24
	{
25
		$authorized=$this->session->userdata('authorized');
25
		$authorized=$this->session->userdata('authorized');
26
		//standard array
26
		//standard array
27
		$data = array();
27
		$data = array();
28
		//get cache 
28
		//get cache 
29
		$configdata =array();
29
		$configdata =array();
30
		$configdata = $this->config->item('productinfo');
30
		$configdata = $this->config->item('productinfo');
31
		$cachemodule = array('header','footer');
31
		$cachemodule = array('header','footer');
32
		$configdata = getCache($configdata,$cachemodule);
32
		$configdata = getCache($configdata,$cachemodule);
33
		//end of get cache
33
		//end of get cache
34
		//echo $this->uri->segment(2);
34
		//echo $this->uri->segment(2);
35
		$last = $this->uri->total_segments();
35
		$last = $this->uri->total_segments();
36
		$itemcode = $this->uri->segment($last);
36
		$itemcode = $this->uri->segment($last);
37
		$originalCode = $itemcode;
37
		$originalCode = $itemcode;
38
		if (strpos($itemcode,'-') !== false) {
38
		if (strpos($itemcode,'-') !== false) {
39
		    $itemcode = explode('-', $itemcode);
39
		    $itemcode = explode('-', $itemcode);
40
			$itemcode = end($itemcode);
40
			$itemcode = end($itemcode);
41
		}
41
		}
42
		//print_r($itemcode);
42
		//print_r($itemcode);
43
		if(!is_numeric($itemcode)){
43
		if(!is_numeric($itemcode)){
44
			redirect(base_url());
44
			redirect(base_url());
45
		}
45
		}
46
		$productinfo = 'productinfo'.$itemcode;
46
		$productinfo = 'productinfo'.$itemcode;
47
		$cache = getFIleCache($productinfo);
47
		$cache = getFIleCache($productinfo);
48
		if(isset($cache) && !empty($cache)){
48
		if(isset($cache) && !empty($cache)){
49
			$data['response'] = $cache;
49
			$data['response'] = $cache;
50
		}else{
50
		}else{
51
			$data['response']=$this->productinfo_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$itemcode);
51
			$data['response']=$this->productinfo_model->getProducts($this->input->get(),$this->input->post(),$configdata['module'],$itemcode);
52
			if(isset($data['response']['response']['product_details']) && !empty($data['response']['response']['product_details']))
52
			if(isset($data['response']['response']['product_details']) && !empty($data['response']['response']['product_details']))
53
			setFileCache($data['response'], $productinfo,60);
53
			setFileCache($data['response'], $productinfo,300);
54
		}
54
		}
55
		$entity = $data['response']['response']['product_details'][0]->entity;
55
		$entity = $data['response']['response']['product_details'][0]->entity;
56
		if(!isset($entity)) {
56
		if(!isset($entity)) {
57
			redirect(base_url());
57
			redirect(base_url());
58
		}elseif(isset($entity) && !empty($entity)){
58
		}elseif(isset($entity) && !empty($entity)){
59
			$id = $data['response']['response']['product_details'][0]->entity->id;
59
			$id = $data['response']['response']['product_details'][0]->entity->id;
60
			$items = $data['response']['response']['product_details'][0]->entity->items;
60
			$items = $data['response']['response']['product_details'][0]->entity->items;
61
			$i=0;
61
			$i=0;
62
			foreach ($items as $item) {
62
			foreach ($items as $item) {
63
				if(isset($item->sellingPrice) && !empty($item->sellingPrice)){
63
				if(isset($item->sellingPrice) && !empty($item->sellingPrice)){
64
					$sellingPrice = $item->sellingPrice;
64
					$sellingPrice = $item->sellingPrice;
65
				}
65
				}
66
				if(isset($item->mrp) && $item->mrp != 0){
66
				if(isset($item->mrp) && $item->mrp != 0){
67
					$mrp = $item->mrp;
67
					$mrp = $item->mrp;
68
					$discount = (($mrp - $sellingPrice)/$mrp);
68
					$discount = (($mrp - $sellingPrice)/$mrp);
69
	    			$discount = round($discount*100);
69
	    			$discount = round($discount*100);
70
	    			$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
70
	    			$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
71
				}
71
				}
72
				if(isset($item->dealPojo) && !empty($authorized['isPrivateDealUser'])) {
72
				if(isset($item->dealPojo) && !empty($authorized['isPrivateDealUser'])) {
73
					$mrp = $item->mrp;
73
					$mrp = $item->mrp;
74
					$discount = (($mrp - $item->dealPojo->dealPrice)/$mrp);
74
					$discount = (($mrp - $item->dealPojo->dealPrice)/$mrp);
75
					$discount = round($discount*100);
75
					$discount = round($discount*100);
76
					$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
76
					$data['response']['response']['product_details'][0]->entity->items[$i]->discount = $discount;
77
					$data['response']['response']['product_details'][0]->entity->items[$i]->dealPrice = $item->dealPojo->dealPrice;
77
					$data['response']['response']['product_details'][0]->entity->items[$i]->dealPrice = $item->dealPojo->dealPrice;
78
					$data['response']['response']['product_details'][0]->entity->items[$i]->dealText = $item->dealPojo->dealText;
78
					$data['response']['response']['product_details'][0]->entity->items[$i]->dealText = $item->dealPojo->dealText;
79
				}
79
				}
80
	    			$i++;
80
	    			$i++;
81
			}
81
			}
82
			if(!isset($id) || empty($id)){
82
			if(!isset($id) || empty($id)){
83
				redirect(base_url());
83
				redirect(base_url());
84
			}
84
			}
85
			$name = str_replace(' ', '-', $data['response']['response']['product_details'][0]->entity->name);
85
			$name = str_replace(' ', '-', $data['response']['response']['product_details'][0]->entity->name);
86
			$apiCode = strtolower($name.'-'.$id);
86
			$apiCode = strtolower($name.'-'.$id);
87
			$apicode = str_replace('-','',$apiCode);
87
			$apicode = str_replace('-','',$apiCode);
88
			$originalCode = str_replace('-','',$originalCode);
88
			$originalCode = str_replace('-','',$originalCode);
89
			//echo $originalCode;
89
			//echo $originalCode;
90
			if($itemcode == $id){
90
			if($itemcode == $id){
91
				//set cache to output or renew cache
91
				//set cache to output or renew cache
92
				if(isset($cachemodule) and !empty($cachemodule))
92
				if(isset($cachemodule) and !empty($cachemodule))
93
				{
93
				{
94
					foreach($cachemodule as $cm)
94
					foreach($cachemodule as $cm)
95
					{
95
					{
96
						if(isset($configdata[$cm]) and !empty($configdata[$cm]))
96
						if(isset($configdata[$cm]) and !empty($configdata[$cm]))
97
						{
97
						{
98
							$data['response'][$cm]=$configdata[$cm];
98
							$data['response'][$cm]=$configdata[$cm];
99
						}
99
						}
100
					}
100
					}
101
				}
101
				}
102
				setCache($configdata['module'],$cachemodule,$data['response']);
102
				setCache($configdata['module'],$cachemodule,$data['response']);
103
				$this->lessphp->object()->ccompile('assets/css/pd-detail.less','assets/css/pd-detail.css');
103
				$this->lessphp->object()->ccompile('assets/css/pd-detail.less','assets/css/pd-detail.css');
104
				$data['stylesheet'] = 'pd-detail.css';
104
				$data['stylesheet'] = 'pd-detail.css';
105
				$title = $data['response']['response']['product_details'][0]->entity->title;
105
				$title = $data['response']['response']['product_details'][0]->entity->title;
106
				if(isset($title) && !empty($title)){
106
				if(isset($title) && !empty($title)){
107
					$data['title'] = $title;
107
					$data['title'] = $title;
108
				}
108
				}
109
				$metaDescription = $data['response']['response']['product_details'][0]->entity->metaDescription;
109
				$metaDescription = $data['response']['response']['product_details'][0]->entity->metaDescription;
110
				if(isset($metaDescription) && !empty($metaDescription)){
110
				if(isset($metaDescription) && !empty($metaDescription)){
111
					$data['metaDescription'] = $metaDescription;
111
					$data['metaDescription'] = $metaDescription;
112
				}
112
				}
113
				/*$subView = $this->session->userdata('subView');
113
				/*$subView = $this->session->userdata('subView');
114
				if(isset($subView) && !empty($subView))
114
				if(isset($subView) && !empty($subView))
115
				{
115
				{
116
				    $data['subView'] = $subView;
116
				    $data['subView'] = $subView;
117
				}
117
				}
118
				elseif(mt_rand(1,2) % 2)
118
				elseif(mt_rand(1,2) % 2)
119
				{
119
				{
120
				    $data['subView'] = 'a';
120
				    $data['subView'] = 'a';
121
				    $this->session->set_userdata('subView','a');
121
				    $this->session->set_userdata('subView','a');
122
				}
122
				}
123
				else
123
				else
124
				{
124
				{
125
				    $data['subView'] = 'b';
125
				    $data['subView'] = 'b';
126
				    $this->session->set_userdata('subView','b');
126
				    $this->session->set_userdata('subView','b');
127
				}*/			
127
				}*/			
128
				$data['subView'] = 'b';
128
				//echo print_r($entity->dtrAffiliateJSON);
129
				if(!empty($entity->exclusiveAffiliateInfo[0])) {
129
				$data['subView'] = 'b';
130
					$data['subView'] = 'c';
130
				if(!empty($entity->exclusiveAffiliateInfo[0])) {
131
				}
131
					$data['subView'] = 'c';
132
				//end of set cache
132
				}elseif(!empty($entity->dtrAffiliateJSON) && !empty($entity->dtrAffiliateJSON->map->products)){
133
				$this->layout->view('productinfo/productinfo_view',$data);
133
					$data['subView'] = 'd';
134
			}
134
				}
135
			else{
135
				$this->layout->view('productinfo/productinfo_view',$data);
136
				$url = base_url().strtolower(get_class()).'/'.$apiCode;
136
			}
137
				redirect($url);
137
			else{
138
			}
138
				$url = base_url().strtolower(get_class()).'/'.$apiCode;
139
		}
139
				redirect($url);
140
		
140
			}
141
	}
141
		}
142
 
142
		
143
	function getDeliveryDetails($itemId,$pinCode){
143
	}
144
 
144
	
145
		$url = $this->config->item('estimate_delivery');
145
	function clicks(){
146
		$url = $url['url'];
146
		$url = $this->config->item('curl_base_url').'/clicks';
147
        $url = $this->config->item('curl_base_url').$url;	
147
		$params = array();
148
        $params = array();
148
		$params['source_id'] = $this->input->get('source_id');
149
        $params['itemId'] = $itemId;
149
		$params['url'] = $this->input->get('click_url');
150
        $params['pinCode'] = $pinCode;	
150
		$this->mcurl->add_call('clicks','get',$url,$params);
151
        $this->mcurl->add_call('delivery','get',$url,$params);
151
        $response = $this->mcurl->execute($url);
152
        $response = $this->mcurl->execute($url);
152
		echo ($response['clicks']['response']);
153
        $data['response'] = $response['delivery']['response'];
153
	}
154
        echo($data['response']);
154
 
155
	}
155
	function getDeliveryDetails($itemId,$pinCode){
156
 
156
 
157
	function removeStuff($string) {
157
		$url = $this->config->item('estimate_delivery');
158
    	return preg_replace('/[^a-zA-Z0-9]/', '', $string);
158
		$url = $url['url'];
159
	}
159
        $url = $this->config->item('curl_base_url').$url;	
160
}
160
        $params = array();
161
 
161
        $params['itemId'] = $itemId;
162
/* End of file welcome.php */
162
        $params['pinCode'] = $pinCode;	
163
/* Location: ./application/controllers/welcome.php */
163
        $this->mcurl->add_call('delivery','get',$url,$params);
-
 
164
        $response = $this->mcurl->execute($url);
-
 
165
        $data['response'] = $response['delivery']['response'];
-
 
166
        echo($data['response']);
-
 
167
	}
-
 
168
 
-
 
169
	function removeStuff($string) {
-
 
170
    	return preg_replace('/[^a-zA-Z0-9]/', '', $string);
-
 
171
	}
-
 
172
}
-
 
173
 
-
 
174
/* End of file welcome.php */
-
 
175
/* Location: ./application/controllers/welcome.php */