Guest User

Untitled

a guest
May 20th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Cart extends CI_Controller {
  4.  
  5.  
  6.    
  7.     function __construct()
  8.     {
  9.       parent::__construct();
  10.       $this->load->helper('url');
  11.       $this->load->library('session');
  12.       $this->load->library('cart');
  13.       $this->load->helper('form');
  14.       $this->load->database();
  15.     }
  16.  
  17.     public function index()
  18.     {
  19.     $this->load->model('Model_products');
  20.     $data['categories'] = $this->Model_products->get_categories();
  21.     $this->load->view('header');
  22.     $this->load->view('category_box', $data);
  23.     $this->load->view('cart');
  24.     $this->load->view('footer');
  25.     }
  26.  
  27.     public function addToCart()
  28.     {
  29.         $this->load->library('session');
  30.         $this->load->library('cart');
  31.         $this->load->model('Model_products');
  32.         $data['product'] = $this->Model_products->get_product($_POST['product_id']);
  33.         $data = array(
  34.                 'id'      => $data['product'][0]->id ,
  35.                 'qty'     => $_POST['quantity'],
  36.                 'price'   => $data['product'][0]->price,
  37.                 'name'    => $data['product'][0]->name
  38.                 );
  39.         $this->cart->insert($data);
  40.         print_r($this->cart->insert($data));
  41.         redirect(base_url().'cart');
  42.     }
  43.  
  44.     public function updateCart()
  45.     {
  46.         $data = array(
  47.                'rowid' => $_GET['rowid'],
  48.                'qty'   => $_GET['qty']
  49.             );
  50.  
  51.         $this->cart->update($data);
  52.     }
  53.  
  54.     public function emptyCart()
  55.     {
  56.     $this->cart->destroy();
  57.     redirect(base_url());
  58.     }
  59. }
Add Comment
Please, Sign In to add comment