Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require '../admin/inc/db.php';
- if (isset($_SESSION['customer'])) {
- $sess_username = $_SESSION['customer']['cust_id'];
- $check_login = mysqli_query($koneksi, "SELECT * FROM customer WHERE email = '$sess_username'");
- $data_login = mysqli_fetch_assoc($check_login);
- }
- if (isset($_SESSION['customer'])) {
- }else{
- header("location:signin.php");
- }
- ?>
- <?php include 'isi/header.php' ?>
- <?php
- $query = mysqli_query($koneksi, "SELECT * FROM cart WHERE cust_id = $sess_username");
- $alamatt = mysqli_query($koneksi, "SELECT * FROM customer_alamat WHERE cust_id = $sess_username");
- $alamatz = mysqli_fetch_assoc($alamatt);
- function rupiah($angka){
- $hasil_rupiah = "Rp " . number_format($angka,0,',','.');
- return $hasil_rupiah;
- }
- ?>
- <div class="tt-breadcrumb">
- <div class="container">
- <ul>
- <li><a href="index.php">Home</a></li>
- <li>Shopping Cart</li>
- </ul>
- </div>
- </div>
- <?php
- if (mysqli_num_rows($query) == 0) {
- echo '<div id="tt-pageContent">
- <div class="container-indent nomargin">
- <div class="tt-empty-cart">
- <span class="tt-icon icon-f-39"></span>
- <h1 class="tt-title">SHOPPING CART IS EMPTY</h1>
- <p>You have no items in your shopping cart.</p>
- <a href="index.php" class="btn">CONTINUE SHOPPING</a>
- </div>
- </div>
- </div>';
- }
- ?>
- <?php
- if (mysqli_num_rows($query) != 0) {
- echo '<div id="tt-pageContent">
- <div class="container-indent">
- <div class="container">
- <h1 class="tt-title-subpages noborder">SHOPPING CART</h1>
- <div class="row">
- <div class="col-sm-12 col-xl-8">
- <div class="tt-shopcart-table">
- <form method="post">
- <table>
- <tbody>';
- }
- ?>
- <?php
- if (mysqli_num_rows($query) == 0) {
- }else{
- while ($data = mysqli_fetch_assoc($query)){
- $uang = $data['prod_harga'];
- $uang2 = $data['hargatotal'];
- echo '<tr>';
- echo '<td>';
- echo '<a href="cart_delete.php?cart_id='.$data['cart_id'].'" class="tt-btn-close"></a>';
- echo '</td>';
- echo '<td>';
- echo '<div class="tt-product-img">';
- echo '<img src="images/loader.svg" data-src="'.$data['prod_gambar1'].'" alt="">';
- echo '</div>';
- echo '</td>';
- echo '<td>';
- echo '<h2 class="tt-title">';
- echo '<a href="product.php?name='.$data['prod_nama'].'">'.$data['prod_nama'].'</a>';
- echo '</h2>';
- echo '<ul class="tt-list-parameters">';
- echo '<li>';
- echo '<div class="tt-price">'.rupiah($uang).'</div>';
- echo '</li>';
- echo '<li>';
- echo '<div class="detach-quantity-mobile"></div>';
- echo '</li>';
- echo '<li>';
- echo '<div class="tt-price subtotal">'.rupiah($uang).'</div>';
- echo '</li>';
- echo '</ul>';
- echo '</td>';
- echo '<td>';
- echo '<div class="tt-price">'.rupiah($uang).'</div>';
- echo '</td>';
- echo '<td>';
- echo '<input type="hidden" value="'.$data['prod_id'].'" name="prod_id[]">';
- echo '<input type="hidden" value="'.$data['cust_id'].'" name="cust_id">';
- echo '<input type="hidden" value="'.$data['prod_harga'].'" name="prod_harga[]">';
- echo '<div class="detach-quantity-desctope">';
- echo '<div class="tt-input-counter style-01">';
- echo '<span class="minus-btn"></span>';
- echo '<input type="text" value="'.$data['qty'].'" name="qty[]" size="100">';
- echo '<span class="plus-btn"></span>';
- echo '</div>';
- echo '</div>';
- echo '</td>';
- echo '<td>';
- echo '<div class="tt-price subtotal">'.rupiah($uang2).'</div>';
- echo '</td>';
- echo '</tr>';
- }
- echo'
- </tbody>
- </table>
- <div class="tt-shopcart-btn">
- <div class="col-left">
- <a class="btn-link" href="index.php"><i class="icon-e-19"></i>CONTINUE SHOPPING</a>
- </div>
- <div class="col-right">
- <button style="border:none; cursor:pointer;" type="submit" name="clearallcart" class="btn-link" href="#"><i class="icon-h-02"></i>CLEAR ALL SHOPPING CART</button>
- <button style="border:none; cursor:pointer;" name="updatecart" value="tete" class="btn-link" href="#"><i class="icon-h-48"></i>UPDATE CART</button>
- </div>
- </form>
- </div>
- </div>
- </div>
- ';
- }
- ?>
- <?php
- $sums = mysqli_query($koneksi, "SELECT sum(hargatotal) from cart WHERE cust_id = $sess_username");
- $row = mysqli_fetch_assoc($sums);
- $uang3 = $row['sum(hargatotal)'];
- $query2 = mysqli_query($koneksi, "SELECT * FROM cart WHERE cust_id = $sess_username");
- $data2 = mysqli_fetch_assoc($query2);
- if (mysqli_num_rows($query) > 0) {
- echo '
- <div class="col-sm-12 col-xl-4">
- <div class="tt-shopcart-wrapper">
- <div class="tt-shopcart-box">
- <h4 class="tt-title">
- SHIPPING ADDRESS
- </h4>';
- $user_check = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM customer_alamat WHERE cust_id = '$sess_username'"));
- if ($user_check == 0) {
- echo "<p>You don't have an address, <a style='font-weight:bold;' href='address.php'>click here</a> to create an address</p>";
- echo '
- </div>
- <div class="tt-shopcart-box">
- <h4 class="tt-title">
- NOTE
- </h4>
- <p>Add special instructions for your order</p>
- <form class="form-default">
- <textarea class="form-control" rows="7"></textarea>
- </form>
- </div>
- <div class="tt-shopcart-box tt-boredr-large">
- <table class="tt-shopcart-table01">
- <tfoot>
- <tr>
- <th>TOTAL</th>
- <td>'.rupiah($uang3) .'</td>
- </tr>
- </tfoot>
- </table>
- <button href="#" style="border:none;" class="btn-lg"><span class="icon icon-check_circle" disabled></span>PROCEED TO CHECKOUT</button>
- </div>';
- }else{
- echo '
- <p>'.$alamatz['nama_penerima'].' ('.$alamatz['nohp'].') - '.$alamatz['nama_alamat'].' <br/>'.$alamatz['alamat'].', '.$alamatz['kelurahan'].', '.$alamatz['kecamatan'].', '.$alamatz['kota'].', '.$alamatz['provinsi'].', '.$alamatz['kode_pos'].'</p>
- </div>
- <div class="tt-shopcart-box">
- <h4 class="tt-title">
- NOTE
- </h4>
- <p>Add special instructions for your order</p>
- <form method="post" class="form-default">
- <input type="hidden" name="order_id">
- <input type="hidden" value="'.$data2['cust_id'].'" name="cust_id">
- <input type="hidden" value="'.$alamatz['ca_id'].'" name="ca_id">
- ';
- $query = mysqli_query($koneksi, "SELECT * FROM cart WHERE cust_id = $sess_username");
- while($data = mysqli_fetch_assoc($query)){
- echo '
- <input type="text" style="display:none;" name="prod_id[]" value="'.$data['prod_id'].'">
- <input type="text" style="display:none;" name="prod_nama[]" value="'.$data['prod_nama'].'">
- <input type="text" style="display:none;" name="hartot[]" value="'.$data['hargatotal'].'">
- <input type="text" style="display:none;" name="qty[]" value="'.$data['qty'].'">
- <input type="text" style="display:none;" name="prod_harga[]" value="'.$data['prod_harga'].'">
- ';
- }
- echo'
- <textarea style="display:none;" name="alamat">'.$alamatz['nama_penerima'].' ('.$alamatz['nohp'].') - '.$alamatz['nama_alamat'].' <br/>'.$alamatz['alamat'].', '.$alamatz['kelurahan'].', '.$alamatz['kecamatan'].', '.$alamatz['kota'].', '.$alamatz['provinsi'].', '.$alamatz['kode_pos'].'</textarea>
- <textarea class="form-control" name="catatan" rows="7"></textarea>
- </div>
- <div class="tt-shopcart-box tt-boredr-large">
- <table class="tt-shopcart-table01">
- <tfoot>
- <tr>
- <th>TOTAL</th>
- <td>'.rupiah($uang3) .'</td>
- </tr>
- </tfoot>
- </table>
- <button name="checkout" href="#" style="border:none;" class="btn btn-lg"><span class="icon icon-check_circle" disabled></span>PROCEED TO CHECKOUT</button>
- </div>
- </form>';
- }
- }
- ?>
- <?php if (mysqli_num_rows($query) > 0) {
- echo '
- </div>
- </div>
- </div>
- </div>
- </div>
- </div> ';
- }
- ?>
- <?php
- if (isset($_POST['checkout'])){
- $cust_id = $_POST['cust_id'];
- $ca_id = $_POST['ca_id'];
- $note = $_POST['catatan'];
- $prod_id = $_POST['prod_id'];
- $prod_nama = $_POST['prod_nama'];
- $prod_hartot = $_POST['hartot'];
- $prod_harga = $_POST['prod_harga'];
- $prod_qty = $_POST['qty'];
- $alamat = $_POST['alamat'];
- $total = array_sum($prod_hartot);
- $id = "";
- $nama = "";
- $hartot = "";
- $harga = "";
- $qty = "";
- for ($i=0; $i < count($prod_id) ; $i++) {
- $id .= $prod_id[$i].',';
- $nama .= $prod_nama[$i].',';
- $hartot .= $prod_hartot[$i].',';
- $harga .= $prod_harga[$i].',';
- $qty .= $prod_qty[$i].',';
- }
- $queryINSERT = "INSERT INTO `checkout`(`order_id`, `cust_id`, `ca_id`, `alamat`, `prod_id`, `prod_nama`, `prod_gambar1`, `prod_harga`, `qty`, `hargatotal`, `total`, `note`, `pembayaran_stat`, `pengiriman_stat`, `tanggal`) VALUES(NULL,'$cust_id','$ca_id','$alamat','$id','$nama','-','$harga','$qty','$hartot','$total','$note',0,0,'".date('Y-m-d')."')";
- $insert = mysqli_query($koneksi,$queryINSERT);
- if($insert){
- $queryDELETE = "DELETE FROM cart WHERE cust_id=$cust_id";
- $del = mysqli_query($koneksi,$queryDELETE);
- if($del){
- echo "<script>alert('suskes')</script>";
- }else{
- echo "<script>alert('error! note:".mysqli_error($koneksi)."')</script>";
- }
- }else{
- echo "<script>alert('error! note:".mysqli_error($koneksi)."')</script>";
- }
- }
- if (isset($_POST['updatecart'])) {
- $prod_id = $_POST['prod_id'];
- $cust_id = $_POST['cust_id'];
- $qty = $_POST['qty'];
- $prod_harga = $_POST['prod_harga'];
- for ($i=0; $i <= count($prod_id) ; $i++) {
- $hargatotal3 = $prod_harga[$i] * $qty[$i];
- $update = mysqli_query($koneksi,"UPDATE cart SET qty = $qty[$i], hargatotal = $hargatotal3 WHERE prod_id ='$prod_id[$i]' AND cust_id ='$cust_id'");
- if ($update) {
- echo "<script>window.location='cart.php';</script>";
- }else{
- echo "<script>window.location='cart.php';</script>";
- }
- }
- }
- if (isset($_POST['clearallcart'])) {
- $deleteallcart = mysqli_query($koneksi, "DELETE from cart WHERE cust_id = '$sess_username'");
- if ($deleteallcart) {
- echo "<script>window.location='cart.php';</script>";
- }else{
- echo "<script>window.location='cart.php';</script>";
- }
- }
- ?>
- <?php include 'isi/footer.php' ?>
Advertisement
Add Comment
Please, Sign In to add comment