(
+
+
+
+
+
+
+ Anderen Kategorien bei Auswahl zurücksetzen
+
+
+ Wenn aktiv, setzt die Auswahl eines Artikels dieser Kategorie alle anderen Kategorien zurück.
+
+
+
+ )}
+ />
+
{
- if (s.productIds && s.productIds.length > 0) {
- s.productIds.forEach(id => {
- if (id) selectedIds.push(id)
- })
- } else if (s.productId) {
- selectedIds.push(s.productId)
- }
- })
+ if (shouldReset) {
+ // Reset all other categories
+ categories.forEach(c => {
+ if (c.id !== catId) {
+ next[c.id] = { productId: null, productIds: [], moduleIds: [] }
+ }
+ })
+ } else {
+ // Automatically deselect now conflicting products in other categories
+ const selectedIds: string[] = []
+ Object.values(next).forEach(s => {
+ if (s.productIds && s.productIds.length > 0) {
+ s.productIds.forEach(id => {
+ if (id) selectedIds.push(id)
+ })
+ } else if (s.productId) {
+ selectedIds.push(s.productId)
+ }
+ })
- categories.forEach(c => {
- if (c.id === catId) return
- const s = next[c.id]
- if (c.allow_multiselect && s?.productIds) {
- const validProductIds = s.productIds.filter(pId => {
- const prod = products.find(p => p.id === pId)
- const otherSelectedProductIds = selectedIds.filter(id => id !== pId)
+ categories.forEach(c => {
+ if (c.id === catId) return
+ const s = next[c.id]
+ if (c.allow_multiselect && s?.productIds) {
+ const validProductIds = s.productIds.filter(pId => {
+ const prod = products.find(p => p.id === pId)
+ const otherSelectedProductIds = selectedIds.filter(id => id !== pId)
+ const isExcluded = prod && (
+ otherSelectedProductIds.some(otherId => {
+ const otherProd = products.find(p => p.id === otherId)
+ return otherProd?.exclusions?.includes(prod.id)
+ }) ||
+ prod.exclusions?.some(exId => otherSelectedProductIds.includes(exId))
+ )
+ return !isExcluded
+ })
+ next[c.id] = {
+ productId: validProductIds[0] || null,
+ productIds: validProductIds,
+ moduleIds: []
+ }
+ } else if (s?.productId) {
+ const prod = products.find(p => p.id === s.productId)
+ const otherSelectedProductIds = selectedIds.filter(id => id !== s.productId)
const isExcluded = prod && (
otherSelectedProductIds.some(otherId => {
const otherProd = products.find(p => p.id === otherId)
@@ -410,28 +441,12 @@ export function OrderWizard({
}) ||
prod.exclusions?.some(exId => otherSelectedProductIds.includes(exId))
)
- return !isExcluded
- })
- next[c.id] = {
- productId: validProductIds[0] || null,
- productIds: validProductIds,
- moduleIds: []
+ if (isExcluded) {
+ next[c.id] = { productId: null, productIds: [], moduleIds: [] }
+ }
}
- } else if (s?.productId) {
- const prod = products.find(p => p.id === s.productId)
- const otherSelectedProductIds = selectedIds.filter(id => id !== s.productId)
- const isExcluded = prod && (
- otherSelectedProductIds.some(otherId => {
- const otherProd = products.find(p => p.id === otherId)
- return otherProd?.exclusions?.includes(prod.id)
- }) ||
- prod.exclusions?.some(exId => otherSelectedProductIds.includes(exId))
- )
- if (isExcluded) {
- next[c.id] = { productId: null, productIds: [], moduleIds: [] }
- }
- }
- })
+ })
+ }
return next
})
diff --git a/shop/lib/types.ts b/shop/lib/types.ts
index 18ba045..9161ae6 100644
--- a/shop/lib/types.ts
+++ b/shop/lib/types.ts
@@ -31,6 +31,7 @@ export type Category = {
preselect: boolean
show_in_kauf?: boolean
show_in_abo?: boolean
+ resets_others: boolean
created_at: string
}
diff --git a/shop/supabase/migrations/20260709153000_add_resets_others_to_categories.sql b/shop/supabase/migrations/20260709153000_add_resets_others_to_categories.sql
new file mode 100644
index 0000000..c8a2bc1
--- /dev/null
+++ b/shop/supabase/migrations/20260709153000_add_resets_others_to_categories.sql
@@ -0,0 +1,2 @@
+-- Add resets_others column to categories table
+ALTER TABLE public.categories ADD COLUMN IF NOT EXISTS resets_others BOOLEAN DEFAULT false NOT NULL;