first commit

This commit is contained in:
torbinus
2026-07-06 13:37:08 +02:00
commit 7e51514383
171 changed files with 29200 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
import { medusaFetch } from "./medusa";
export interface MedusaCartItem {
id: string;
title: string;
thumbnail: string | null;
quantity: number;
unit_price: number;
}
export interface MedusaCart {
id: string;
email: string | null;
currency_code: string;
item_total: number;
items: MedusaCartItem[];
}
export interface MedusaShippingOption {
id: string;
name: string;
amount: number;
}
export async function createCart(regionId: string): Promise<MedusaCart> {
const data = await medusaFetch("/store/carts", {
method: "POST",
body: JSON.stringify({ region_id: regionId }),
});
return data.cart;
}
export async function getCart(cartId: string): Promise<MedusaCart> {
const data = await medusaFetch(`/store/carts/${cartId}`);
return data.cart;
}
export async function addLineItem(cartId: string, variantId: string, quantity = 1): Promise<MedusaCart> {
const data = await medusaFetch(`/store/carts/${cartId}/line-items`, {
method: "POST",
body: JSON.stringify({ variant_id: variantId, quantity }),
});
return data.cart;
}
export async function updateLineItem(cartId: string, lineId: string, quantity: number): Promise<MedusaCart> {
const data = await medusaFetch(`/store/carts/${cartId}/line-items/${lineId}`, {
method: "POST",
body: JSON.stringify({ quantity }),
});
return data.cart;
}
export async function removeLineItem(cartId: string, lineId: string): Promise<void> {
await medusaFetch(`/store/carts/${cartId}/line-items/${lineId}`, { method: "DELETE" });
}
interface CartAddress {
first_name: string;
last_name: string;
address_1: string;
postal_code: string;
city: string;
country_code: string;
}
export async function updateCart(
cartId: string,
payload: { email?: string; shipping_address?: CartAddress; billing_address?: CartAddress }
): Promise<MedusaCart> {
const data = await medusaFetch(`/store/carts/${cartId}`, {
method: "POST",
body: JSON.stringify(payload),
});
return data.cart;
}
export async function listShippingOptions(cartId: string): Promise<MedusaShippingOption[]> {
const data = await medusaFetch(`/store/shipping-options?cart_id=${cartId}`);
return data.shipping_options;
}
export async function addShippingMethod(cartId: string, optionId: string): Promise<MedusaCart> {
const data = await medusaFetch(`/store/carts/${cartId}/shipping-methods`, {
method: "POST",
body: JSON.stringify({ option_id: optionId }),
});
return data.cart;
}
export async function createPaymentCollection(cartId: string) {
const data = await medusaFetch("/store/payment-collections", {
method: "POST",
body: JSON.stringify({ cart_id: cartId }),
});
return data.payment_collection;
}
export async function createPaymentSession(paymentCollectionId: string, providerId: string) {
const data = await medusaFetch(`/store/payment-collections/${paymentCollectionId}/payment-sessions`, {
method: "POST",
body: JSON.stringify({ provider_id: providerId }),
});
return data.payment_collection;
}
export async function completeCart(cartId: string): Promise<{ type: "order" | "cart"; order?: any; cart?: any; error?: { message: string } }> {
return medusaFetch(`/store/carts/${cartId}/complete`, { method: "POST" });
}
+14
View File
@@ -0,0 +1,14 @@
export const CART_COOKIE_NAME = "cart_id";
export function getCartIdClient(): string | null {
const match = document.cookie.match(new RegExp(`(?:^|; )${CART_COOKIE_NAME}=([^;]*)`));
return match ? decodeURIComponent(match[1]) : null;
}
export function setCartIdClient(id: string) {
document.cookie = `${CART_COOKIE_NAME}=${encodeURIComponent(id)}; path=/; max-age=${60 * 60 * 24 * 30}; SameSite=Lax`;
}
export function clearCartIdClient() {
document.cookie = `${CART_COOKIE_NAME}=; path=/; max-age=0`;
}
+8
View File
@@ -0,0 +1,8 @@
export function formatEUR(amount: number): string {
return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(amount);
}
export function formatGrundpreis(amount: number, netWeightGrams: number): string {
const perKg = (amount / netWeightGrams) * 1000;
return `${formatEUR(perKg)}/kg`;
}
+67
View File
@@ -0,0 +1,67 @@
const BACKEND_URL = import.meta.env.PUBLIC_MEDUSA_BACKEND_URL;
const PUBLISHABLE_KEY = import.meta.env.PUBLIC_MEDUSA_PUBLISHABLE_KEY;
export async function medusaFetch(path: string, init?: RequestInit) {
const res = await fetch(`${BACKEND_URL}${path}`, {
...init,
headers: {
"Content-Type": "application/json",
"x-publishable-api-key": PUBLISHABLE_KEY,
...init?.headers,
},
});
const body = await res.json().catch(() => ({}));
if (!res.ok) {
throw new Error(body?.message || `Medusa request failed: ${path} (${res.status})`);
}
return body;
}
export interface MedusaVariant {
id: string;
title: string;
calculated_price?: { calculated_amount: number; currency_code: string };
metadata?: { net_weight_grams?: number } | null;
}
export interface MedusaProduct {
id: string;
title: string;
handle: string;
description: string | null;
thumbnail: string | null;
images?: { id: string; url: string }[];
variants: MedusaVariant[];
metadata?: { delivery_time?: string; category?: string } | null;
}
// Pulls in the custom metadata (delivery time, category, net fill weight) on
// top of Medusa's default product/variant fields.
const PRODUCT_FIELDS = "*variants.calculated_price,+metadata,+variants.metadata";
export async function listProducts(regionId?: string): Promise<MedusaProduct[]> {
const params = new URLSearchParams({ fields: PRODUCT_FIELDS });
if (regionId) params.set("region_id", regionId);
const data = await medusaFetch(`/store/products?${params}`);
return data.products;
}
export async function getProductByHandle(handle: string, regionId?: string): Promise<MedusaProduct | null> {
const params = new URLSearchParams({ handle, fields: PRODUCT_FIELDS });
if (regionId) params.set("region_id", regionId);
const data = await medusaFetch(`/store/products?${params}`);
return data.products[0] ?? null;
}
export interface MedusaRegion {
id: string;
currency_code: string;
}
export async function getDefaultRegion(): Promise<MedusaRegion> {
const data = await medusaFetch("/store/regions");
return data.regions[0];
}
+35
View File
@@ -0,0 +1,35 @@
export const partners = [
{ name: "ABB", file: "abb-3x2-1.png" },
{ name: "AdvoNeo", file: "advoneo-3x2-1.png" },
{ name: "ak.", file: "ak-3x2-1-smaller.png" },
{ name: "bp", file: "bp-3x2-1.png" },
{ name: "Coloplast", file: "coloplast_logo.png" },
{ name: "dentsu", file: "dentsu-3x2-1.png" },
{ name: "East Cosmos", file: "east-cosmos-3x2-1.png" },
{ name: "Edeka Harburg", file: "edeka_harburg.png" },
{ name: "Eggers", file: "eggers-3x2-1.png" },
{ name: "Empire Riverside Hotels", file: "empire-riverside-hotels-3x2-1.png" },
{ name: "Engel & Völkers", file: "engel-voelkers-3x2-1.png" },
{ name: "EY", file: "ey-3x2-1.png" },
{ name: "Fairplay", file: "fairplay-3x2-1.png" },
{ name: "Hamburger Feuerkasse", file: "hamburger_feuerkasse.png" },
{ name: "Hanseatic Bank", file: "hanseatic-bank-3x2-1.png" },
{ name: "International School of Hamburg", file: "international-school-of-hamburg-3x2-1.png" },
{ name: "Jung von Matt", file: "jungvmatt-3x2-1.png" },
{ name: "Kinderzimmer", file: "kinderzimmer.png" },
{ name: "Kontora", file: "kontora-3x2-1.png" },
{ name: "Lorentz", file: "lorentz-3x2-1.png" },
{ name: "Martha Haus", file: "martha_haus.png" },
{ name: "NKG", file: "nkg-3x2-1.png" },
{ name: "Nordmann", file: "nordmann-3x2-1.png" },
{ name: "Porsche Zentren", file: "porsche_zentren.png" },
{ name: "Private Banking", file: "private-banking-3x2-1.png" },
{ name: "Röder Stiftung", file: "roeder_stiftung.png" },
{ name: "Sund", file: "sund-3x2-1.png" },
{ name: "Stilwerks", file: "stilwerks-3x2-1-smaller.png" },
{ name: "Still", file: "still-3x2-1.png" },
{ name: "Seniorenzentren Geschwister Jensen", file: "senioren-zentren-geschwister-jensen-3x2-1.png" },
{ name: "Tews", file: "tews-3x2-1.png" },
{ name: "The Cloud One", file: "the_cloud_one.png" },
{ name: "ZF", file: "zf-3x2-1.png" },
];
+61
View File
@@ -0,0 +1,61 @@
export type Section = "private" | "business";
export const COMPANY_NAME = "place4bees";
/** Fixed canonical domain: all pages consolidate their SEO signal here, even
* though the site also resolves on hhonig.de (see Layout.astro). */
export const PRIMARY_DOMAIN = "https://place4bees.com";
interface SectionConfig {
label: string;
tagline: string;
/** Stable, host-independent path for this section's homepage. Always link
* here internally (never to bare "/") so switching sections behaves the
* same regardless of which domain a visitor is on. */
homeHref: string;
nav: { label: string; href: string }[];
}
export const sections: Record<Section, SectionConfig> = {
private: {
label: "Privatkunden",
tagline: "Regionaler Honig aus Hamburg",
homeHref: "/privatkunden",
nav: [
{ label: "Shop", href: "/shop" },
{ label: "Über uns", href: "/ueber-uns" },
{ label: "Kontakt", href: "/kontakt" },
],
},
business: {
label: "Business",
tagline: "Eigene Bienen vor Ort. Professionell betreut. Nachhaltig erlebbar.",
homeHref: "/business",
nav: [
{ label: "Ihr Projekt", href: "/business/ihr-projekt" },
{ label: "Über uns", href: "/business/ueber-uns" },
{ label: "Philosophie", href: "/business/philosophie" },
{ label: "Presse", href: "/business/presse" },
{ label: "Angebot", href: "/business/angebot" },
{ label: "Anfrage", href: "/business/anfrage" },
{ label: "Kontakt", href: "/business/kontakt" },
],
},
};
export function sectionForPath(pathname: string): Section {
return pathname.startsWith("/business") ? "business" : "private";
}
/** hhonig.de defaults to the private/B2C section, place4bees.com to business. */
export function isBusinessHost(hostname: string): boolean {
return hostname.includes("place4bees");
}
/** Resolves the active section for a request, accounting for the host-based
* default that only applies at the bare "/" root. */
export function resolveSection(pathname: string, hostname: string): Section {
if (pathname.startsWith("/business")) return "business";
if (pathname === "/" && isBusinessHost(hostname)) return "business";
return "private";
}