@@ -42,14 +42,35 @@ model Category {
4242 imgSrc String ? @map (" img_src " )
4343 alt String ?
4444 description String ?
45+ hasVariants Boolean @default (false ) @map (" has_variants " ) // Indica si esta categoría maneja variantes
4546 createdAt DateTime @default (now () ) @map (" created_at " ) @db.Timestamp (0 )
4647 updatedAt DateTime @default (now () ) @map (" updated_at " ) @db.Timestamp (0 )
4748
48- products Product []
49+ products Product []
50+ categoryVariants CategoryVariant []
4951
5052 @@map (" categories " )
5153}
5254
55+ // Variantes disponibles para cada categoría
56+ model CategoryVariant {
57+ id Int @id @default (autoincrement () )
58+ categoryId Int @map (" category_id " )
59+ value String // "small", "medium", "large", "3x3", "5x5", "10x10"
60+ label String // "S", "M", "L", "3×3 cm", "5×5 cm", "10×10 cm"
61+ priceModifier Decimal @default (0 ) @map (" price_modifier " ) @db.Decimal (10 , 2 )
62+ sortOrder Int @default (0 ) @map (" sort_order " ) // Para ordenar las opciones
63+ createdAt DateTime @default (now () ) @map (" created_at " ) @db.Timestamp (0 )
64+ updatedAt DateTime @default (now () ) @map (" updated_at " ) @db.Timestamp (0 )
65+
66+ category Category @relation (fields : [categoryId ] , references : [id ] , onDelete : Cascade )
67+ cartItems CartItem []
68+ orderItems OrderItem []
69+
70+ @@unique ([categoryId , value ] )
71+ @@map (" category_variants " )
72+ }
73+
5374model Product {
5475 id Int @id @default (autoincrement () )
5576 title String
@@ -83,18 +104,21 @@ model Cart {
83104 @@map (" carts " )
84105}
85106
107+ // Actualizar CartItem para variantes de categoría
86108model CartItem {
87- id Int @id @default (autoincrement () )
88- cartId Int @map (" cart_id " )
89- productId Int @map (" product_id " )
90- quantity Int
91- createdAt DateTime @default (now () ) @map (" created_at " ) @db.Timestamp (0 )
92- updatedAt DateTime @default (now () ) @map (" updated_at " ) @db.Timestamp (0 )
93-
94- cart Cart @relation (fields : [cartId ] , references : [id ] , onDelete : Cascade )
95- product Product @relation (fields : [productId ] , references : [id ] , onDelete : Cascade )
96-
97- @@unique ([cartId , productId ] , name : " unique_cart_item " )
109+ id Int @id @default (autoincrement () )
110+ cartId Int @map (" cart_id " )
111+ productId Int @map (" product_id " )
112+ categoryVariantId Int ? @map (" category_variant_id " ) // Variante seleccionada
113+ quantity Int
114+ createdAt DateTime @default (now () ) @map (" created_at " ) @db.Timestamp (0 )
115+ updatedAt DateTime @default (now () ) @map (" updated_at " ) @db.Timestamp (0 )
116+
117+ cart Cart @relation (fields : [cartId ] , references : [id ] , onDelete : Cascade )
118+ product Product @relation (fields : [productId ] , references : [id ] , onDelete : Cascade )
119+ categoryVariant CategoryVariant ? @relation (fields : [categoryVariantId ] , references : [id ] , onDelete : SetNull )
120+
121+ @@unique ([cartId , productId , categoryVariantId ] , name : " unique_cart_item_variant " )
98122 @@map (" cart_items " )
99123}
100124
@@ -122,19 +146,23 @@ model Order {
122146 @@map (" orders " )
123147}
124148
149+ // Actualizar OrderItem
125150model OrderItem {
126- id Int @id @default (autoincrement () )
127- orderId Int @map (" order_id " )
128- productId Int ? @map (" product_id " )
129- quantity Int
130- title String
131- price Decimal @db.Decimal (10 , 2 )
132- imgSrc String ? @map (" img_src " )
133- createdAt DateTime @default (now () ) @map (" created_at " ) @db.Timestamp (0 )
134- updatedAt DateTime @default (now () ) @map (" updated_at " ) @db.Timestamp (0 )
135-
136- order Order @relation (fields : [orderId ] , references : [id ] , onDelete : Cascade )
137- product Product ? @relation (fields : [productId ] , references : [id ] , onDelete : SetNull )
151+ id Int @id @default (autoincrement () )
152+ orderId Int @map (" order_id " )
153+ productId Int ? @map (" product_id " )
154+ categoryVariantId Int ? @map (" category_variant_id " )
155+ quantity Int
156+ title String
157+ variantInfo String ? @map (" variant_info " ) // "Talla: M" o "Tamaño: 5×5 cm"
158+ price Decimal @db.Decimal (10 , 2 ) // Precio final (base + modificador)
159+ imgSrc String ? @map (" img_src " )
160+ createdAt DateTime @default (now () ) @map (" created_at " ) @db.Timestamp (0 )
161+ updatedAt DateTime @default (now () ) @map (" updated_at " ) @db.Timestamp (0 )
162+
163+ order Order @relation (fields : [orderId ] , references : [id ] , onDelete : Cascade )
164+ product Product ? @relation (fields : [productId ] , references : [id ] , onDelete : SetNull )
165+ categoryVariant CategoryVariant ? @relation (fields : [categoryVariantId ] , references : [id ] , onDelete : SetNull )
138166
139167 @@map (" order_items " )
140- }
168+ }
0 commit comments