aktueller stand
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
---
|
||||
import Layout from "../../layouts/Layout.astro";
|
||||
import AddToCartButton from "../../components/AddToCartButton.astro";
|
||||
import { getProductByHandle, getDefaultRegion } from "../../lib/medusa";
|
||||
import { formatEUR, formatGrundpreis } from "../../lib/format";
|
||||
import SubscriptionOptions from "../../components/SubscriptionOptions.astro";
|
||||
import SponsorshipOptions from "../../components/SponsorshipOptions.astro";
|
||||
import GiftVoucherOptions from "../../components/GiftVoucherOptions.astro";
|
||||
import { getProductByHandle, getDefaultRegion, listHoneyVarieties, getShopSettings, getGiftShippingSurcharge } from "../../lib/medusa";
|
||||
import { formatEUR, formatEURKurz, formatGrundpreis } from "../../lib/format";
|
||||
import { findVariety, COLLECTION_LABELS } from "../../lib/varieties";
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
@@ -23,90 +27,216 @@ const infoByVariant = Object.fromEntries(
|
||||
variant.calculated_price && variant.metadata?.net_weight_grams
|
||||
? formatGrundpreis(variant.calculated_price.calculated_amount, variant.metadata.net_weight_grams)
|
||||
: null,
|
||||
// Only set in the Medusa admin per variant (Produkt → Variante →
|
||||
// Bild) — most variants don't have one yet, so the gallery simply
|
||||
// doesn't switch for those until someone assigns one.
|
||||
image: variant.thumbnail ?? null,
|
||||
},
|
||||
])
|
||||
);
|
||||
const initial = infoByVariant[product.variants[0]?.id] ?? { price: "", grundpreis: null };
|
||||
const deliveryTime = product.metadata?.delivery_time;
|
||||
const categoryName = product.categories?.[0]?.name;
|
||||
|
||||
const gallery = (product.images?.length ? product.images.map((i) => i.url) : product.thumbnail ? [product.thumbnail] : []);
|
||||
|
||||
// Beim Abo-Produkt kommt die Sortenauswahl dazu. Sie ist keine Variante,
|
||||
// sondern reist als Metadatum am Warenkorb-Posten mit.
|
||||
const isSubscription = Boolean(product.metadata?.subscription);
|
||||
// Die Patenschaft braucht Angaben, die keine Bestellung mitbringt: einen
|
||||
// Namen für Urkunde und Etikett, beim Geschenk die Adresse des Beschenkten.
|
||||
const isSponsorship = Boolean(product.metadata?.sponsorship);
|
||||
// Der Geschenkgutschein kommt per E-Mail: kein Versand, keine Lieferzeit,
|
||||
// dafür wahlweise die Adresse des Beschenkten.
|
||||
const isGiftVoucher = Boolean(product.metadata?.gift_voucher);
|
||||
const honeyVarieties = isSubscription ? await listHoneyVarieties(region.id) : [];
|
||||
|
||||
// Beim Geschenk-Abo: ob jedes Paket seinen Versand trägt. Steht als
|
||||
// Metadatum am Abo-Produkt und ist im Admin änderbar.
|
||||
const giftShippingPerDelivery = product.metadata?.gift_shipping === "per_delivery";
|
||||
const giftSurcharge = isSubscription && giftShippingPerDelivery
|
||||
? await getGiftShippingSurcharge(region.id)
|
||||
: null;
|
||||
|
||||
const variety = findVariety(product.title);
|
||||
|
||||
// Aus den Shop-Einstellungen, damit hier nichts steht, was an der Kasse
|
||||
// nicht gilt.
|
||||
const { freeShippingThreshold } = await getShopSettings();
|
||||
---
|
||||
|
||||
<Layout title={product.title} description={product.description ?? product.title}>
|
||||
<section class="mx-auto max-w-6xl px-4 sm:px-6 lg:px-8 py-8 sm:py-12">
|
||||
<nav class="flex items-center gap-2 text-sm text-brand-text-muted">
|
||||
<a href="/shop" class="hover:text-brand-primary transition-colors">Shop</a>
|
||||
<span>/</span>
|
||||
{product.metadata?.category && (
|
||||
<>
|
||||
<span>{product.metadata.category}</span>
|
||||
<span>/</span>
|
||||
</>
|
||||
)}
|
||||
<span class="text-brand-text">{product.title}</span>
|
||||
</nav>
|
||||
<section class="brand-section bg-brand-surface-strong pt-24 pb-[var(--section-y)] sm:pt-28">
|
||||
<div class="mx-auto max-w-[84rem] px-[var(--gutter)]">
|
||||
<nav aria-label="Brotkrumen" class="flex flex-wrap items-center gap-2 text-sm text-brand-text-muted">
|
||||
<a href="/shop" class="transition-colors hover:text-brand-ink">Shop</a>
|
||||
<span aria-hidden="true">/</span>
|
||||
{categoryName && (
|
||||
<>
|
||||
<span>{categoryName}</span>
|
||||
<span aria-hidden="true">/</span>
|
||||
</>
|
||||
)}
|
||||
<span class="text-brand-ink" aria-current="page">{product.title}</span>
|
||||
</nav>
|
||||
|
||||
<div class="mt-8 grid gap-12 sm:grid-cols-2">
|
||||
<div>
|
||||
<div id="main-image" class="aspect-square rounded-2xl bg-brand-surface overflow-hidden">
|
||||
{gallery[0] && <img src={gallery[0]} alt={product.title} class="h-full w-full object-cover" />}
|
||||
</div>
|
||||
{gallery.length > 1 && (
|
||||
<div class="mt-4 flex gap-3">
|
||||
{gallery.map((url, index) => (
|
||||
<button
|
||||
class:list={[
|
||||
"gallery-thumb h-16 w-16 rounded-lg overflow-hidden ring-2 transition-colors",
|
||||
index === 0 ? "ring-brand-primary" : "ring-transparent",
|
||||
]}
|
||||
data-src={url}
|
||||
>
|
||||
<img src={url} alt="" class="h-full w-full object-cover" />
|
||||
</button>
|
||||
))}
|
||||
<div class="mt-10 grid gap-12 lg:grid-cols-12 lg:gap-16">
|
||||
<div class="lg:col-span-7">
|
||||
{/* Auf großen Schirmen steht die Bildreihe hochkant neben dem
|
||||
Bild statt darunter — so bleibt das Hauptbild größer. */}
|
||||
<div class="flex flex-col gap-4 lg:sticky lg:top-28 lg:flex-row">
|
||||
<div id="main-image" class="order-1 aspect-square min-w-0 flex-1 overflow-hidden rounded-[var(--radius-card)] bg-brand-surface-sunk lg:order-2">
|
||||
{gallery[0] && (
|
||||
<img
|
||||
src={gallery[0]}
|
||||
alt={product.title}
|
||||
transition:name={`p-${product.handle}`}
|
||||
class="h-full w-full object-cover"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{gallery.length > 1 && (
|
||||
<div class="order-2 flex shrink-0 gap-3 lg:order-1 lg:flex-col" role="group" aria-label="Weitere Produktbilder">
|
||||
{gallery.map((url, index) => (
|
||||
<button
|
||||
type="button"
|
||||
class:list={[
|
||||
"gallery-thumb h-20 w-20 overflow-hidden rounded-[var(--radius-inner)] ring-2 ring-offset-2 ring-offset-brand-surface-strong transition-[box-shadow,transform] duration-200 ease-out hover:-translate-y-0.5",
|
||||
index === 0 ? "ring-brand-primary" : "ring-transparent",
|
||||
]}
|
||||
data-src={url}
|
||||
>
|
||||
<span class="sr-only">Bild {index + 1} anzeigen</span>
|
||||
<img src={url} alt="" class="h-full w-full object-cover" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{product.metadata?.category && (
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.2em] text-brand-accent">{product.metadata.category}</p>
|
||||
)}
|
||||
<h1 class="mt-2 text-3xl font-semibold text-brand-ink">{product.title}</h1>
|
||||
|
||||
<div class="mt-3 flex items-baseline gap-3">
|
||||
<p id="product-price" class="text-2xl font-semibold text-brand-primary">{initial.price}</p>
|
||||
<span class="text-sm text-brand-text-muted">inkl. MwSt.</span>
|
||||
</div>
|
||||
<p id="product-grundpreis" class="mt-1 text-sm text-brand-text-muted">{initial.grundpreis ?? ""}</p>
|
||||
|
||||
<p class="mt-6 text-brand-text whitespace-pre-line">{product.description}</p>
|
||||
|
||||
<div class="mt-8">
|
||||
<AddToCartButton variants={product.variants} regionId={region.id} />
|
||||
</div>
|
||||
|
||||
<div class="mt-8 grid gap-3 sm:grid-cols-2">
|
||||
{deliveryTime && (
|
||||
<p class="flex items-center gap-2 text-sm text-brand-text-muted">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
|
||||
</svg>
|
||||
Lieferzeit: {deliveryTime}
|
||||
</p>
|
||||
<div class="lg:col-span-5">
|
||||
{/* Bei Honig steht die Kollektion aus dem Briefing über der
|
||||
Kategorie — "Urban Collection" sagt mehr als "Honig". */}
|
||||
<span
|
||||
class:list={["section-label", variety && "section-label-sorte"]}
|
||||
style={variety ? `--sorte: ${variety.color}` : undefined}
|
||||
>
|
||||
{variety ? COLLECTION_LABELS[variety.collection] : categoryName}
|
||||
</span>
|
||||
<h1 class="mt-5 text-h2">{product.title}</h1>
|
||||
{variety?.subline && (
|
||||
<p class="mt-3 text-lede text-brand-text">{variety.subline}</p>
|
||||
)}
|
||||
<p class="flex items-center gap-2 text-sm text-brand-text-muted">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
Regional aus Hamburg
|
||||
|
||||
<div class="mt-6 flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
||||
<p id="product-price" class="font-display text-[2rem] font-normal tabular-nums tracking-[0.01em] text-brand-ink">
|
||||
{initial.price}
|
||||
</p>
|
||||
{/* Die Preisangabenverordnung verlangt beides: den Hinweis auf
|
||||
die enthaltene Umsatzsteuer UND darauf, dass Versandkosten
|
||||
hinzukommen, samt Verweis auf die Einzelheiten. Bisher stand
|
||||
hier nur die Umsatzsteuer. */}
|
||||
<span class="text-sm text-brand-text-muted">
|
||||
{/* Auf einer Zeile: ein Umbruch vor dem Verweis wird beim
|
||||
Übersetzen verschluckt, dann klebt „zzgl.Versandkosten". */}
|
||||
{isGiftVoucher
|
||||
? "inkl. MwSt. · Versand per E-Mail, ohne Versandkosten"
|
||||
: <>inkl. MwSt. zzgl. <a href="/versand" class="underline underline-offset-2 hover:text-brand-ink">Versandkosten</a></>}
|
||||
</span>
|
||||
</div>
|
||||
<p id="product-grundpreis" class="mt-1 text-sm tabular-nums text-brand-text-muted">
|
||||
{initial.grundpreis ?? ""}
|
||||
</p>
|
||||
<p class="flex items-center gap-2 text-sm text-brand-text-muted">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
||||
|
||||
{/* Die Eckdaten standen bisher als Tabelle unter dem Kaufknopf und
|
||||
damit hinter der Entscheidung. Jetzt stehen sie davor. */}
|
||||
<ul class="eckdaten mt-8">
|
||||
{freeShippingThreshold != null && !isGiftVoucher && (
|
||||
<li>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="M8.5 12.2l2.4 2.4 4.6-5" stroke-linecap="round" stroke-linejoin="round" />
|
||||
</svg>
|
||||
Versandkostenfrei ab {formatEURKurz(freeShippingThreshold)}
|
||||
</li>
|
||||
)}
|
||||
{isGiftVoucher && (
|
||||
<li>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" aria-hidden="true">
|
||||
<rect x="3" y="5" width="18" height="14" rx="1.5" />
|
||||
<path d="M3.5 6l8.5 7 8.5-7" stroke-linejoin="round" />
|
||||
</svg>
|
||||
Per E-Mail nach Zahlungseingang
|
||||
</li>
|
||||
)}
|
||||
{isGiftVoucher && (
|
||||
<li>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="M8.5 12.2l2.4 2.4 4.6-5" stroke-linecap="round" stroke-linejoin="round" />
|
||||
</svg>
|
||||
Restguthaben bleibt erhalten
|
||||
</li>
|
||||
)}
|
||||
{deliveryTime && !isGiftVoucher && (
|
||||
<li>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" aria-hidden="true">
|
||||
<rect x="1" y="6" width="14" height="11" rx="1.5" />
|
||||
<path d="M15 10h4l3 3.5V17h-7z" />
|
||||
<circle cx="6" cy="19" r="1.6" />
|
||||
<circle cx="17.5" cy="19" r="1.6" />
|
||||
</svg>
|
||||
Lieferzeit {deliveryTime}
|
||||
</li>
|
||||
)}
|
||||
<li>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" aria-hidden="true">
|
||||
<path d="M12 21s7-6.2 7-11a7 7 0 1 0-14 0c0 4.8 7 11 7 11z" stroke-linejoin="round" />
|
||||
<circle cx="12" cy="10" r="2.5" />
|
||||
</svg>
|
||||
Regional aus Hamburg
|
||||
</li>
|
||||
<li>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" aria-hidden="true">
|
||||
<path d="M12 20c0-6 3.5-9.5 8-10-.5 6-4 9.5-8 10z" stroke-linejoin="round" />
|
||||
<path d="M12 20c0-4.5-2.5-7.5-6-8 .4 4.5 3 7.5 6 8z" stroke-linejoin="round" />
|
||||
<path d="M12 20v-3" stroke-linecap="round" />
|
||||
</svg>
|
||||
Nachhaltig, von Hand abgefüllt
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div>
|
||||
{isSponsorship && <SponsorshipOptions />}
|
||||
{isGiftVoucher && <GiftVoucherOptions />}
|
||||
{isSubscription && (
|
||||
<SubscriptionOptions
|
||||
varieties={honeyVarieties}
|
||||
variants={product.variants}
|
||||
giftSurcharge={giftSurcharge}
|
||||
/>
|
||||
)}
|
||||
<AddToCartButton
|
||||
variants={product.variants}
|
||||
regionId={region.id}
|
||||
showQuantity={!isSubscription}
|
||||
isSponsorship={isSponsorship}
|
||||
isGiftVoucher={isGiftVoucher}
|
||||
giftSurchargeVariantId={giftSurcharge?.variantId ?? null}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Die Beschreibung folgt dem Kaufknopf: wer sie liest, hat den
|
||||
Preis schon gesehen, und der Knopf rutscht nicht unter den Rand. */}
|
||||
<p class="mt-12 max-w-[52ch] text-[1.0625rem] leading-[1.75] whitespace-pre-line text-brand-text">{product.description}</p>
|
||||
|
||||
<a href="/shop" class="link-underline mt-10">
|
||||
<svg viewBox="0 0 20 20" class="h-4 w-4 rotate-180 text-brand-primary" fill="none" stroke="currentColor" stroke-width="1.75" aria-hidden="true">
|
||||
<path d="M4 10h12M11 5l5 5-5 5" stroke-linecap="round" stroke-linejoin="round" />
|
||||
</svg>
|
||||
Nachhaltig produziert
|
||||
</p>
|
||||
Zurück zum Shop
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -116,31 +246,56 @@ const gallery = (product.images?.length ? product.images.map((i) => i.url) : pro
|
||||
</Layout>
|
||||
|
||||
<script>
|
||||
const priceEl = document.getElementById("product-price");
|
||||
const grundpreisEl = document.getElementById("product-grundpreis");
|
||||
const infoJson = document.getElementById("variant-info")?.textContent;
|
||||
// astro:page-load feuert beim ersten Laden und nach jedem
|
||||
// View-Transition-Wechsel.
|
||||
document.addEventListener("astro:page-load", () => {
|
||||
const priceEl = document.getElementById("product-price");
|
||||
const grundpreisEl = document.getElementById("product-grundpreis");
|
||||
const infoJson = document.getElementById("variant-info")?.textContent;
|
||||
const mainImageContainer = document.getElementById("main-image");
|
||||
|
||||
if (priceEl && grundpreisEl && infoJson) {
|
||||
const info: Record<string, { price: string; grundpreis: string | null }> = JSON.parse(infoJson);
|
||||
document.querySelectorAll<HTMLInputElement>('input[name="variant"]').forEach((input) => {
|
||||
input.addEventListener("change", () => {
|
||||
const entry = info[input.value];
|
||||
priceEl.textContent = entry?.price ?? "";
|
||||
grundpreisEl.textContent = entry?.grundpreis ?? "";
|
||||
});
|
||||
});
|
||||
}
|
||||
function selectImage(url: string | null | undefined) {
|
||||
if (!url || !mainImageContainer) return;
|
||||
let img = mainImageContainer.querySelector<HTMLImageElement>("img");
|
||||
if (!img) {
|
||||
img = document.createElement("img");
|
||||
img.className = "h-full w-full object-cover";
|
||||
mainImageContainer.appendChild(img);
|
||||
}
|
||||
img.src = url;
|
||||
|
||||
const mainImage = document.querySelector<HTMLImageElement>("#main-image img");
|
||||
document.querySelectorAll<HTMLButtonElement>(".gallery-thumb").forEach((thumb) => {
|
||||
thumb.addEventListener("click", () => {
|
||||
if (mainImage && thumb.dataset.src) mainImage.src = thumb.dataset.src;
|
||||
document.querySelectorAll(".gallery-thumb").forEach((t) => {
|
||||
t.classList.remove("ring-brand-primary");
|
||||
t.classList.add("ring-transparent");
|
||||
// Keep the thumbnail rail in sync if the newly selected image also
|
||||
// happens to be one of the gallery thumbnails.
|
||||
document.querySelectorAll<HTMLButtonElement>(".gallery-thumb").forEach((thumb) => {
|
||||
const matches = thumb.dataset.src === url;
|
||||
thumb.classList.toggle("ring-brand-primary", matches);
|
||||
thumb.classList.toggle("ring-transparent", !matches);
|
||||
});
|
||||
thumb.classList.remove("ring-transparent");
|
||||
thumb.classList.add("ring-brand-primary");
|
||||
}
|
||||
|
||||
if (priceEl && grundpreisEl && infoJson) {
|
||||
const info: Record<string, { price: string; grundpreis: string | null; image: string | null }> = JSON.parse(infoJson);
|
||||
document.querySelectorAll<HTMLInputElement>('input[name="variant"]').forEach((input) => {
|
||||
input.addEventListener("change", () => {
|
||||
const entry = info[input.value];
|
||||
priceEl.textContent = entry?.price ?? "";
|
||||
grundpreisEl.textContent = entry?.grundpreis ?? "";
|
||||
// Kurzes Überblenden, damit der neue Preis nicht einfach dasteht.
|
||||
for (const el of [priceEl, grundpreisEl]) {
|
||||
el.classList.remove("price-swap");
|
||||
void el.offsetWidth;
|
||||
el.classList.add("price-swap");
|
||||
}
|
||||
// Not every variant has its own image assigned in the admin yet —
|
||||
// when it doesn't, leave whichever photo is currently shown alone
|
||||
// rather than clearing it.
|
||||
if (entry?.image) selectImage(entry.image);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll<HTMLButtonElement>(".gallery-thumb").forEach((thumb) => {
|
||||
thumb.addEventListener("click", () => selectImage(thumb.dataset.src));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user