Neue Seife heißt Pflegeseife mit Milch und Honig

Dazu ein kurzer Beschreibungstext. Was noch fehlt, ist als Platzhalter
markiert: Gewicht, Duft und die Zutatenliste — letztere ist bei Seife
vorgeschrieben, bevor verkauft werden darf.

Das Skript findet den Entwurf auch unter seinem früheren Namen und
benennt ihn um, statt ein zweites Produkt anzulegen.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
torbinus
2026-10-12 13:07:17 +02:00
parent b78f1a0ea0
commit 9d58a90148
@@ -18,7 +18,19 @@ import {
} from "@medusajs/core-flows";
const KATEGORIE = "Pflegeprodukte";
const NEUE_SEIFE = "honigseife-neu";
const NEUE_SEIFE = "pflegeseife-milch-honig";
/** Der Entwurf hieß zunächst anders — damit ein erneuter Lauf ihn findet und
* umbenennt, statt ein zweites Produkt anzulegen. */
const FRUEHERE_HANDLES = ["honigseife-neu"];
const TITEL = "Pflegeseife mit Milch und Honig";
const BESCHREIBUNG =
"Pflegeseife mit Milch und Honig aus unserer Imkerei. " +
"Honig spendet Feuchtigkeit, Milch macht den Schaum weich und mild — " +
"angenehm für trockene Haut und für jeden Tag.\n\n" +
"⚠️ Platzhalter: Gewicht, Duftrichtung und die vollständige Zutatenliste " +
"fehlen noch. Bei Seife ist die Angabe der Inhaltsstoffe (INCI) " +
"vorgeschrieben, bevor sie verkauft werden darf.";
export default async function ({ container }: any) {
const query = container.resolve("query");
@@ -84,12 +96,22 @@ export default async function ({ container }: any) {
// 3. Die neue Seife.
const { data: neue } = await query.graph({
entity: "product",
fields: ["id", "title", "status", "thumbnail"],
filters: { handle: NEUE_SEIFE },
fields: ["id", "title", "handle", "status", "thumbnail"],
filters: { handle: [NEUE_SEIFE, ...FRUEHERE_HANDLES] },
});
if (neue?.[0]) {
const produkt = neue[0] as any;
if (produkt.handle !== NEUE_SEIFE || produkt.title !== TITEL) {
await updateProductsWorkflow(container).run({
input: {
selector: { id: produkt.id },
update: { title: TITEL, handle: NEUE_SEIFE, description: BESCHREIBUNG },
} as any,
});
logger.info(`Umbenannt in "${TITEL}".`);
}
// Sobald ein Bild hinterlegt ist, darf sie sichtbar werden.
if (produkt.thumbnail && produkt.status !== "published") {
await updateProductsWorkflow(container).run({
@@ -115,13 +137,11 @@ export default async function ({ container }: any) {
input: {
products: [
{
title: "Honigseife",
title: TITEL,
handle: NEUE_SEIFE,
// Entwurf, bis das Foto da ist.
status: "draft" as any,
description:
"Handgemachte Seife mit Honig aus unserer Imkerei. " +
"⚠️ Beschreibungstext ist ein Platzhalter und muss noch geschrieben werden.",
description: BESCHREIBUNG,
shipping_profile_id: profile?.[0]?.id,
sales_channels: kanaele?.[0] ? [{ id: kanaele[0].id }] : undefined,
metadata: { category: KATEGORIE, delivery_time: "2-3 Werktage" },
@@ -142,5 +162,5 @@ export default async function ({ container }: any) {
},
});
logger.info('Neue "Honigseife" angelegt: 8,90 €, Entwurf, wartet auf das Foto.');
logger.info(`"${TITEL}" angelegt: 8,90 €, Entwurf, wartet auf das Foto.`);
}