| 12694 |
anikendra |
1 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
2 |
|
|
|
3 |
class Cart 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->output->set_header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
|
|
|
16 |
$this->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
|
|
17 |
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
|
|
18 |
$this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
|
|
|
19 |
$this->output->set_header("Pragma: no-cache");
|
|
|
20 |
$this->layout->setlayout('layout/layout_main');
|
|
|
21 |
$this->load->model('cart_model');
|
|
|
22 |
$this->layoutName= $this->layout->getLayout();
|
|
|
23 |
$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
|
|
|
24 |
//print_r($this->session->userdata);
|
|
|
25 |
|
|
|
26 |
}
|
|
|
27 |
public function index()
|
|
|
28 |
{
|
|
|
29 |
$authorized = $this->session->userdata('authorized');
|
|
|
30 |
//standard array
|
|
|
31 |
$configdata = $this->config->item('cart');
|
|
|
32 |
$cachemodule = array('header','footer');
|
|
|
33 |
$configdata = getCache($configdata,$cachemodule);
|
|
|
34 |
$data = array();
|
|
|
35 |
if(isset($authorized) && !empty($authorized)){
|
|
|
36 |
$_GET['userId'] = $authorized['Id'];
|
|
|
37 |
$_GET['Id'] = $authorized['cartId'];
|
|
|
38 |
if(isset($authorized['isPrivateDealUser']) && !empty($authorized['isPrivateDealUser'])) {
|
|
|
39 |
$_GET['privateDealUser'] = 'true';
|
|
|
40 |
}
|
|
|
41 |
$isAutoApplicationOff = $this->session->userdata('isAutoApplicationOff');
|
|
|
42 |
$_GET['autoApplicationOff'] = 'false';
|
|
|
43 |
if(isset($isAutoApplicationOff) && !empty($isAutoApplicationOff)) {
|
|
|
44 |
$_GET['autoApplicationOff'] = 'true';
|
|
|
45 |
}
|
|
|
46 |
if($authorized['isLoggedIn'] == 1){
|
|
|
47 |
$_GET['isLoggedIn'] = 'true';
|
|
|
48 |
}
|
|
|
49 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
50 |
$_GET['isLoggedIn'] = 'false';
|
|
|
51 |
}
|
|
|
52 |
unset($configdata['module']['response'][0]);
|
|
|
53 |
$data['response']=$this->cart_model->getCart($this->input->get(),$this->input->post(),$configdata['module']);
|
|
|
54 |
if(isset($data['response']['response']['carts'][0]->lines))
|
|
|
55 |
$cartCount = sizeof($data['response']['response']['carts'][0]->lines);
|
|
|
56 |
$authorized = $this->session->userdata('authorized');
|
|
|
57 |
if(isset($authorized) && !empty($authorized)){
|
|
|
58 |
$newValues = $authorized;
|
|
|
59 |
$newValues['totalItems'] = $cartCount;
|
|
|
60 |
$this->session->set_userdata('authorized',$newValues);
|
|
|
61 |
}
|
|
|
62 |
$this->lessphp->object()->ccompile('assets/css/cart.less','assets/css/cart.css');
|
|
|
63 |
$data['stylesheet'] = 'cart.css';
|
|
|
64 |
if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
|
|
|
65 |
{
|
|
|
66 |
foreach($cachemodule as $cm)
|
|
|
67 |
{
|
|
|
68 |
if(isset($configdata[$cm]) and !empty($configdata[$cm]))
|
|
|
69 |
{
|
|
|
70 |
$data['response'][$cm]=$configdata[$cm];
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
setCache($configdata['module'],$cachemodule,$data['response']);
|
|
|
75 |
$this->layout->view('cart/cart_view',$data);
|
|
|
76 |
}else{
|
|
|
77 |
unset($configdata['module']['response'][1]);
|
|
|
78 |
$data['response']=$this->cart_model->getCart($this->input->get(),$this->input->post(),$configdata['module']);
|
|
|
79 |
$this->lessphp->object()->ccompile('assets/css/cart.less','assets/css/cart.css');
|
|
|
80 |
$data['stylesheet'] = 'cart.css';
|
|
|
81 |
if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
|
|
|
82 |
{
|
|
|
83 |
foreach($cachemodule as $cm)
|
|
|
84 |
{
|
|
|
85 |
if(isset($configdata[$cm]) and !empty($configdata[$cm]))
|
|
|
86 |
{
|
|
|
87 |
$data['response'][$cm]=$configdata[$cm];
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
setCache($configdata['module'],$cachemodule,$data['response']);
|
|
|
92 |
$this->layout->view('cart/carts',$data);
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
public function add($id=null,$email=null,$itemname)
|
|
|
98 |
{
|
|
|
99 |
$response=array();
|
|
|
100 |
|
|
|
101 |
$authorized = $this->session->userdata('authorized');
|
|
|
102 |
$isAutoApplicationOff = $this->session->userdata('isAutoApplicationOff');
|
|
|
103 |
|
|
|
104 |
if(isset($id) and !empty($id) and is_numeric($id))
|
|
|
105 |
{
|
|
|
106 |
//if user logged-in
|
|
|
107 |
$_POST['itemId'] = $id;
|
|
|
108 |
}
|
|
|
109 |
else{
|
|
|
110 |
redirect(base_url());
|
|
|
111 |
}
|
|
|
112 |
if(isset($authorized) && !empty($authorized)){
|
|
|
113 |
$_POST['userId'] = $authorized['Id'];
|
|
|
114 |
$_POST['Id'] = $authorized['cartId'];
|
|
|
115 |
|
|
|
116 |
if($authorized['isLoggedIn'] == 1){
|
|
|
117 |
$_POST['isLoggedIn'] = 'true';
|
|
|
118 |
}
|
|
|
119 |
elseif((isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn']))) {
|
|
|
120 |
$_POST['isLoggedIn'] = 'false';
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
else{
|
|
|
124 |
$response = $this->anonymous();
|
|
|
125 |
if(isset($response['authorized']) && !empty($response['authorized'])){
|
|
|
126 |
$authorized = $response['authorized'];
|
|
|
127 |
$_POST['userId'] = $authorized['Id'];
|
|
|
128 |
$_POST['Id'] = $authorized['cartId'];
|
|
|
129 |
if(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])){
|
|
|
130 |
$_POST['isLoggedIn'] = 'false';
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
if(isset($email) && $email != 'null'){
|
|
|
135 |
$_POST['email'] = $email;
|
|
|
136 |
}
|
|
|
137 |
$response=$this->cart_model->getCart($this->input->get(),$this->input->post(),$this->config->item('cart_add'));
|
|
|
138 |
if(isset($response['response']['addcart'][0]->message) && !empty($response['response']['addcart'][0]->message)){
|
|
|
139 |
if(isset($itemname) && $itemname != 'null'){
|
|
|
140 |
if(!isset($email) || $email == 'null'){
|
|
|
141 |
$productinfo = 'productinfo'.$itemname;
|
|
|
142 |
deleteFileCache($productinfo);
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
echo json_encode($response['response']);
|
|
|
146 |
}
|
|
|
147 |
elseif(isset($response['response']['addcart'][0]->redirectUrl) && $response['response']['addcart'][0]->redirectUrl == 'cart'){
|
|
|
148 |
$authorized = $this->session->userdata('authorized');
|
|
|
149 |
if(isset($authorized) && !empty($authorized)){
|
|
|
150 |
$cartCount = $authorized['totalItems'];
|
|
|
151 |
$newValues = $authorized;
|
|
|
152 |
$newValues['totalItems'] = $cartCount+1;
|
|
|
153 |
$this->session->set_userdata('authorized',$newValues);
|
|
|
154 |
}
|
|
|
155 |
echo json_encode($response['response']);
|
|
|
156 |
//redirect(base_url().strtolower(__CLASS__),'refresh');
|
|
|
157 |
}elseif(isset($response['response']['addcart'][0]->redirectUrl) && $response['response']['addcart'][0]->redirectUrl != 'cart'){
|
|
|
158 |
echo json_encode($response['response']);
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
public function update($id=null,$qty=null)
|
|
|
162 |
{
|
|
|
163 |
$response=array();
|
|
|
164 |
$authorized = $this->session->userdata('authorized');
|
|
|
165 |
if(isset($id) and !empty($id))
|
|
|
166 |
{
|
|
|
167 |
//if user logged-in
|
|
|
168 |
$_POST['itemId'] = $id;
|
|
|
169 |
}
|
|
|
170 |
if(isset($qty) and !empty($qty))
|
|
|
171 |
{
|
|
|
172 |
//if user logged-in
|
|
|
173 |
$_POST['quantity'] = $qty;
|
|
|
174 |
}
|
|
|
175 |
if(isset($authorized) && !empty($authorized)){
|
|
|
176 |
$_POST['userId'] = $authorized['Id'];
|
|
|
177 |
$_POST['_method'] = 'put';
|
|
|
178 |
$cartId = $authorized['cartId'];
|
|
|
179 |
if($authorized['isLoggedIn'] == 1){
|
|
|
180 |
$_POST['isLoggedIn'] = 'true';
|
|
|
181 |
}
|
|
|
182 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
183 |
$_POST['isLoggedIn'] = 'false';
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
$response=$this->cart_model->getCart($this->input->get(),$this->input->post(),$this->config->item('cart_update'),$cartId);
|
|
|
187 |
redirect(base_url().strtolower(__CLASS__));
|
|
|
188 |
|
|
|
189 |
}
|
|
|
190 |
public function delete($id=null)
|
|
|
191 |
{
|
|
|
192 |
|
|
|
193 |
$authorized = $this->session->userdata('authorized');
|
|
|
194 |
if(isset($id) and !empty($id) and is_numeric($id))
|
|
|
195 |
{
|
|
|
196 |
//if user logged-in
|
|
|
197 |
$_POST['itemId'] = $id;
|
|
|
198 |
}
|
|
|
199 |
else{
|
|
|
200 |
redirect(base_url());
|
|
|
201 |
}
|
|
|
202 |
if(isset($authorized) && !empty($authorized)){
|
|
|
203 |
$_POST['userId'] = $authorized['Id'];
|
|
|
204 |
$_POST['_method'] = 'delete';
|
|
|
205 |
$cartId = $authorized['cartId'];
|
|
|
206 |
if($authorized['isLoggedIn'] == 1){
|
|
|
207 |
$_POST['isLoggedIn'] = 'true';
|
|
|
208 |
}
|
|
|
209 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
210 |
$_POST['isLoggedIn'] = 'false';
|
|
|
211 |
}
|
|
|
212 |
}
|
|
|
213 |
$response=array();
|
|
|
214 |
if(isset($id) and !empty($id))
|
|
|
215 |
{
|
|
|
216 |
$response=$this->cart_model->getCart($this->input->get(),$this->input->post(),$this->config->item('cart_delete'),$cartId);
|
|
|
217 |
if(isset($response['response']['deletecart'][0]->lines)) {
|
|
|
218 |
$cartCount = sizeof($response['response']['deletecart'][0]->lines);
|
|
|
219 |
$authorized = $this->session->userdata('authorized');
|
|
|
220 |
if(isset($authorized) && !empty($authorized)){
|
|
|
221 |
$newValues = $authorized;
|
|
|
222 |
$newValues['totalItems'] = $cartCount;
|
|
|
223 |
$this->session->set_userdata('authorized',$newValues);
|
|
|
224 |
redirect(base_url().strtolower(__CLASS__));
|
|
|
225 |
}
|
|
|
226 |
}else{
|
|
|
227 |
redirect(base_url().strtolower(__CLASS__));
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
else
|
|
|
231 |
{
|
|
|
232 |
$response['response']['msg'] = 'Invalid Parameter!';
|
|
|
233 |
redirect(base_url().strtolower(__CLASS__));
|
|
|
234 |
|
|
|
235 |
}
|
|
|
236 |
redirect(base_url().strtolower(__CLASS__));
|
|
|
237 |
|
|
|
238 |
}
|
|
|
239 |
public function coupon($code=null)
|
|
|
240 |
{
|
|
|
241 |
$response=array();
|
|
|
242 |
$authorized = $this->session->userdata('authorized');
|
|
|
243 |
if(isset($authorized) && !empty($authorized)){
|
|
|
244 |
$_GET['userId'] = $authorized['Id'];
|
|
|
245 |
$_GET['action'] = 'applycoupon';
|
|
|
246 |
$cartId = $authorized['cartId'];
|
|
|
247 |
if($authorized['isLoggedIn'] == 1){
|
|
|
248 |
$_GET['isLoggedIn'] = 'true';
|
|
|
249 |
}
|
|
|
250 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
251 |
$_GET['isLoggedIn'] = 'false';
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
if(isset($code) and !empty($code))
|
|
|
255 |
{
|
|
|
256 |
//if user logged-in
|
|
|
257 |
$_GET['coupon_code'] = $code;
|
|
|
258 |
//TODO: Move to a config file maybe
|
|
|
259 |
if($code=='saholicdeals') {
|
|
|
260 |
$this->session->set_userdata('isAutoApplicationOff','false');
|
|
|
261 |
}
|
|
|
262 |
//$d=$this->input->get();
|
|
|
263 |
}
|
|
|
264 |
$response=$this->cart_model->getCart($this->input->get(),$this->input->post(),$this->config->item('cart_coupon'),$cartId);
|
|
|
265 |
$dealTextArray = array();
|
|
|
266 |
if(!empty($response)){
|
|
|
267 |
foreach($response['response']['cartcoupon'][0]->lines AS $line) {
|
|
|
268 |
$dealTextArray[$line->itemId] = $line->dealText;
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
$result = $response['response']['cartcoupon'][0];
|
|
|
272 |
if(isset($result->couponCode) && !empty($result->couponCode)){
|
|
|
273 |
$couponCode = $result->couponCode;
|
|
|
274 |
}
|
|
|
275 |
else{
|
|
|
276 |
$couponCode = '';
|
|
|
277 |
}
|
|
|
278 |
if($result->discountedPrice==0){
|
|
|
279 |
$res = array('totalPrice'=>$result->totalPrice,'discountedPrice'=>$result->totalPrice,'message'=>$result->message,'couponCode'=>$couponCode);
|
|
|
280 |
} else {
|
|
|
281 |
$res = array('totalPrice'=>$result->totalPrice,'discountedPrice'=>$result->discountedPrice,'message'=>$result->message,'couponCode'=>$couponCode);
|
|
|
282 |
}
|
|
|
283 |
$res['dealTextArray']=$dealTextArray;
|
|
|
284 |
echo json_encode($res);
|
|
|
285 |
}
|
|
|
286 |
public function couponClear($code=null)
|
|
|
287 |
{
|
|
|
288 |
$response=array();
|
|
|
289 |
$authorized = $this->session->userdata('authorized');
|
|
|
290 |
$this->session->set_userdata('isAutoApplicationOff','true');
|
|
|
291 |
if(isset($authorized) && !empty($authorized)){
|
|
|
292 |
$_GET['userId'] = $authorized['Id'];
|
|
|
293 |
$_GET['action'] = 'removecoupon';
|
|
|
294 |
$cartId = $authorized['cartId'];
|
|
|
295 |
if($authorized['isLoggedIn'] == 1){
|
|
|
296 |
$_GET['isLoggedIn'] = 'true';
|
|
|
297 |
}
|
|
|
298 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
299 |
$_GET['isLoggedIn'] = 'false';
|
|
|
300 |
}
|
|
|
301 |
}
|
|
|
302 |
if(isset($code) and !empty($code))
|
|
|
303 |
{
|
|
|
304 |
//if user logged-in
|
|
|
305 |
$_GET['coupon_code'] = $code;
|
|
|
306 |
//$d=$this->input->get();
|
|
|
307 |
}
|
|
|
308 |
//print_r($this->config->item('cart_couponclear'));
|
|
|
309 |
$response=$this->cart_model->getCart($this->input->get(),$this->input->post(),$this->config->item('cart_couponclear'),$cartId);
|
|
|
310 |
$result = $response['response']['cartcouponclear'][0];
|
|
|
311 |
$res = array('totalPrice'=>$result->totalPrice,'discountedPrice'=>$result->discountedPrice,'message'=>$result->message);
|
|
|
312 |
echo json_encode($res);
|
|
|
313 |
}
|
|
|
314 |
public function cartCount()
|
|
|
315 |
{
|
|
|
316 |
$response=array();
|
|
|
317 |
$authorized = $this->session->userdata('authorized');
|
|
|
318 |
$shoppingId =$this->session->userdata('shoppingId');
|
|
|
319 |
if((isset($authorized) and !empty($authorized['id'])) || ((isset($shoppingId) && !empty($shoppingId)))){
|
|
|
320 |
$response=$this->cart_model->getCart($this->input->get(),$this->input->post(),$this->config->item('cart_count'));
|
|
|
321 |
if(isset($response['response']['cartcount'][0])){
|
|
|
322 |
$result = $response['response']['cartcount'][0];
|
|
|
323 |
echo $result;
|
|
|
324 |
}
|
|
|
325 |
else{
|
|
|
326 |
$result = 0;
|
|
|
327 |
echo $result;
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
else{
|
|
|
331 |
$result = 0;
|
|
|
332 |
echo $result;
|
|
|
333 |
}
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
public function insure($itemId,$toInsure,$insuranceType){
|
|
|
337 |
$authorized = $this->session->userdata('authorized');
|
|
|
338 |
if(isset($authorized) && !empty($authorized)){
|
|
|
339 |
$_GET['userId'] = $authorized['Id'];
|
|
|
340 |
$_GET['Id'] = $authorized['cartId'];
|
|
|
341 |
if($authorized['isLoggedIn'] == 1){
|
|
|
342 |
$_GET['isLoggedIn'] = 'true';
|
|
|
343 |
}
|
|
|
344 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
345 |
$_GET['isLoggedIn'] = 'false';
|
|
|
346 |
}
|
|
|
347 |
}
|
|
|
348 |
$_GET['itemId'] = $itemId;
|
|
|
349 |
$_GET['toInsure'] = $toInsure;
|
|
|
350 |
$_GET['insuranceType'] = $insuranceType;
|
|
|
351 |
$response=$this->cart_model->getCart($this->input->get(),$this->input->post(),$this->config->item('cart_insure'));
|
|
|
352 |
$insurance = $response['response']['cartinsure'][0]->insuranceResult;
|
|
|
353 |
if(strcasecmp($insurance, 'success') == 0){
|
|
|
354 |
//$status[0] = true;
|
|
|
355 |
$res = array('status'=>true);
|
|
|
356 |
echo json_encode($res);
|
|
|
357 |
}
|
|
|
358 |
elseif(strcasecmp($insurance, 'failure') == 0) {
|
|
|
359 |
$status[0] = false;
|
|
|
360 |
echo json_encode($status);
|
|
|
361 |
}
|
|
|
362 |
}
|
|
|
363 |
//improve functinalities using ajax
|
|
|
364 |
public function anonymous()
|
|
|
365 |
{
|
|
|
366 |
$url = $this->config->item('anonymous');
|
|
|
367 |
$url = $url['url'];
|
|
|
368 |
$url = $this->config->item('curl_base_url').$url;
|
|
|
369 |
$params = array();
|
|
|
370 |
$this->mcurl->add_call('anonymous','get',$url,$params);
|
|
|
371 |
$responses = $this->mcurl->execute($url);
|
|
|
372 |
$response = array();
|
|
|
373 |
if(isset($responses['anonymous']['response']) && !empty($responses['anonymous']['response'])){
|
|
|
374 |
$data = json_decode($responses['anonymous']['response']);
|
|
|
375 |
$childarray=array();
|
|
|
376 |
$childarray['Id']=$data->userId;
|
|
|
377 |
$childarray['isLoggedIn']=$data->isLoggedIn;
|
|
|
378 |
$childarray['pincode']=$data->pincode;
|
|
|
379 |
$childarray['email']=$data->email;
|
|
|
380 |
$childarray['totalItems']=$data->totalItems;
|
|
|
381 |
$childarray['cartId']=$data->cartId;
|
|
|
382 |
$response['authorized']=$childarray;
|
|
|
383 |
$this->session->set_userdata('authorized',$response['authorized']);
|
|
|
384 |
}
|
|
|
385 |
return $response;
|
|
|
386 |
}
|
|
|
387 |
public function delete_ajax()
|
|
|
388 |
{}
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
/* End of file welcome.php */
|
|
|
392 |
/* Location: ./application/controllers/welcome.php */
|