126 lines
7.9 KiB
PHP
126 lines
7.9 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
require_once __DIR__ . '/store.php';
|
||
|
||
$summary = store_cart_summary();
|
||
$lines = $summary['lines'];
|
||
$currentUser = store_current_user();
|
||
|
||
store_page_start('Keranjang', 'Tinjau item, ubah quantity, dan lanjutkan checkout.', ['noindex' => true]);
|
||
?>
|
||
<section class="section-block pt-0">
|
||
<div class="section-heading mb-4">
|
||
<span class="eyebrow">Keranjang</span>
|
||
<h1 class="section-title">Tinjau pesanan sebelum checkout.</h1>
|
||
<p class="section-copy mb-0">Update quantity, cek ongkir, lalu lanjut ke checkout untuk menyimpan pesanan ke sistem.</p>
|
||
</div>
|
||
|
||
<?php if ($lines && !$currentUser): ?>
|
||
<div class="alert alert-light border shadow-sm mb-4" role="alert">
|
||
Keranjang berisi item, tetapi checkout hanya bisa dilakukan setelah login.
|
||
Silakan <a href="auth.php?mode=login&redirect_to=cart.php">login / register</a> untuk melanjutkan pesanan.
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php if (!$lines): ?>
|
||
<div class="empty-state-card text-center mx-auto">
|
||
<span class="eyebrow">Keranjang kosong</span>
|
||
<h2 class="section-title">Belum ada produk di keranjang.</h2>
|
||
<p class="section-copy">Mulai dari katalog untuk mencoba alur add-to-cart lalu kembali ke halaman ini.</p>
|
||
<div class="d-flex justify-content-center gap-2 mt-3">
|
||
<a class="btn btn-dark" href="index.php#catalog">Buka katalog</a>
|
||
<a class="btn btn-outline-secondary" href="order_status.php">Lacak pesanan</a>
|
||
</div>
|
||
</div>
|
||
<?php else: ?>
|
||
<div class="row g-4 align-items-start">
|
||
<div class="col-lg-8">
|
||
<form id="cart-update-form" action="cart_action.php" method="post" class="d-grid gap-3" data-auto-disable>
|
||
<input type="hidden" name="action" value="update">
|
||
<input type="hidden" name="redirect_to" value="cart.php">
|
||
<?php foreach ($lines as $line): ?>
|
||
<article class="cart-item">
|
||
<div class="product-visual product-visual--<?= h($line['product']['tone']) ?> product-visual--mini">
|
||
<span class="product-visual__meta"><?= h($line['product']['category_label']) ?></span>
|
||
<strong class="product-visual__code"><?= h($line['product']['visual_code']) ?></strong>
|
||
<span class="product-visual__name"><?= h($line['product']['name']) ?></span>
|
||
</div>
|
||
<div class="cart-item__body">
|
||
<div class="d-flex flex-column flex-md-row justify-content-between gap-3">
|
||
<div>
|
||
<h2 class="cart-item__title"><?= h($line['product']['name']) ?></h2>
|
||
<p class="text-muted mb-1"><?= h($line['product']['short_description']) ?></p>
|
||
<div class="detail-chip-group mt-2">
|
||
<span class="detail-chip"><?= h($line['product']['lead_time']) ?></span>
|
||
<span class="detail-chip"><?= h($line['product']['serves']) ?></span>
|
||
</div>
|
||
</div>
|
||
<div class="text-md-end">
|
||
<div class="price-tag price-tag--inline"><?= h(store_money((float)$line['product']['price'])) ?></div>
|
||
<div class="small text-muted mt-1">per <?= h($line['product']['unit']) ?></div>
|
||
</div>
|
||
</div>
|
||
<div class="d-flex flex-column flex-sm-row align-items-sm-center justify-content-between gap-3 mt-3">
|
||
<div class="quantity-field quantity-field--compact">
|
||
<button type="button" class="btn btn-outline-secondary" data-qty-target="qty-<?= h($line['slug']) ?>" data-qty-step="-1" aria-label="Kurangi jumlah">−</button>
|
||
<input id="qty-<?= h($line['slug']) ?>" class="form-control text-center" type="number" name="quantities[<?= h($line['slug']) ?>]" min="1" max="20" value="<?= h((string)$line['quantity']) ?>">
|
||
<button type="button" class="btn btn-outline-secondary" data-qty-target="qty-<?= h($line['slug']) ?>" data-qty-step="1" aria-label="Tambah jumlah">+</button>
|
||
</div>
|
||
<div class="d-flex align-items-center gap-2 ms-sm-auto">
|
||
<div class="cart-item__total"><?= h(store_money((float)$line['line_total'])) ?></div>
|
||
<button type="submit" class="btn btn-outline-secondary btn-sm" form="remove-<?= h($line['slug']) ?>">Hapus</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</article>
|
||
<?php endforeach; ?>
|
||
<div class="d-flex flex-column flex-md-row justify-content-between gap-2">
|
||
<a class="btn btn-outline-secondary" href="index.php#catalog">Tambah produk lain</a>
|
||
<button class="btn btn-dark" type="submit">Perbarui keranjang</button>
|
||
</div>
|
||
</form>
|
||
|
||
<?php foreach ($lines as $line): ?>
|
||
<form id="remove-<?= h($line['slug']) ?>" action="cart_action.php" method="post" class="d-none">
|
||
<input type="hidden" name="action" value="remove">
|
||
<input type="hidden" name="slug" value="<?= h($line['slug']) ?>">
|
||
<input type="hidden" name="redirect_to" value="cart.php">
|
||
</form>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<div class="col-lg-4">
|
||
<aside class="summary-card sticky-summary">
|
||
<div class="card-kicker">Ringkasan pembayaran</div>
|
||
<h2 class="summary-title">Siap dilanjutkan ke checkout.</h2>
|
||
<div class="receipt-line">
|
||
<span>Subtotal</span>
|
||
<strong><?= h(store_money((float)$summary['subtotal'])) ?></strong>
|
||
</div>
|
||
<div class="receipt-line">
|
||
<span>Ongkir</span>
|
||
<strong><?= h(store_money((float)$summary['shipping_fee'])) ?></strong>
|
||
</div>
|
||
<div class="receipt-line receipt-line--total">
|
||
<span>Total</span>
|
||
<strong><?= h(store_money((float)$summary['grand_total'])) ?></strong>
|
||
</div>
|
||
<p class="note-copy mt-3 mb-4">Gratis ongkir otomatis untuk subtotal mulai Rp 250.000.</p>
|
||
<div class="d-grid gap-2">
|
||
<?php if ($currentUser): ?>
|
||
<a class="btn btn-dark btn-lg" href="checkout.php">Lanjut ke checkout</a>
|
||
<?php else: ?>
|
||
<a class="btn btn-dark btn-lg" href="auth.php?mode=login&redirect_to=cart.php">Login untuk lanjut checkout</a>
|
||
<?php endif; ?>
|
||
<a class="btn btn-outline-secondary" href="order_status.php">Sudah punya kode pesanan?</a>
|
||
</div>
|
||
<?php if (!$currentUser): ?>
|
||
<p class="note-copy mt-3 mb-0">Setelah login berhasil, Anda bisa kembali ke keranjang dan meneruskan checkout.</p>
|
||
<?php endif; ?>
|
||
</aside>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
</section>
|
||
<?php store_page_end(); ?>
|