| Server IP : 103.48.194.25 / Your IP : 216.73.217.33 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 8.2.20 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hocthongminh.net-bk/public_html/site/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cart extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('cart_model','cart');
}
public function index()
{
$res['token'] = '';
$res['items'] = array();
$res['note'] = '';
$res['free_shipping'] = false;
$res['total_price'] = 0;
$res['total_weight'] = 0;
$res['item_count'] = 0;
$res['requires_shipping'] = false;
$res['sub_total_price'] = 0;
$res['total_line_item_price'] = 0;
$res['discount'] = 0;
$res['shipping_fee'] = 0;
$res['attributes'] = array();
$res['referring_site'] = "https://za.zalo.me/v3/verifyv2/pc?token=OMxnnTHyLmfW1_F9sHPVRMK0-RZQ4K9mPnlckJW\u0026continue=https%3A%2F%2Fant-mobile.mysapo.net%2Fdien-thoai";
$res['reference'] = '';
$res['landing_site'] = '/dien-thoai';
$res['landing_site_ref'] = '';
echo json_encode($res);
}
function add()
{
$req = $this->_get_form();
$ses_cart = get_ses_cart();
foreach($ses_cart as $cart):
if($cart['proid'] == $req['proid']):
$res['code'] = 0 ;
$res['msg'] = 'Sản phẩm đã có trong giỏ hàng';
echo json_encode($res) ;
return;
endif;
endforeach;
array_push($ses_cart, $req);
$_SESSION['cart'] = $ses_cart;
$res['code'] = 1 ;
$res['msg'] = 'Đã thêm vào giỏ hàng';
echo json_encode($res);
return;
}
function _get_form()
{
$proid = $this->input->post('proid');
$rs = $this->cart->get_record('product',array('proid'=>$proid));
if($rs)
{
$data['proid'] = $proid ;
$data['pro_name'] = $rs->pro_name ;
$data['pro_img'] = $rs->proimg ;
$data['pro_price'] = $rs->price ;
$data['nb_order'] = $this->input->post('quantity') ;
return $data ;
}
}
//cap nhat so luong sản phẩm sẽ mua
function update()
{
$new_cart = array();
$proid = $this->input->post('proid');
$nb_order = $this->input->post('nb_order');
$ses_cart = get_ses_cart();
foreach($ses_cart as $cart):
if($cart['proid'] == $proid):
$cart['nb_order'] = $nb_order;
endif;
array_push($new_cart,$cart);
endforeach;
$_SESSION['cart'] = $new_cart;
$res['code'] = 1 ;
$res['msg'] = 'Đã cập nhật giỏ hàng';
echo json_encode($res);
return;
}
function remove($proid=0)
{
$new_cart = array();
$ses_cart = get_ses_cart() ;
foreach($ses_cart as $cart):
if($cart['proid'] == $proid):
continue;
endif;
array_push($new_cart,$cart);
endforeach ;
$_SESSION['cart'] = $new_cart;
redirect('gio-hang');
}
/*function edit()
{
$req = $this->_get_form() ;
$ses_cart = isset($_SESSION['cart'])? (!empty($_SESSION['cart']) ? $_SESSION['cart'] : array()) : array() ;
//xoa item cu ra khoi gio hang
$item = $this->input->post('item') ;
array_splice($ses_cart, $item, 1) ;
//them vao gio hang
array_push($ses_cart, $req) ;
$_SESSION['cart'] = $ses_cart ;
}*/
/*function remove()
{
$ses_cart = get_ses_cart() ;
$item = $this->input->post('item');
$proid = $this->input->post('proid');
array_splice($ses_cart, $item, 1) ;
$new_cart = array();
foreach($ses_cart as $cart):
array_push($new_cart,$cart);
endforeach ;
$_SESSION['cart'] = $ses_cart ;
redirect("gio-hang");
}*/
}
?>