e6a373f016
Titel und Claim wie auf den neuen Etiketten: Honig-Lakritz, -Bonbons, -Doppelbärchen, -Waffeln (je "Honig. Aber Anders." über dem Titel), Honig-Balsamico mit Herstellung und Empfehlung, Honig-Seife (die Pflegeseife mit Milch und Honig). Die Produktseite zeigt dafür den Claim (subtitle) unter dem Titel und metadata.label statt des Kategorienamens darüber — bisher gab es beides nur bei den Honigsorten. Die Beschreibungen der Snacks bleiben, dort stehen Zutaten und Nährwerte. Gesetzt über src/scripts/produkttexte-2026.ts, mehrfach ausführbar. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
358 lines
16 KiB
Plaintext
358 lines
16 KiB
Plaintext
---
|
|
import Layout from "../../layouts/Layout.astro";
|
|
import AddToCartButton from "../../components/AddToCartButton.astro";
|
|
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";
|
|
import { PRIMARY_DOMAIN } from "../../lib/sections";
|
|
|
|
export const prerender = false;
|
|
|
|
const { handle } = Astro.params;
|
|
const region = await getDefaultRegion();
|
|
const product = handle ? await getProductByHandle(handle, region.id) : null;
|
|
|
|
if (!product) {
|
|
return Astro.redirect("/shop");
|
|
}
|
|
|
|
const infoByVariant = Object.fromEntries(
|
|
product.variants.map((variant) => [
|
|
variant.id,
|
|
{
|
|
price: variant.calculated_price ? formatEUR(variant.calculated_price.calculated_amount) : "",
|
|
grundpreis:
|
|
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();
|
|
|
|
// Strukturierte Daten für Suchmaschinen: Damit in der Trefferliste Preis und
|
|
// Verfügbarkeit stehen können und nicht nur ein blauer Link. Jede Variante
|
|
// wird als eigenes Angebot ausgewiesen, weil sich die Preise unterscheiden.
|
|
// Die Brotkrumen darunter zeigen, wo die Seite im Shop hängt.
|
|
const angebote = product.variants
|
|
.filter((v) => v.calculated_price)
|
|
.map((v) => ({
|
|
"@type": "Offer",
|
|
name: v.title,
|
|
price: (v.calculated_price!.calculated_amount).toFixed(2),
|
|
priceCurrency: "EUR",
|
|
availability: "https://schema.org/InStock",
|
|
url: `${PRIMARY_DOMAIN}/shop/${product.handle}`,
|
|
itemCondition: "https://schema.org/NewCondition",
|
|
}));
|
|
|
|
const produktDaten = {
|
|
"@context": "https://schema.org",
|
|
"@type": "Product",
|
|
name: product.title,
|
|
description: product.description ?? product.title,
|
|
image: gallery.map((bild) => (bild.startsWith("http") ? bild : `${PRIMARY_DOMAIN}${bild}`)),
|
|
brand: { "@type": "Brand", name: "PLACE4BEES" },
|
|
...(angebote.length === 1 ? { offers: angebote[0] } : {}),
|
|
...(angebote.length > 1
|
|
? {
|
|
offers: {
|
|
"@type": "AggregateOffer",
|
|
priceCurrency: "EUR",
|
|
lowPrice: Math.min(...angebote.map((a) => Number(a.price))).toFixed(2),
|
|
highPrice: Math.max(...angebote.map((a) => Number(a.price))).toFixed(2),
|
|
offerCount: angebote.length,
|
|
offers: angebote,
|
|
},
|
|
}
|
|
: {}),
|
|
};
|
|
|
|
const brotkrumenDaten = {
|
|
"@context": "https://schema.org",
|
|
"@type": "BreadcrumbList",
|
|
itemListElement: [
|
|
{ "@type": "ListItem", position: 1, name: "Shop", item: `${PRIMARY_DOMAIN}/shop` },
|
|
...(categoryName ? [{ "@type": "ListItem", position: 2, name: categoryName }] : []),
|
|
{
|
|
"@type": "ListItem",
|
|
position: categoryName ? 3 : 2,
|
|
name: product.title,
|
|
item: `${PRIMARY_DOMAIN}/shop/${product.handle}`,
|
|
},
|
|
],
|
|
};
|
|
---
|
|
|
|
<Layout title={product.title} description={product.description ?? product.title}>
|
|
<script type="application/ld+json" is:inline set:html={JSON.stringify(produktDaten)} />
|
|
<script type="application/ld+json" is:inline set:html={JSON.stringify(brotkrumenDaten)} />
|
|
<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-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 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] : (product.metadata?.label ?? categoryName)}
|
|
</span>
|
|
<h1 class="mt-5 text-h2">{product.title}</h1>
|
|
{(variety?.subline ?? product.subtitle) && (
|
|
<p class="mt-3 text-lede text-brand-text">{variety?.subline ?? product.subtitle}</p>
|
|
)}
|
|
|
|
<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>
|
|
|
|
{/* 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>
|
|
Zurück zum Shop
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<script type="application/json" id="variant-info" set:html={JSON.stringify(infoByVariant)} />
|
|
</Layout>
|
|
|
|
<script>
|
|
// 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");
|
|
|
|
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;
|
|
|
|
// 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);
|
|
});
|
|
}
|
|
|
|
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>
|