Advertisement
Guest User

controller

a guest
Jul 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Shopping_cart extends CI_Controller {
  5.  
  6. function index()
  7. {
  8. $this->load->model("shopping_cart_model");
  9. $this->load->library(array("template","simple_login"));
  10. $this->simple_login->cek_login();
  11. $data["data_barang"] = $this->shopping_cart_model->fetch_all();
  12. $this->template->set('title', 'shopping_cart');
  13. $this->template->load('blank', 'contents' , 'shopping_cart', $data);
  14. }
  15.  
  16.  
  17. function add()
  18. {
  19. $this->load->library("cart");
  20. $data = array(
  21. "id" => $_POST["id_barang"],
  22. "name" => $_POST["nama_barang"],
  23. "qty" => $_POST["quantity"],
  24. "price" => $_POST["jenis_barang"]
  25. );
  26. $this->cart->insert($data); //return rowid
  27. echo $this->view();
  28. }
  29. function insert() {
  30. $this->load->library("cart");
  31. $data =array(
  32. "id" => $_POST["id_barang"],
  33. "name" => $_POST["nama_barang"],
  34. "qty" => $_POST["quantity"],
  35. "price" => $_POST["jenis_barang"]
  36. );
  37. $query=$this->db->insert('barang_masuk', $data);
  38. echo $this->view();
  39. }
  40. function load()
  41. {
  42. echo $this->view();
  43. }
  44.  
  45. function remove()
  46. {
  47. $this->load->library("cart");
  48. $row_id = $_POST["row_id"];
  49. $data = array(
  50. 'rowid' => $row_id,
  51. 'qty' => 0
  52. );
  53. $this->cart->update($data);
  54. echo $this->view();
  55. }
  56. function save(){
  57.  
  58. $shopping_cart_data = $this->input->post('data');
  59. $this->load->model('shopping_cart_model');
  60. $status->$this->shopping_cart_model->save($data);
  61.  
  62. $this->output->set_content_type('application/json');
  63. echo json_encode(array('status' => $status));
  64. }
  65.  
  66. function clear()
  67. {
  68. $this->load->library("cart");
  69. $this->cart->destroy();
  70. echo $this->view();
  71. }
  72.  
  73. function view()
  74. {
  75. $this->load->library("cart");
  76. $output = '';
  77. $output .= '
  78. <h3>Data Barang Yang Akan Dimasukkan</h3><br />
  79. <div class="table-responsive">
  80. <div align="right">
  81. <button type="button" id="clear_cart" class="btn btn-warning">Clear Cart</button>
  82. </div>
  83. <br />
  84. <table class="table table-bordered">
  85. <tr>
  86. <th width="40%">Name</th>
  87. <th width="15%">Quantity</th>
  88. <th width="15%">Kode Jenis</th>
  89. <th width="15%">Total</th>
  90. <th width="25%">Action</th>
  91. </tr>
  92.  
  93. ';
  94. $count = 0;
  95. foreach($this->cart->contents() as $items)
  96. {
  97. $count++;
  98. $output .= '
  99. <tr>
  100. <td>'.$items["name"].'</td>
  101. <td>'.$items["qty"].'</td>
  102. <td>'.$items["price"].'</td>
  103. <td>'.$items["subtotal"].'</td>
  104. <td><button type="button" name="remove" class="btn btn-danger btn-xs remove_inventory" id="'.$items["rowid"].'">Remove</button></td>
  105. </tr>
  106. ';
  107. }
  108. $output .= '
  109. <tr>
  110. <td colspan="4" align="right">Total</td>
  111. <td>'.$this->cart->total().'</td>
  112. <td><button type="button" name="simpan" class="btn btn-warning btn-xs save_inventory" id="rowid">Simpan</button></td>
  113. </tr>
  114. </table>
  115.  
  116. </div>
  117. ';
  118.  
  119. if($count == 0)
  120. {
  121. $output = '<h3 align="center">Cart is Empty</h3>';
  122. }
  123. return $output;
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement