Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Shopping_cart extends CI_Controller {
- function index()
- {
- $this->load->model("shopping_cart_model");
- $this->load->library(array("template","simple_login"));
- $this->simple_login->cek_login();
- $data["data_barang"] = $this->shopping_cart_model->fetch_all();
- $this->template->set('title', 'shopping_cart');
- $this->template->load('blank', 'contents' , 'shopping_cart', $data);
- }
- function add()
- {
- $this->load->library("cart");
- $data = array(
- "id" => $_POST["id_barang"],
- "name" => $_POST["nama_barang"],
- "qty" => $_POST["quantity"],
- "price" => $_POST["jenis_barang"]
- );
- $this->cart->insert($data); //return rowid
- echo $this->view();
- }
- function insert() {
- $this->load->library("cart");
- $data =array(
- "id" => $_POST["id_barang"],
- "name" => $_POST["nama_barang"],
- "qty" => $_POST["quantity"],
- "price" => $_POST["jenis_barang"]
- );
- $query=$this->db->insert('barang_masuk', $data);
- echo $this->view();
- }
- function load()
- {
- echo $this->view();
- }
- function remove()
- {
- $this->load->library("cart");
- $row_id = $_POST["row_id"];
- $data = array(
- 'rowid' => $row_id,
- 'qty' => 0
- );
- $this->cart->update($data);
- echo $this->view();
- }
- function save(){
- $shopping_cart_data = $this->input->post('data');
- $this->load->model('shopping_cart_model');
- $status->$this->shopping_cart_model->save($data);
- $this->output->set_content_type('application/json');
- echo json_encode(array('status' => $status));
- }
- function clear()
- {
- $this->load->library("cart");
- $this->cart->destroy();
- echo $this->view();
- }
- function view()
- {
- $this->load->library("cart");
- $output = '';
- $output .= '
- <h3>Data Barang Yang Akan Dimasukkan</h3><br />
- <div class="table-responsive">
- <div align="right">
- <button type="button" id="clear_cart" class="btn btn-warning">Clear Cart</button>
- </div>
- <br />
- <table class="table table-bordered">
- <tr>
- <th width="40%">Name</th>
- <th width="15%">Quantity</th>
- <th width="15%">Kode Jenis</th>
- <th width="15%">Total</th>
- <th width="25%">Action</th>
- </tr>
- ';
- $count = 0;
- foreach($this->cart->contents() as $items)
- {
- $count++;
- $output .= '
- <tr>
- <td>'.$items["name"].'</td>
- <td>'.$items["qty"].'</td>
- <td>'.$items["price"].'</td>
- <td>'.$items["subtotal"].'</td>
- <td><button type="button" name="remove" class="btn btn-danger btn-xs remove_inventory" id="'.$items["rowid"].'">Remove</button></td>
- </tr>
- ';
- }
- $output .= '
- <tr>
- <td colspan="4" align="right">Total</td>
- <td>'.$this->cart->total().'</td>
- <td><button type="button" name="simpan" class="btn btn-warning btn-xs save_inventory" id="rowid">Simpan</button></td>
- </tr>
- </table>
- </div>
- ';
- if($count == 0)
- {
- $output = '<h3 align="center">Cart is Empty</h3>';
- }
- return $output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement