İçeriğe geç
Tüm kodlar

ER3NSHOP

Kurulum sihirbazlı online mağaza sistemi

251 satır · 17,7 KBHamİndir
<?php
$product = db_one('SELECT * FROM products WHERE slug = ? AND status = 1', [get('slug', '')]);
if (!$product) {
    not_found();
}

$category = $product['category_id'] ? db_find('categories', $product['category_id']) : null;
$gallery = product_gallery($product);
$variants = product_variants($product['id']);
$reviews = product_reviews($product['id']);
$breakdown = review_breakdown($reviews);
$related = $category
    ? db_all('SELECT * FROM products WHERE status = 1 AND category_id = ? AND id != ? ORDER BY sold DESC, RAND() LIMIT ' . max(0, min(12, (int) theme('related_count'))), [$category['id'], $product['id']])
    : [];
$discount = discount_rate($product);
$in_stock = $product['stock'] > 0;
$can_review = is_customer() && !customer_reviewed($product['id']);
$gallery_layout = theme('gallery_layout');
$tabs = theme('product_tabs') !== 'stack';

$crumbs = $category ? [$category['name'] => category_url($category), $product['name'] => null] : [$product['name'] => null];

view_header(seo_title($product, $product['name']), [
    'description' => $product['meta_description'] ?: $product['description'],
    'image'       => $gallery[0] ?? null,
    'type'        => 'product',
    'jsonld'      => product_jsonld($product, $gallery),
]);
?>

