Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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('m_home');
  11. }
  12.  
  13. public function index()
  14. {
  15. $this->template->sageng('cart');
  16. }
  17.  
  18. public function add()
  19. {
  20. if(is_numeric($this->uri->segment(3)))
  21. {
  22. $id = $this->uri->segment(3);
  23. $get = $this->m_home->get_where('t_items', array('id_item' => $id))->row();
  24.  
  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.  
  42. public function update()
  43. {
  44. if ($this->uri->segment(3))
  45. {
  46. $this->load->library('form_validation');
  47.  
  48. $this->form_validation->set_rules('qty', 'Jumlah Pesanan', 'required|numeric');
  49.  
  50. if ($this->form_validation->run() ==TRUE)
  51. {
  52. $data = array(
  53. 'qty' => $this->input->post('qty', TRUE),
  54. 'rowid' => $this->uri->segment(3)
  55. );
  56.  
  57. $this->cart->update($data);
  58.  
  59. redirect('cart');
  60. } else {
  61. $this->template->sageng('cart');
  62. }
  63.  
  64. } else {
  65. redirect('cart');
  66. }
  67. }
  68.  
  69. public function delete()
  70. {
  71. if ($this->uri->segment(3))
  72. {
  73.  
  74. $rowid = $this->uri->segment(3);
  75.  
  76. $this->cart->remove($rowid);
  77.  
  78. redirect('cart');
  79. } else {
  80. redirect('cart');
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement