diff --git a/shop/app/admin/wysiwyg/wysiwyg-client.tsx b/shop/app/admin/wysiwyg/wysiwyg-client.tsx
index f403542..2ff5872 100644
--- a/shop/app/admin/wysiwyg/wysiwyg-client.tsx
+++ b/shop/app/admin/wysiwyg/wysiwyg-client.tsx
@@ -302,31 +302,8 @@ export function WysiwygAdminClient({
{(prod.modules || []).length > 0 ? (
(prod.modules || []).map((m) => (
-
- {m.name}
-
+
+ {m.name}
+ {/* Verknüpfte monatliche Gebühr */}
+
+ Verknüpfte Gebühr:
+
+
+
{/* Modul hinzufügen Popover */}
{
- for (const p of products) {
- const mod = p.modules?.find((m: any) => m.id === mId);
- if (mod && mod.linked_fee_product_id) {
- feeProductIds.add(mod.linked_fee_product_id);
- }
+
+ if (sel.productId) {
+ const p = products.find((prod: any) => prod.id === sel.productId);
+ if (p && p.linked_fee_product_id) {
+ feeProductIds.add(p.linked_fee_product_id);
+ }
+ }
+
+ sel.productIds?.forEach((pId: string) => {
+ const p = products.find((prod: any) => prod.id === pId);
+ if (p && p.linked_fee_product_id) {
+ feeProductIds.add(p.linked_fee_product_id);
}
});
}
diff --git a/shop/components/order-wizard.tsx b/shop/components/order-wizard.tsx
index 9cd62f4..c985fe3 100644
--- a/shop/components/order-wizard.tsx
+++ b/shop/components/order-wizard.tsx
@@ -429,6 +429,10 @@ export function OrderWizard({
oneTime += basePrice
}
+ if (prod.linked_fee_product_id) {
+ feeProductIds.add(prod.linked_fee_product_id)
+ }
+
// Module
sel.moduleIds?.forEach((mId: string) => {
const mod = prod.modules?.find(m => m.id === mId)
@@ -439,10 +443,6 @@ export function OrderWizard({
} else {
oneTime += mod.price * qty
}
-
- if (mod.linked_fee_product_id) {
- feeProductIds.add(mod.linked_fee_product_id)
- }
}
})
})
diff --git a/shop/lib/actions/products.ts b/shop/lib/actions/products.ts
index 1a31643..13ec6f5 100644
--- a/shop/lib/actions/products.ts
+++ b/shop/lib/actions/products.ts
@@ -9,7 +9,7 @@ export async function getProducts() {
const supabase = await createClient()
const { data, error } = await supabase
.from('products')
- .select('*, category:categories(*), modules:product_modules!product_modules_product_id_fkey(*)')
+ .select('*, category:categories(*), modules:product_modules(*)')
.order('created_at', { ascending: false })
if (error) throw error
@@ -90,7 +90,6 @@ export async function createProduct(
requirements: m.requirements || [],
exclusions: m.exclusions || [],
has_quantity: m.has_quantity ?? false,
- linked_fee_product_id: m.linked_fee_product_id || null,
}))
const { error: modulesError } = await supabase
.from('product_modules')
@@ -128,7 +127,6 @@ export async function updateProduct(id: string, product: Partial, modul
requirements: m.requirements || [],
exclusions: m.exclusions || [],
has_quantity: m.has_quantity ?? false,
- linked_fee_product_id: m.linked_fee_product_id || null,
}))
const { error: modulesError } = await supabase
.from('product_modules')
diff --git a/shop/lib/types.ts b/shop/lib/types.ts
index f7d4971..dff24b5 100644
--- a/shop/lib/types.ts
+++ b/shop/lib/types.ts
@@ -18,6 +18,7 @@ export type Product = {
requirements?: string[]
exclusions?: string[]
allow_update_discount?: boolean
+ linked_fee_product_id?: string | null
}
export type Category = {
@@ -46,7 +47,6 @@ export type ProductModule = {
exclusions: string[] // UUID[] von Modulen, die nicht gleichzeitig aktiv sein dürfen
created_at: string
has_quantity?: boolean
- linked_fee_product_id?: string | null
}
export type Profile = {
diff --git a/shop/supabase/migrations/20260722110000_move_linked_fee_to_products.sql b/shop/supabase/migrations/20260722110000_move_linked_fee_to_products.sql
new file mode 100644
index 0000000..212a29a
--- /dev/null
+++ b/shop/supabase/migrations/20260722110000_move_linked_fee_to_products.sql
@@ -0,0 +1,7 @@
+-- Remove linked_fee_product_id from product_modules
+ALTER TABLE public.product_modules
+DROP COLUMN IF EXISTS linked_fee_product_id;
+
+-- Add linked_fee_product_id to products
+ALTER TABLE public.products
+ADD COLUMN IF NOT EXISTS linked_fee_product_id UUID REFERENCES public.products(id) ON DELETE SET NULL;