<section class="container-x pt-8">
    <?php breadcrumb($crumbs) ?>

    <div class="mt-8 grid gap-10 lg:grid-cols-12 lg:gap-16">
        <div class="lg:col-span-7" data-customize="urun" data-customize-label="Ürün galerisi">
            <?php if ($gallery_layout === 'grid' && count($gallery) > 1): ?>
                <div class="grid grid-cols-2 gap-3">
                    <?php foreach ($gallery as $i => $image): ?>
                        <div class="relative overflow-hidden rounded-2xl bg-zinc-100 <?= $i === 0 ? 'col-span-2 aspect-[4/5] sm:aspect-[5/4]' : 'aspect-[4/5]' ?>">
                            <img src="<?= e(upload_url($image)) ?>" alt="<?= e($product['name']) ?>" class="h-full w-full object-cover" <?= $i ? 'loading="lazy"' : '' ?>>
                            <?php if ($i === 0 && $discount): ?>
                                <span class="absolute top-5 left-5 rounded-full bg-accent-600 px-3 py-1.5 text-xs font-bold text-white">−%<?= $discount ?></span>
                            <?php endif ?>
                        </div>
                    <?php endforeach ?>
                </div>
            <?php else: ?>
                <div class="flex gap-4 <?= $gallery_layout === 'side' ? 'flex-col-reverse sm:flex-row' : 'flex-col-reverse' ?>">
                    <?php if (count($gallery) > 1): ?>
                        <div class="flex flex-wrap gap-3 <?= $gallery_layout === 'side' ? 'sm:w-20 sm:flex-col sm:flex-nowrap' : '' ?>">
                            <?php foreach ($gallery as $i => $image): ?>
                                <button type="button" data-thumb="<?= e(upload_url($image)) ?>" <?= $i === 0 ? 'data-active' : '' ?> class="aspect-[4/5] w-16 overflow-hidden rounded-xl bg-zinc-100 opacity-60 ring-2 ring-transparent transition hover:opacity-100 data-active:opacity-100 data-active:ring-ink <?= $gallery_layout === 'side' ? 'sm:w-full' : 'sm:w-20' ?>">
                                    <img src="<?= e(upload_url($image)) ?>" alt="" class="h-full w-full object-cover">
                                </button>
                            <?php endforeach ?>
                        </div>
                    <?php endif ?>
                    <div class="relative <?= card_ratio_class() ?> flex-1 overflow-hidden rounded-3xl bg-zinc-100">
                        <?php if ($gallery): ?>
                            <img id="main-image" src="<?= e(upload_url($gallery[0])) ?>" alt="<?= e($product['name']) ?>" class="h-full w-full object-cover">
                        <?php else: ?>
                            <?= placeholder($product['name'], 'text-[14rem]') ?>
                        <?php endif ?>
                        <div class="pointer-events-none absolute top-5 left-5 flex flex-col items-start gap-1.5">
                            <?php foreach (product_badges($product) as [$label, $class]): ?>
                                <span class="rounded-full px-3 py-1.5 text-xs font-bold backdrop-blur <?= $class ?>"><?= e($label) ?></span>
                            <?php endforeach ?>
                        </div>
                    </div>
                </div>
            <?php endif ?>
        </div>

        <div class="lg:col-span-5">
            <div class="lg:sticky lg:top-28">
                <?php if ($category): ?>
                    <a href="<?= category_url($category) ?>" class="eyebrow transition hover:text-ink"><?= e($category['name']) ?></a>
                <?php endif ?>
                <h1 class="heading mt-3 text-3xl leading-tight <?= heading_weight_class() ?> sm:text-4xl"><?= e($product['name']) ?></h1>

                <?php if ($product['review_count']): ?>
                    <a href="#yorumlar" class="mt-4 inline-flex items-center gap-2 text-sm text-zinc-600 hover:text-ink">
                        <?= stars($product['rating']) ?>
                        <span class="font-semibold text-ink"><?= number_format($product['rating'], 1, ',', '') ?></span>
                        <span class="underline-offset-4 hover:underline"><?= (int) $product['review_count'] ?> değerlendirme</span>
                    </a>
                <?php endif ?>

                <div class="mt-6 flex items-baseline gap-3">
                    <span data-price class="font-display text-3xl font-semibold tracking-tight <?= $discount ? 'text-accent-600' : 'text-ink' ?>"><?= money($product['price']) ?></span>
                    <?php if ($discount): ?>
                        <span class="text-lg text-zinc-400 line-through"><?= money($product['old_price']) ?></span>
                    <?php endif ?>
                </div>
                <?php if (tax_rate() > 0): ?><p class="mt-1 text-xs text-zinc-500">KDV dahil</p><?php endif ?>

                <form method="post" action="<?= url('sepet-ekle') ?>" data-ajax class="mt-8 space-y-6 border-t border-zinc-200 pt-8">
                    <?= csrf_field() ?>
                    <input type="hidden" name="id" value="<?= $product['id'] ?>">

                    <?php if ($variants): ?>
                        <div data-variants>
                            <p class="text-sm font-medium text-ink"><?= e($product['variant_name'] ?: 'Seçenek') ?>: <span data-selected-variant class="font-normal text-zinc-500">Seçiniz</span></p>
                            <div class="mt-3 flex flex-wrap gap-2">
                                <?php foreach ($variants as $variant): ?>
                                    <label class="cursor-pointer">
                                        <input type="radio" name="variant_id" value="<?= $variant['id'] ?>" class="peer sr-only"
                                               data-price="<?= $variant['price'] ?? $product['price'] ?>" data-stock="<?= (int) $variant['stock'] ?>" data-label="<?= e($variant['name']) ?>">
                                        <span class="flex h-12 min-w-12 items-center justify-center rounded-xl border border-zinc-200 px-4 text-sm font-medium text-ink transition peer-checked:border-ink peer-checked:bg-ink peer-checked:text-white peer-focus-visible:ring-4 peer-focus-visible:ring-zinc-900/10 hover:border-ink <?= $variant['stock'] < 1 ? 'text-zinc-400 line-through decoration-zinc-300' : '' ?>">
                                            <?= e($variant['name']) ?>
                                        </span>
                                    </label>
                                <?php endforeach ?>
                            </div>
                        </div>
                    <?php endif ?>

                    <p class="flex items-center gap-2 text-sm font-medium <?= $in_stock ? 'text-emerald-700' : 'text-rose-600' ?>">
                        <span class="relative flex size-2">
                            <?php if ($in_stock): ?><span class="absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-60"></span><?php endif ?>
                            <span class="relative inline-flex size-2 rounded-full <?= $in_stock ? 'bg-emerald-500' : 'bg-rose-500' ?>"></span>
                        </span>
                        <span data-stock-label><?= $in_stock ? ($variants ? 'Stokta, seçenek seçin' : ($product['stock'] <= 5 ? 'Son ' . (int) $product['stock'] . ' ürün' : 'Stokta, hemen kargoda')) : 'Tükendi' ?></span>
                    </p>

                    <div class="flex gap-3">
                        <div class="inline-flex h-14 items-center rounded-xl border border-zinc-200">
                            <button type="button" data-step="-1" class="flex h-full w-11 items-center justify-center text-zinc-500 hover:text-ink" aria-label="Azalt"><?= icon('minus', 'size-4', '2') ?></button>
                            <input type="number" name="qty" value="1" min="1" max="<?= max(1, (int) $product['stock']) ?>" class="h-full w-10 bg-transparent text-center font-semibold focus:outline-none" aria-label="Adet">
                            <button type="button" data-step="1" class="flex h-full w-11 items-center justify-center text-zinc-500 hover:text-ink" aria-label="Artır"><?= icon('plus', 'size-4', '2') ?></button>
                        </div>
                        <button data-add-button class="btn-primary h-14 flex-1 text-base" <?= $in_stock ? '' : 'disabled' ?>><?= icon('bag', 'size-5') ?>Sepete ekle</button>
                    </div>
                </form>

                <form method="post" action="<?= url('favori') ?>" data-ajax class="mt-3">
                    <?= csrf_field() ?>
                    <input type="hidden" name="id" value="<?= $product['id'] ?>">
                    <button data-favorite="<?= $product['id'] ?>" <?= is_favorite($product['id']) ? 'data-active' : '' ?> class="btn-light group h-12 w-full data-active:border-rose-200 data-active:text-rose-600 [&[data-active]_svg]:fill-current">
                        <?= icon('heart', 'size-5') ?>
                        <span class="group-data-active:hidden">Favorilere ekle</span>
                        <span class="hidden group-data-active:inline">Favorilerde</span>
                    </button>
                </form>

                <ul class="mt-8 divide-y divide-zinc-100 rounded-2xl border border-zinc-200 text-sm">
                    <li class="flex items-center gap-4 px-5 py-4"><?= icon('truck', 'size-5 text-zinc-500') ?><span><?= setting('free_shipping_limit') > 0 ? '<strong class="font-semibold">' . money(setting('free_shipping_limit')) . '</strong> üzeri ücretsiz kargo' : '1-3 iş gününde kargoda' ?></span></li>
                    <li class="flex items-center gap-4 px-5 py-4"><?= icon('refresh', 'size-5 text-zinc-500') ?><span>14 gün içinde <strong class="font-semibold">ücretsiz iade</strong></span></li>
                    <li class="flex items-center gap-4 px-5 py-4"><?= icon('shield', 'size-5 text-zinc-500') ?><span>Güvenli ödeme, kapıda ödeme seçeneği</span></li>
                </ul>
            </div>
        </div>
    </div>
</section>

<section id="yorumlar" class="container-x mt-24 scroll-mt-28" data-tabs>
    <div class="<?= $tabs ? 'flex' : 'hidden' ?> flex-wrap gap-8 border-b border-zinc-200">
        <?php foreach (['aciklama' => 'Açıklama', 'yorumlar' => 'Değerlendirmeler (' . count($reviews) . ')', 'teslimat' => 'Teslimat ve iade'] as $key => $label): ?>
            <button type="button" data-tab="<?= $key ?>" <?= $key === 'aciklama' ? 'data-active' : '' ?> class="-mb-px border-b-2 border-transparent pb-4 text-sm font-semibold text-zinc-500 transition hover:text-ink data-active:border-ink data-active:text-ink"><?= $label ?></button>
        <?php endforeach ?>
    </div>

    <div data-panel="aciklama" class="max-w-3xl py-10 text-[15px] leading-8 text-zinc-700">
        <?php if (!$tabs): ?><h2 class="heading mb-4 text-2xl font-semibold">Açıklama</h2><?php endif ?>
        <?= $product['description'] ? nl2br(e($product['description'])) : '<p class="text-zinc-500">Bu ürün için açıklama eklenmemiş.</p>' ?>
    </div>

    <div data-panel="yorumlar" class="<?= $tabs ? 'hidden' : 'border-t border-zinc-200' ?> py-10">
        <?php if (!$tabs): ?><h2 class="heading mb-8 text-2xl font-semibold">Değerlendirmeler (<?= count($reviews) ?>)</h2><?php endif ?>
        <div class="grid gap-12 lg:grid-cols-12">
            <div class="lg:col-span-4">
                <div class="rounded-3xl bg-soft p-8">
                    <p class="font-display text-6xl font-semibold tracking-tight"><?= number_format($product['rating'], 1, ',', '') ?></p>
                    <div class="mt-3"><?= stars($product['rating'], 'size-5') ?></div>
                    <p class="mt-2 text-sm text-zinc-500"><?= count($reviews) ?> değerlendirme</p>
                    <div class="mt-6 space-y-2">
                        <?php foreach ($breakdown as $score => $count): ?>
                            <div class="flex items-center gap-3 text-xs text-zinc-500">
                                <span class="w-3"><?= $score ?></span>
                                <div class="h-1.5 flex-1 overflow-hidden rounded-full bg-zinc-200">
                                    <div class="h-full rounded-full bg-amber-400" style="width: <?= $reviews ? round($count / count($reviews) * 100) : 0 ?>%"></div>
                                </div>
                                <span class="w-5 text-right"><?= $count ?></span>
                            </div>
                        <?php endforeach ?>
                    </div>
                </div>

                <div class="mt-6">
                    <?php if ($can_review): ?>
                        <form method="post" action="<?= url('yorum') ?>" data-ajax class="space-y-4 rounded-3xl border border-zinc-200 p-6">
                            <?= csrf_field() ?>
                            <input type="hidden" name="id" value="<?= $product['id'] ?>">
                            <p class="font-semibold text-ink">Ürünü değerlendirin</p>
                            <div class="flex flex-row-reverse justify-end gap-1">
                                <?php for ($i = 5; $i >= 1; $i--): ?>
                                    <input type="radio" name="rating" value="<?= $i ?>" id="puan<?= $i ?>" class="peer sr-only" <?= $i === 5 ? 'checked' : '' ?>>
                                    <label for="puan<?= $i ?>" class="peer cursor-pointer text-zinc-200 transition peer-checked:text-amber-400 hover:text-amber-300 peer-hover:text-amber-300"><?= star_icon('size-7') ?></label>
                                <?php endfor ?>
                            </div>
                            <textarea name="comment" rows="4" class="input" placeholder="Ürün hakkındaki düşünceleriniz" required minlength="10"></textarea>
                            <button class="btn-primary w-full">Değerlendirmeyi gönder</button>
                            <p class="text-xs text-zinc-500">Yorumunuz onaylandıktan sonra yayınlanır.</p>
                        </form>
                    <?php elseif (!is_customer()): ?>
                        <p class="rounded-2xl border border-zinc-200 p-5 text-sm text-zinc-600">Değerlendirme yapmak için <a href="<?= url('giris') ?>" class="font-semibold text-ink underline underline-offset-4">giriş yapın</a>.</p>
                    <?php endif ?>
                </div>
            </div>

            <div class="lg:col-span-8">
                <?php if ($reviews): ?>
                    <ul class="divide-y divide-zinc-100">
                        <?php foreach ($reviews as $review): ?>
                            <li class="py-6 first:pt-0">
                                <div class="flex items-center justify-between gap-4">
                                    <div class="flex items-center gap-3">
                                        <span class="flex size-10 items-center justify-center rounded-full bg-zinc-100 text-sm font-semibold text-zinc-600"><?= e(mb_substr($review['name'], 0, 1)) ?></span>
                                        <div>
                                            <p class="text-sm font-semibold text-ink"><?= e($review['name']) ?></p>
                                            <p class="text-xs text-zinc-500"><?= date_tr($review['created_at']) ?></p>
                                        </div>
                                    </div>
                                    <?= stars($review['rating']) ?>
                                </div>
                                <p class="mt-4 text-[15px] leading-7 text-zinc-700"><?= nl2br(e($review['comment'])) ?></p>
                            </li>
                        <?php endforeach ?>
                    </ul>
                <?php else: ?>
                    <?php empty_state('chat', 'Henüz değerlendirme yok', 'Bu ürünü ilk değerlendiren siz olun.') ?>
                <?php endif ?>
            </div>
        </div>
    </div>

    <div data-panel="teslimat" class="<?= $tabs ? 'hidden' : 'border-t border-zinc-200' ?> max-w-3xl space-y-4 py-10 text-[15px] leading-8 text-zinc-700">
        <?php if (!$tabs): ?><h2 class="heading mb-4 text-2xl font-semibold">Teslimat ve iade</h2><?php endif ?>
        <p>Siparişleriniz 1-3 iş günü içinde özenle paketlenip kargoya teslim edilir. <?= setting('free_shipping_limit') > 0 ? money(setting('free_shipping_limit')) . ' ve üzeri siparişlerde kargo ücretsizdir.' : '' ?></p>
        <p>Ürünü teslim aldığınız tarihten itibaren 14 gün içinde, kullanılmamış ve orijinal ambalajında olması koşuluyla iade edebilirsiniz.</p>
    </div>
</section>

<?php if ($related): ?>
    <section class="container-x mt-20">
        <?php section_title('Bunları da beğenebilirsiniz', $category ? category_url($category) : null) ?>
        <?php product_grid($related) ?>
    </section>
<?php endif ?>

<?php view_footer() ?>

Lisans bilgisi projenin LICENSE dosyasında.