Advertisement
timonte

cart_view

Apr 13th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Cart extends CI_Controller {
  5.  
  6. function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->library(array('template', 'cart'));
  10. $this->load->model('app_home');
  11. }
  12.  
  13. public function index()
  14. {
  15. $this->template->alfatihmart("cart");
  16. }
  17.  
  18. public function add()
  19. {
  20. if(is_numeric($this->uri->segment(3)))
  21. {
  22.  
  23. $id = $this->uri->segment(3);
  24. $get = $this->app_home->get_where('t_items', array('id_item' => $id))->row();
  25. $data= array(
  26. 'id'=> $get->id_item,
  27. 'name'=> $get->nama_item,
  28. 'price'=> $get->harga,
  29. 'weight'=> $get->berat,
  30. 'qty' => 1
  31.  
  32. );
  33. $this->cart->insert($data);
  34.  
  35. echo'<script type="text/javascript">window.history.go(-1);</script>';
  36.  
  37. } else {
  38. redirect('home');
  39. }
  40. }
  41. public function update()
  42. {
  43. if ($this->uri->segment(3))
  44. {
  45. $this->load->library('form_validation');
  46.  
  47. $this->form_validation->set_rules('qty', 'Jumlah Pesanan', 'required|numeric');
  48.  
  49. if ($this->form_validation->run() == TRUE)
  50. {
  51. $data = array(
  52. 'qty' => $this->input->post('qty', TRUE),
  53. 'rowid' => $this->uri->segment(3)
  54. );
  55.  
  56. $this->cart->update($data);
  57.  
  58. redirect('cart');
  59. } else {
  60. $this->template->alfatihmart('cart');
  61. }
  62.  
  63. } else {
  64. redirect('cart');
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement