Neue Bienenwachskerzen mit Farbwahl, Honiglöffel unter Zubehör

Sieben handgemachte Kerzen lösen die alten aus der Shopify-Übernahme ab:
Bubble-Würfel, Regenbogen-, Tropfen-, Lampion-, Bubble-Stumpen-, Rillen-
und Tannenbaumkerze. Jede gibt es in Honiggelb und Elfenbeinweiß, als
Variante, damit die Farbe in der Bestellung steht; über der Auswahl steht
"Farbe" statt "Variante". Hauptbild ist jeweils das schlichte Paar aus
heller und dunkler Kerze, dazu das weihnachtliche.

Der Adventskranz wird nicht verkauft, seine Bilder stehen bei der
Rillenkerze. Das alte Produkt "Bienenwachskerzen" ist Entwurf, nicht
gelöscht. Der Honiglöffel steht in der neuen Kategorie "Zubehör".

Die Bilder liefert das Frontend aus, so kommen sie mit dem Image auf jedes
System, ohne Kopieren ins Upload-Volume. Die Daten bringt ein
Migrationsskript mit, das der migrate-Dienst beim Ausrollen einmal ausführt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
torbinus
2026-11-05 08:04:31 +01:00
parent f4b13e6018
commit 872535d17d
26 changed files with 376 additions and 1 deletions
@@ -0,0 +1,13 @@
/**
* Bringt die neuen Kerzen und den Honiglöffel auf jedes System.
*
* Medusa führt Dateien in diesem Ordner bei `medusa db:migrate` genau einmal
* aus — auf Test und Produktion erledigt das der migrate-Dienst beim
* Ausrollen. Die eigentliche Arbeit steht im Skript, das sich lokal auch von
* Hand wiederholen lässt.
*/
import kerzen from "../scripts/set-kerzenbilder";
export default async function ({ container }: any) {
await kerzen({ container });
}
@@ -0,0 +1,357 @@
/**
* Hängt die neuen Fotos an die Kerzen und den Honiglöffel.
*
* npx medusa exec ./src/scripts/set-kerzenbilder.ts
*
* Die vier Kerzen aus der Preisliste 9/2026 (setup-neu-2026.ts) bekommen
* ihre Bilder, einen stimmigen Namen und eine kurze Beschreibung und werden
* sichtbar.
*
* Sie lösen die alten Kerzen ab: Das Produkt "Bienenwachskerzen" (Bienenkorb,
* Wabenkerze, klassisch) wird Entwurf. Nicht gelöscht — Bestellungen und
* Varianten bleiben erhalten, im Admin lässt es sich wieder einschalten.
*
* Drei weitere Kerzen stehen nicht in der Preisliste. Ihre Preise sind an
* die vorhandenen Formen angelehnt und im Admin änderbar. Der Honiglöffel
* (Handle "honigdipper") steht in der eigenen Kategorie "Zubehör".
*
* Jede Kerze gibt es in zwei Farben, Honiggelb und Elfenbeinweiß. Die Farbe
* ist eine Variante (Option "Farbe"), damit sie in der Bestellung steht.
*
* Der Adventskranz wird nicht verkauft. Seine Bilder stehen in der Galerie
* der Rillenkerze, denn auf ihm stecken genau diese Kerzen.
*
* Vorn steht das schlichte Bild mit heller und dunkler Kerze gemeinsam, danach
* das weihnachtliche Paar. Das erste Bild ist zugleich das Hauptbild im
* Raster. Adressen ohne Domain, damit dieselben Daten im Heimnetz, auf dem
* Testsystem und in der Produktion stimmen.
*
* Auf Test und Produktion läuft das Skript beim Ausrollen von selbst, über
* src/migration-scripts/kerzen-und-honigloeffel.ts.
*
* Wiederholbar: Vorhandenes wird aktualisiert, nicht doppelt angelegt.
*/
import {
createAndLinkProductOptionsToProductWorkflow,
createProductCategoriesWorkflow,
createProductVariantsWorkflow,
createProductsWorkflow,
updateProductOptionsWorkflow,
updateProductOptionValuesWorkflow,
updateProductsWorkflow,
updateProductVariantsWorkflow,
} from "@medusajs/core-flows";
/** Nicht mehr im Shop: die abgelösten Kerzen aus der Shopify-Übernahme und
* der Adventskranz, der nur noch als Bild bei der Rillenkerze steht. */
const NICHT_IM_SHOP = ["bienenwachskerzen", "adventskranz"];
/** Die beiden Farben jeder Kerze; die erste ist vorausgewählt. */
const FARBEN = ["Honiggelb", "Elfenbeinweiß"];
/** Die Bilder liefert das Frontend aus (frontend/public/images/produkte).
* So kommen sie mit dem Frontend-Image auf jedes System, ohne Kopieren in
* das Upload-Volume des Backends. */
const BILDPFAD = "/images/produkte";
const PLATZHALTER = /\n*⚠️ Platzhalter:.*$/s;
/** Alle Kerzen sind handgemacht aus reinem Bienenwachs; der Titel sagt es
* im Muster der Honige ("Akazienhonig aus … - flüssig"). */
const PRODUKTE: {
handle: string;
titel: string;
kategorie: string;
/** Erstes Bild = Hauptbild: helle und dunkle Kerze gemeinsam, schlicht. */
aufnahmen: string[];
/** Nur für sichtbare Produkte, ersetzt den Platzhaltertext. */
beschreibung?: string;
/** Euro; gilt für alle Varianten. */
preis?: number;
/** Kerze in Honiggelb und Elfenbeinweiß. */
farben?: boolean;
sichtbar?: boolean;
}[] = [
// Schon vorhanden. Die Handles bleiben, damit Adressen stabil sind.
{
handle: "bubble-kerze",
titel: "Bubble-Würfel aus Bienenwachs - handgemacht",
kategorie: "Bienenprodukte",
aufnahmen: ["duo", "weihnacht"],
beschreibung: "Würfelkerze aus kleinen Wachskugeln, ca. 180 g. Handgemacht aus reinem Bienenwachs.",
preis: 9.9,
sichtbar: true,
farben: true,
},
{
handle: "regenbogen",
titel: "Regenbogenkerze aus Bienenwachs - handgemacht",
kategorie: "Bienenprodukte",
aufnahmen: ["duo", "weihnacht"],
beschreibung: "Kerze in Bogenform mit feinen Rillen. Handgemacht aus reinem Bienenwachs.",
preis: 7.9,
sichtbar: true,
farben: true,
},
// Eierform 1 ist die facettierte Tropfenform, Eierform 2 die gerippte Kugel.
{
handle: "eierform-1",
titel: "Tropfenkerze aus Bienenwachs - handgemacht",
kategorie: "Bienenprodukte",
aufnahmen: ["duo", "weihnacht"],
beschreibung: "Facettierte Kerze in Tropfenform. Handgemacht aus reinem Bienenwachs.",
preis: 5.5,
sichtbar: true,
farben: true,
},
{
handle: "eierform-2",
titel: "Lampionkerze aus Bienenwachs - handgemacht",
kategorie: "Bienenprodukte",
aufnahmen: ["duo", "weihnacht"],
beschreibung: "Runde, gerippte Kerze in Lampionform. Handgemacht aus reinem Bienenwachs.",
preis: 5.5,
sichtbar: true,
farben: true,
},
// Nicht in der Preisliste; Preise angelehnt an die vorhandenen Formen.
{
handle: "bubble-stumpenkerze",
titel: "Bubble-Stumpenkerze aus Bienenwachs - handgemacht",
kategorie: "Bienenprodukte",
aufnahmen: ["duo", "weihnacht"],
beschreibung: "Stumpenkerze mit Noppen-Oberfläche. Handgemacht aus reinem Bienenwachs.",
preis: 9.9,
sichtbar: true,
farben: true,
},
{
handle: "geriffelte-stumpenkerze",
titel: "Rillenkerze aus Bienenwachs - handgemacht",
kategorie: "Bienenprodukte",
aufnahmen: ["duo", "weihnacht", "adventskranz-gold", "adventskranz-elfenbein"],
beschreibung: "Stumpenkerze mit feinen Rillen und spitzer Krone. Handgemacht aus reinem Bienenwachs.",
preis: 7.9,
sichtbar: true,
farben: true,
},
// Von den Tannen gibt es nur weihnachtliche Paare.
{
handle: "bienenwachs-tannenbaum",
titel: "Tannenbaumkerze aus Bienenwachs - handgemacht",
kategorie: "Bienenprodukte",
aufnahmen: ["studio", "tafel", "sideboard"],
beschreibung: "Kerze in Tannenbaumform für die Weihnachtszeit. Handgemacht aus reinem Bienenwachs.",
preis: 5.5,
sichtbar: true,
farben: true,
},
// Keine Kerze: eigene Kategorie, ohne Farbwahl.
{
handle: "honigdipper",
titel: "Honiglöffel aus Holz",
kategorie: "Zubehör",
aufnahmen: ["studio", "wabe", "fruehstueck", "akazie"],
beschreibung:
"Honiglöffel aus Holz mit der Gravur „Honigliebe“. Die Rillen nehmen den Honig auf, " +
"er läuft nicht vom Löffel und tropft gezielt aufs Brot oder in den Tee.",
preis: 4.9,
sichtbar: true,
},
];
export default async function ({ container }: any) {
const query = container.resolve("query");
const logger = container.resolve("logger");
let { data: kategorien } = await query.graph({
entity: "product_category",
fields: ["id", "name", "rank"],
});
// Fehlende Kategorien (z. B. "Zubehör") hinten anhängen.
for (const name of new Set(PRODUKTE.map((p) => p.kategorie))) {
if ((kategorien ?? []).some((c: any) => c.name === name)) continue;
const rang = Math.max(0, ...(kategorien ?? []).map((c: any) => c.rank ?? 0)) + 1;
const handle = name.toLowerCase().replace("ö", "oe").replace(/[^a-z0-9]+/g, "-");
const { result } = await createProductCategoriesWorkflow(container).run({
input: { product_categories: [{ name, handle, is_active: true, rank: rang }] },
});
kategorien = [...(kategorien ?? []), (result as any)[0]];
logger.info(`Kategorie "${name}" angelegt.`);
}
const { data: profile } = await query.graph({ entity: "shipping_profile", fields: ["id"] });
const { data: kanaele } = await query.graph({ entity: "sales_channel", fields: ["id"] });
for (const p of PRODUKTE) {
const bilder = p.aufnahmen.map((a) => `${BILDPFAD}/produkt-${a}-${p.handle}.jpg`);
const kategorie = (kategorien ?? []).find((c: any) => c.name === p.kategorie);
const lesen = async () =>
(
await query.graph({
entity: "product",
fields: ["id", "title", "status", "description", "metadata", "variants.id"],
filters: { handle: p.handle },
})
).data?.[0];
// Fehlt das Produkt (etwa auf einem frischen System), zuerst als Entwurf
// anlegen; danach geht es für alle gleich weiter.
let produkt = await lesen();
if (!produkt) {
await createProductsWorkflow(container).run({
input: {
products: [
{
title: p.titel,
handle: p.handle,
status: "draft" as any,
description:
`${p.titel}.\n\n` +
"⚠️ Platzhalter: Beschreibung, Maße, Preis und Gewicht fehlen noch.",
shipping_profile_id: profile?.[0]?.id,
sales_channels: kanaele?.[0] ? [{ id: kanaele[0].id }] : undefined,
metadata: { category: p.kategorie, delivery_time: "2-3 Werktage" },
...(kategorie ? { category_ids: [kategorie.id] } : {}),
options: [{ title: "Ausführung", values: ["Standard"] }],
variants: [
{
title: "Standard",
options: { "Ausführung": "Standard" },
manage_inventory: false,
prices: p.preis !== undefined ? [{ amount: p.preis, currency_code: "eur" }] : [],
},
],
},
],
},
});
logger.info(`"${p.titel}" angelegt.`);
produkt = await lesen();
}
const update: any = {
title: p.titel,
category_ids: kategorie ? [kategorie.id] : undefined,
metadata: { ...(produkt.metadata ?? {}), category: p.kategorie },
thumbnail: bilder[0],
images: bilder.map((url: string) => ({ url })),
};
if (p.sichtbar) {
update.status = "published";
update.description = p.beschreibung ?? (produkt.description ?? "").replace(PLATZHALTER, "");
}
await updateProductsWorkflow(container).run({
input: { selector: { id: produkt.id }, update } as any,
});
if (p.preis !== undefined) {
for (const v of produkt.variants ?? []) {
await updateProductVariantsWorkflow(container).run({
input: {
selector: { id: v.id },
update: { prices: [{ amount: p.preis, currency_code: "eur" }] },
} as any,
});
}
}
if (p.farben) await farbenSetzen(container, produkt.id, p.preis);
logger.info(`"${p.titel}": ${bilder.length} Bilder (${update.status ?? produkt.status}).`);
}
for (const handle of NICHT_IM_SHOP) {
const { data: alt } = await query.graph({
entity: "product",
fields: ["id", "title", "status"],
filters: { handle },
});
if (alt?.[0] && alt[0].status !== "draft") {
await updateProductsWorkflow(container).run({
input: { selector: { id: alt[0].id }, update: { status: "draft" } } as any,
});
logger.info(`"${alt[0].title}" ist jetzt Entwurf und nicht mehr im Shop.`);
}
}
}
/**
* Macht aus der Option "Ausführung: Standard" die Option "Farbe" mit beiden
* Farben. Umbenennen statt ersetzen: Medusa lässt eine Option nicht los,
* solange Varianten an ihr hängen. Die vorhandene Variante wird Honiggelb
* (Bestellungen bleiben an ihr), Elfenbeinweiß kommt mit demselben Preis dazu.
*/
async function farbenSetzen(container: any, produktId: string, preis?: number) {
const query = container.resolve("query");
const lesen = async () =>
(
await query.graph({
entity: "product",
fields: [
"id",
"options.id",
"options.title",
"options.values.id",
"options.values.value",
"variants.id",
"variants.title",
"variants.prices.amount",
"variants.prices.currency_code",
],
filters: { id: produktId },
})
).data[0];
let produkt = await lesen();
const option = produkt.options.find((o: any) => ["Ausführung", "Farbe"].includes(o.title));
if (!option) throw new Error(`Produkt ${produktId}: keine Option "Ausführung" oder "Farbe".`);
if (option.title !== "Farbe") {
await updateProductOptionsWorkflow(container).run({
input: { selector: { id: option.id }, update: { title: "Farbe" } } as any,
});
}
const standard = option.values.find((v: any) => v.value === "Standard");
if (standard) {
await updateProductOptionValuesWorkflow(container).run({
input: { id: standard.id, update: { value: FARBEN[0] } },
});
}
produkt = await lesen();
const werte = produkt.options.find((o: any) => o.id === option.id).values.map((v: any) => v.value);
const fehlend = FARBEN.filter((f) => !werte.includes(f));
if (fehlend.length) {
await createAndLinkProductOptionsToProductWorkflow(container).run({
input: {
product_id: produktId,
update: [{ product_option_id: option.id, add: fehlend.map((value) => ({ value })) }],
},
});
}
const betrag =
preis ?? produkt.variants[0]?.prices?.find((x: any) => x.currency_code === "eur")?.amount;
const standardVariante = produkt.variants.find((v: any) => !FARBEN.includes(v.title));
if (standardVariante) {
await updateProductVariantsWorkflow(container).run({
input: { selector: { id: standardVariante.id }, update: { title: FARBEN[0] } } as any,
});
}
// Die alte Standard-Variante heißt nach dem Umbenennen Honiggelb.
const vorhanden = produkt.variants.map((v: any) =>
FARBEN.includes(v.title) ? v.title : FARBEN[0]
);
for (const farbe of FARBEN.filter((f) => !vorhanden.includes(f))) {
await createProductVariantsWorkflow(container).run({
input: {
product_variants: [
{
product_id: produktId,
title: farbe,
options: { Farbe: farbe },
manage_inventory: false,
prices: [{ amount: betrag, currency_code: "eur" }],
},
],
},
} as any);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

@@ -7,6 +7,8 @@ interface Variant {
interface Props {
variants: Variant[];
regionId: string;
/** Überschrift über der Variantenwahl, z. B. "Farbe" bei den Kerzen. */
variantLabel?: string;
/**
* Ob der Mengenwähler angezeigt wird. Beim Abo nicht: dort steht die Menge
* schon in der Sortenauswahl und steuert dort die Zahl der Gläser.
@@ -26,6 +28,7 @@ interface Props {
const {
variants,
regionId,
variantLabel = "Variante",
showQuantity = true,
giftSurchargeVariantId = null,
isSponsorship = false,
@@ -36,7 +39,7 @@ const {
<div>
{variants.length > 1 && (
<fieldset id="variant-picker" class="mb-7" aria-labelledby="variant-picker-label">
<p id="variant-picker-label" class="field-label">Variante</p>
<p id="variant-picker-label" class="field-label">{variantLabel}</p>
<div class="flex flex-wrap gap-2">
{variants.map((variant, index) => (
<label class="relative">
+1
View File
@@ -138,6 +138,7 @@ export interface MedusaProduct {
sponsorship?: boolean;
} | null;
categories?: { id: string; name: string; rank: number }[];
options?: { id: string; title: string }[];
}
// Pulls in the custom metadata (delivery time, net fill weight) and the
+1
View File
@@ -276,6 +276,7 @@ const brotkrumenDaten = {
<AddToCartButton
variants={product.variants}
regionId={region.id}
variantLabel={product.options?.some((option) => option.title === "Farbe") ? "Farbe" : undefined}
showQuantity={!isSubscription}
isSponsorship={isSponsorship}
isGiftVoucher={isGiftVoucher}