| 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/nguyenlieumyphamgiasi.vn/public_html/site/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class cart extends CI_Controller
{
protected $_templates;
function __construct()
{
parent::__construct();
$this->load->model('cart_model','cart');
}
public function index()
{
}
function add()
{
$req = $this->_get_form() ;
$ses_cart = get_ses_cart() ;
array_push($ses_cart, $req) ;
$_SESSION['cart'] = $ses_cart ;
}
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 removecart()
{
$ses_cart = isset($_SESSION['cart'])? (!empty($_SESSION['cart']) ? $_SESSION['cart'] : array()) : array() ;
$proid = $this->input->post('proid') ;
$item = $this->input->post('item') ;
array_splice($ses_cart, $item, 1) ;
$_SESSION['cart'] = $ses_cart ;
echo "success" ;
}
function getItem($id)
{
$item = -1 ;
for($i=0;$i<count($ses_product);$i++)
{
if($ses_product[$i]['proid']== $id){
$item = $i ;
return $item ;
}
}
return $item ;
}
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'] = 1 ;
}
return $data ;
}
}
?>