Added variants base functionality.

This commit is contained in:
2026-01-22 20:13:38 +01:00
parent a87500fb24
commit 95fa29a6b3
10 changed files with 407 additions and 23 deletions
+21
View File
@@ -3,6 +3,7 @@ import type {Article} from "~/types/article";
import {NotificationMessage} from "~/types/notificationMessage";
import type {RuntimeConfig} from "nuxt/schema";
import {Origin} from "~/types/origin";
import type {Variant} from "~/types/variant";
interface State {
config: RuntimeConfig,
@@ -165,5 +166,25 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
this.addNotification(true, 'Es ist kein Artikel ausgewählt');
}
},
// Variant
async addVariant(articleID: number, variant: Variant) {
if(this.article != null) {
try {
let createdVariant = await $fetch<Variant>(this.config.public.url + '/article/' + articleID + '/variant', {
method: 'POST',
body: JSON.stringify(variant),
});
this.article.variants.push(createdVariant);
this.addNotification(false, 'Variante erstellt.');
} catch {
this.addNotification(true, 'Fehler beim erstellen der Variante.');
}
} else {
this.addNotification(true, 'Kann Variante nicht erstellen. Es ist kein Artikel ausgewählt.');
}
},
},
});