290 lines
9.8 KiB
PHP
290 lines
9.8 KiB
PHP
<?php include '../template/template1.php'; ?>
|
|
|
|
<?php include '../template/header.php'; ?>
|
|
|
|
<?php
|
|
// Ambil id_produk dari URL
|
|
$id_produk = isset($_GET['id']) ? $_GET['id'] : 0;
|
|
|
|
// Query untuk mengambil data produk berdasarkan id_produk
|
|
$query = mysqli_query($conn, "SELECT * FROM produk WHERE id_produk = $id_produk");
|
|
$produk = mysqli_fetch_assoc($query);
|
|
?>
|
|
|
|
<main class="main">
|
|
|
|
<!-- Portfolio Details Section -->
|
|
<section id="portfolio-details" class="portfolio-details section">
|
|
|
|
<div class="container" data-aos="fade-up">
|
|
|
|
<div class="swiper-wrapper align-items-center">
|
|
|
|
<div class="swiper-slide">
|
|
<img src="<?= $base_url; ?>/assets/img/produk/<?= $produk['gambar']; ?>" width="400" height="400" alt="">
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row justify-content-between gy-4 mt-4">
|
|
|
|
<div class="col-lg-8" data-aos="fade-up">
|
|
<div class="portfolio-description">
|
|
<h2><?php echo $produk['nama_produk']; ?></h2>
|
|
<p><?php echo $produk['deskripsi']; ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-3" data-aos="fade-up" data-aos-delay="100">
|
|
<div class="portfolio-info">
|
|
<h3>Informasi Produk</h3>
|
|
<ul>
|
|
<li><strong>Kategori</strong>: <?php echo $produk['kategori']; ?></li>
|
|
<li><strong>Harga</strong>: Rp <?php echo number_format($produk['harga_jual'], 0, ',', '.'); ?></li>
|
|
<li><strong>Stok</strong>: <?php echo $produk['stok']; ?> <?php echo $produk['satuan']; ?></li>
|
|
</ul>
|
|
|
|
<?php if (isset($_SESSION['status_login']) && $_SESSION['status_login']): ?>
|
|
<div class="d-flex flex-column align-items-center mt-3">
|
|
<div class="d-flex align-items-center mb-2">
|
|
<button type="button" class="btn btn-outline-secondary btn-sm minus-btn"
|
|
data-produk-id="<?= $produk['id_produk']; ?>"
|
|
<?= $produk['stok'] <= 0 ? 'disabled' : ''; ?>>-</button>
|
|
|
|
<input type="number" class="form-control mx-2 text-center jumlah-input"
|
|
data-produk-id="<?= $produk['id_produk']; ?>"
|
|
value="1" min="1" style="width: 50px;" <?= $produk['stok'] <= 0 ? 'disabled' : ''; ?>>
|
|
|
|
<button type="button" class="btn btn-outline-secondary btn-sm plus-btn"
|
|
data-produk-id="<?= $produk['id_produk']; ?>"
|
|
<?= $produk['stok'] <= 0 ? 'disabled' : ''; ?>>+</button>
|
|
</div>
|
|
|
|
<a href="#" class="btn btn-primary w-100 mt-3 mb-2"
|
|
id="tambahKeranjangBtn"
|
|
data-produk-id="<?= $produk['id_produk']; ?>"
|
|
data-stok="<?= $produk['stok']; ?>"
|
|
data-kategori="<?= $produk['kategori']; ?>"
|
|
<?= $produk['stok'] <= 0 ? 'disabled style="pointer-events: none; opacity: 0.5; cursor: not-allowed;"' : ''; ?>>
|
|
Tambah ke Keranjang
|
|
</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<button class="btn btn-secondary w-100 mt-3 mb-2" disabled>Harap Masuk Terlebih Dahulu!</button>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section><!-- /Portfolio Details Section -->
|
|
|
|
<section id="testimonials" class="testimonials section">
|
|
|
|
<!-- Section Title -->
|
|
<div class="container section-title" data-aos="fade-up">
|
|
<h2 style="font-size: 2.5rem;">Testimoni</h2>
|
|
<p style="font-size: 1.25rem;">Kami bangga dengan kepuasan pelanggan kami yang tinggi. Dengarkan apa yang mereka katakan tentang pengalaman mereka bersama kami.</p>
|
|
</div><!-- End Section Title -->
|
|
|
|
<div class="container" data-aos="fade-up" data-aos-delay="100">
|
|
|
|
<div class="swiper init-swiper">
|
|
<script type="application/json" class="swiper-config">
|
|
{
|
|
"loop": true,
|
|
"speed": 600,
|
|
"autoplay": {
|
|
"delay": 5000
|
|
},
|
|
"slidesPerView": "auto",
|
|
"pagination": {
|
|
"el": ".swiper-pagination",
|
|
"type": "bullets",
|
|
"clickable": true
|
|
},
|
|
"breakpoints": {
|
|
"320": {
|
|
"slidesPerView": 1,
|
|
"spaceBetween": 40
|
|
},
|
|
"1200": {
|
|
"slidesPerView": 3,
|
|
"spaceBetween": 10
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
<div class="swiper-wrapper">
|
|
<?php
|
|
$query = mysqli_query($conn, "
|
|
SELECT
|
|
pembeli.id_pembeli,
|
|
pembeli.nama_pembeli,
|
|
pembeli.username,
|
|
pembeli.email,
|
|
pembeli.no_hp,
|
|
pembeli.alamat,
|
|
pembeli.saldo,
|
|
testimoni.id_testimoni,
|
|
testimoni.id_order,
|
|
testimoni.deskripsi,
|
|
testimoni.rating,
|
|
testimoni.tanggal,
|
|
testimoni.gambar,
|
|
produk.nama_produk
|
|
FROM
|
|
testimoni
|
|
JOIN
|
|
pembeli ON testimoni.id_pembeli = pembeli.id_pembeli
|
|
JOIN
|
|
`orders` ON testimoni.id_order = `orders`.id_order
|
|
JOIN
|
|
order_details ON `orders`.id_order = order_details.id_order
|
|
JOIN
|
|
produk ON order_details.id_produk = produk.id_produk
|
|
WHERE
|
|
testimoni.rating = 5 AND produk.id_produk = $id_produk
|
|
ORDER BY
|
|
testimoni.tanggal DESC
|
|
LIMIT 5
|
|
");
|
|
|
|
if (mysqli_num_rows($query) > 0) {
|
|
while ($testi = mysqli_fetch_assoc($query)) {
|
|
$nama_pembeli = htmlspecialchars($testi['nama_pembeli']);
|
|
$komen = htmlspecialchars($testi['deskripsi']);
|
|
$bintang = intval($testi['rating']);
|
|
$nama_produk = htmlspecialchars($testi['nama_produk']);
|
|
$gambar_testi = $testi['gambar'];
|
|
?>
|
|
|
|
<div class="swiper-slide">
|
|
<div class="testimonial-item">
|
|
<!-- Gambar testimoni -->
|
|
<?php if (!empty($gambar_testi) && file_exists('assets/img/testimoni/' . $gambar_testi)) : ?>
|
|
<img src="assets/img/testimoni/<?php echo $gambar_testi; ?>" class="testimonial-img mb-2" alt="Gambar Testimoni" style="max-height: 200px; object-fit: cover; border-radius: 8px;">
|
|
<?php endif; ?>
|
|
|
|
<h3><?php echo $nama_pembeli; ?></h3>
|
|
<h4 style="font-size: 1rem; font-weight: normal; color: #666;">Produk: <strong><?php echo $nama_produk; ?></strong></h4>
|
|
|
|
<div class="stars">
|
|
<?php
|
|
for ($i = 0; $i < $bintang; $i++) {
|
|
echo '<i class="bi bi-star-fill"></i>';
|
|
}
|
|
?>
|
|
</div>
|
|
<p>
|
|
<i class="bi bi-quote quote-icon-left"></i>
|
|
<span><?php echo $komen; ?></span>
|
|
<i class="bi bi-quote quote-icon-right"></i>
|
|
</p>
|
|
</div>
|
|
</div><!-- End testimonial item -->
|
|
|
|
<?php
|
|
}
|
|
} else {
|
|
echo '<div class="swiper-slide"><div class="testimonial-item"><p class="text-muted text-center">Belum ada testimoni untuk produk ini.</p></div></div>';
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
<?php include '../template/footer.php'; ?>
|
|
|
|
<?php include '../template/template2.php'; ?>
|
|
|
|
<script>
|
|
document.querySelectorAll('.plus-btn').forEach((btn, index) => {
|
|
btn.addEventListener('click', function () {
|
|
const jumlahInput = document.querySelectorAll('.jumlah-input')[index];
|
|
const stokMax = <?php echo $produk['stok']; ?>;
|
|
let jumlah = parseInt(jumlahInput.value) + 1;
|
|
|
|
if (jumlah <= stokMax) {
|
|
jumlahInput.value = jumlah;
|
|
} else {
|
|
alert("Jumlah barang melebihi stok yang tersedia.");
|
|
}
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('.minus-btn').forEach((btn, index) => {
|
|
btn.addEventListener('click', function () {
|
|
const jumlahInput = document.querySelectorAll('.jumlah-input')[index];
|
|
if (jumlahInput.value > 1) {
|
|
jumlahInput.value = parseInt(jumlahInput.value) - 1;
|
|
}
|
|
});
|
|
});
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
const tambahBtn = document.getElementById("tambahKeranjangBtn"); // Tombol "Tambah ke Keranjang"
|
|
if (!tambahBtn) return;
|
|
|
|
tambahBtn.addEventListener("click", function (e) {
|
|
e.preventDefault();
|
|
|
|
const produkId = this.dataset.produkId;
|
|
const stok = parseInt(this.dataset.stok);
|
|
const kategori = this.dataset.kategori;
|
|
const jumlah = parseInt(document.querySelector(".jumlah-input").value); // Input jumlah
|
|
|
|
if (jumlah > stok) {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Oops!',
|
|
text: 'Jumlah melebihi stok yang tersedia.',
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (kategori === "Jeroan") {
|
|
window.location.href = `add_to_cart.php?add=${produkId}&jumlah=${jumlah}`;
|
|
return;
|
|
}
|
|
|
|
Swal.fire({
|
|
title: 'Pilih Jumlah Potongan',
|
|
input: 'select',
|
|
inputOptions: {
|
|
1: '1 Potong',
|
|
2: '2 Potong',
|
|
4: '4 Potong',
|
|
6: '6 Potong',
|
|
8: '8 Potong',
|
|
10: '10 Potong',
|
|
12: '12 Potong'
|
|
},
|
|
inputPlaceholder: 'Pilih jumlah potongan',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Tambah ke Keranjang',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
const potongan = result.value;
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Berhasil!',
|
|
text: 'Produk telah ditambahkan ke keranjang.',
|
|
timer: 1500,
|
|
showConfirmButton: false
|
|
}).then(() => {
|
|
window.location.href = `add_to_cart.php?add=${produkId}&jumlah=${jumlah}&potong=${potongan}`;
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|