Advertisement
gurumutant

Shopping Cart dg Session - Halaman Cart

Feb 2nd, 2020
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.05 KB | None | 0 0
  1. <!-- pages/cart.php -->
  2. <div class="container-fluid">
  3.           <!-- Page Heading -->
  4.           <div class="d-sm-flex align-items-center justify-content-between mb-4">
  5.             <h1 class="h3 mb-0 text-gray-800">Keranjang Belanja</h1>
  6.           </div>
  7.            
  8.           <?php tampilPesan(); ?>
  9.           <div class="row"> <!-- start row untuk tabel -->
  10.             <div class="col-xl-12 col-md-12 mb-12">
  11.                 <table class="table table-striped" id="tabel_kategori">
  12.                     <thead>
  13.                     <tr>
  14.                         <th>ID Produk</th>
  15.                         <th>Nama Produk</th>
  16.                         <th>Harga</th>
  17.                         <th>Qty</th>
  18.                         <th>Subtotal</th>
  19.                         <th>Aksi</th>
  20.                     </tr>
  21.                     </thead>
  22.                     <tbody>
  23.                     <?php // mengambil data untuk ditampilkan di tabel
  24.                         $ids=[];
  25.                         if (isset($_SESSION['cart'])) {
  26.                             foreach ($_SESSION['cart'] as $key => $item) {
  27.                                 $ids[] = $key;
  28.                             }
  29.                             $daftar_id_produk = implode(',', $ids);
  30.                         } else {
  31.                             $daftar_id_produk = '0';
  32.                         }
  33.                         $sql = "SELECT *
  34.                                FROM produk
  35.                                 WHERE prod_id IN(".$daftar_id_produk.")";
  36.                         $stmt = $conn->query($sql);
  37.                         while ($row = $stmt->fetch(PDO::FETCH_OBJ)):
  38.                     ?>
  39.                     <tr>
  40.                         <td><?= $row->prod_id; ?></td>
  41.                         <td><?= $row->prod_nama; ?></td>
  42.                         <td><?= $row->prod_harga; ?></td>
  43.                         <td><?= $_SESSION['cart'][$row->prod_id]; ?></td>
  44.                         <td><?= $row->prod_harga * $_SESSION['cart'][$row->prod_id] ?></td>
  45.                         <td>
  46.                             <a href="proses/add-cart.php?id=<?= $row->prod_id; ?>" data-remote="false" class="btn btn-info btn-sm" >Beli</a>
  47.                             <?php if(batasiTampilan([1,9])): ?>
  48.                             <a href="?p=kategori&id=<?= $row->Kode_Kategori; ?>" class="btn btn-sm btn-warning">Edit</a>
  49.                             <a href="proses/kategori-proses.php?id=<?= $row->Kode_Kategori; ?>" class="btn btn-sm btn-danger confirm">Hapus</a>
  50.                             <?php endif; ?>
  51.                         </td>
  52.                     </tr>  
  53.                         <?php endwhile; ?>
  54.                     </tbody>
  55.                 </table>
  56.             </div>
  57.           </div> <!-- end row untuk tabel -->
  58.           <a href="proses/empty-cart.php" class="btn btn-danger">Hapus Keranjang Belanja</a>
  59.         <!-- /.container-fluid -->
  60. </div>
  61. <!-- Modal -->
  62. <div id="myModal" class="modal fade" role="dialog">
  63.     <div class="modal-dialog">
  64.  
  65.         <!-- Modal content-->
  66.         <div class="modal-content">
  67.             <div class="modal-header">
  68.                 <h4 class="modal-title">Detail Kategori</h4>
  69.                 <button type="button" class="close" data-dismiss="modal">&times;</button>
  70.             </div>
  71.             <div class="modal-body">
  72.                 <p>Some text in the modal.</p>
  73.             </div>
  74.             <div class="modal-footer">
  75.                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  76.             </div>
  77.         </div>
  78.  
  79.     </div>
  80. </div>
  81. <script>
  82.     $(document).ready(function() {
  83.         $('#tabel_kategori').DataTable({
  84.             "language": {
  85.                 "url": "http://localhost/pwd2019/perpustakaan/vendor/datatables/Indonesian.json"
  86.             }
  87.         });
  88.  
  89.     });
  90.  
  91. $('a.confirm').bind('click',function(e) {
  92.     var baris = $(this).parents('tr');
  93.     e.preventDefault();
  94.     var url = $(this).attr('href');
  95.     Swal.fire({
  96.       title: 'Anda yakin untuk menghapus?',
  97.       text: "Data yang sudah dihapus tidak dapat dikembalikan lagi.",
  98.       type: 'warning',
  99.       showCancelButton: true,
  100.       confirmButtonColor: '#3085d6',
  101.       cancelButtonColor: '#d33',
  102.       confirmButtonText: 'Ya, saya yakin',
  103.       cancelButtonText: 'Tidak, saya khilaf'
  104.     }).then((result) => {
  105.       if (result.value) {
  106.         $.get(url).done(function(response) {
  107.             Swal.fire('Data berhasil dihapus').then((result) => {
  108.                     baris.remove();
  109.                 });
  110.         });
  111.       }
  112.     });
  113.  
  114. });
  115. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement