Einheitliche Produktfotos für acht Honigsorten

Je Sorte drei Aufnahmen: Studio, Frühstück, Outdoor, alle 1254 Pixel
quadratisch und frontal. Die Studio-Aufnahme wird das Hauptbild — im
Raster stehen die Kacheln dadurch ruhig nebeneinander, genau das war der
Wunsch. Die beiden inszenierten Aufnahmen bilden die Galerie auf der
Produktseite.

Die Adressen stehen ohne Domain in der Datenbank, damit dieselben Daten
im Heimnetz, auf dem Testsystem und in der Produktion stimmen.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
torbinus
2026-10-12 12:52:40 +02:00
parent 0cd133fce9
commit 706e472129
25 changed files with 97 additions and 0 deletions
@@ -0,0 +1,97 @@
/**
* Hängt die einheitlichen Produktfotos an die Honigsorten.
*
* npx medusa exec ./src/scripts/set-produktbilder.ts
*
* Von jeder Sorte gibt es drei Aufnahmen: Studio, Frühstück und Outdoor.
* Die Studio-Aufnahme wird das Hauptbild — im Raster stehen die Kacheln
* dadurch ruhig nebeneinander, genau das war der Wunsch. Die beiden
* inszenierten Aufnahmen stehen als Galerie auf der Produktseite.
*
* Die Dateien liegen unter static/ und werden über /static ausgeliefert. Die
* Adressen stehen ohne Domain in der Datenbank, damit dieselben Daten im
* Heimnetz, auf dem Testsystem und später in der Produktion stimmen.
*
* Wiederholbar: Ein erneuter Lauf setzt dieselben Bilder noch einmal.
*/
import { updateProductsWorkflow } from "@medusajs/core-flows";
/** Dateiname-Baustein → Teil des Produkttitels, über den zugeordnet wird. */
const SORTEN: { datei: string; suche: string }[] = [
{ datei: "akazie", suche: "Akazienhonig" },
{ datei: "fruehling", suche: "Frühlingsblütenhonig" },
{ datei: "heide", suche: "Heidehonig" },
{ datei: "himbeer", suche: "Himbeerblütenhonig" },
{ datei: "kornblume", suche: "Kornblumenhonig" },
{ datei: "raps", suche: "Rapshonig" },
// Im Katalog "Presshonig Hamburger Sommerblüte", im Shop als
// "Traditionshonig" geführt — so heißt auch die Bilddatei.
{ datei: "traditionshonig", suche: "Presshonig" },
{ datei: "wald", suche: "Waldhonig" },
];
const PFAD = (aufnahme: string, sorte: string) =>
`/static/produkt-${aufnahme}-${sorte}-250g.jpg`;
export default async function ({ container }: any) {
const query = container.resolve("query");
const logger = container.resolve("logger");
const { data: produkte } = await query.graph({
entity: "product",
fields: ["id", "title", "thumbnail"],
});
let gesetzt = 0;
const fehlend: string[] = [];
for (const sorte of SORTEN) {
const produkt = (produkte ?? []).find(
(p: any) => p.title?.includes(sorte.suche) && !p.title.includes("Abo")
);
if (!produkt) {
fehlend.push(sorte.suche);
continue;
}
// Studio zuerst: Das erste Bild ist zugleich das Hauptbild im Raster.
const bilder = [
PFAD("studio", sorte.datei),
PFAD("fruehstueck", sorte.datei),
PFAD("outdoor", sorte.datei),
];
await updateProductsWorkflow(container).run({
input: {
selector: { id: produkt.id },
update: {
thumbnail: bilder[0],
images: bilder.map((url) => ({ url })),
},
} as any,
});
logger.info(`${produkt.title}: 3 Bilder gesetzt.`);
gesetzt++;
}
logger.info("—".repeat(60));
logger.info(`${gesetzt} von ${SORTEN.length} Sorten bebildert.`);
if (fehlend.length) {
logger.info(`Kein Produkt gefunden für: ${fehlend.join(", ")}`);
}
// Frisch abfragen: Die Liste von oben stammt von vor dem Schreiben und
// würde die gerade bebilderten Sorten als "ohne Bild" melden.
const { data: danach } = await query.graph({
entity: "product",
fields: ["id", "title", "thumbnail"],
});
const ohne = (danach ?? []).filter(
(p: any) => !p.thumbnail && !p.title?.includes("Versandanteil")
);
if (ohne.length) {
logger.info(`Weiterhin ohne Bild: ${ohne.map((p: any) => p.title).join(", ")}`);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 519 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 624 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB