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