Here's a database design for the shopping cart section in e-commerce, with products having multiple attributes and multiple prices:
Table: Users
UserID
: Primary key, unique integerUsername
: StringEmail
: StringPassword
: StringCreatedAt
: Date and timeUpdatedAt
: Date and time
Table: Carts
CartID
: Primary key, unique integerUserID
: Foreign key referencing Users tableCreatedAt
: Date and timeUpdatedAt
: Date and time
Table: CartItems
CartItemID
: Primary key, unique integerCartID
: Foreign key referencing Carts tableProductID
: Foreign key referencing Products tableVariantID
: Foreign key referencing ProductVariants tableQuantity
: IntegerCreatedAt
: Date and timeUpdatedAt
: Date and time
Table: Products
ProductID
: Primary key, unique integerName
: StringDescription
: TextStockQuantity
: IntegerCreatedAt
: Date and timeUpdatedAt
: Date and time
Table: ProductVariants
VariantID
: Primary key, unique integerProductID
: Foreign key referencing Products tableName
: String (e.g., Color, Size)Value
: String (e.g., Red, XL)
Table: VariantPrices
PriceID
: Primary key, unique integerVariantID
: Foreign key referencing ProductVariants tablePrice
: DecimalCurrency
: String (e.g., USD, VND)
In this design, the CartItems
table will reference the ProductVariants
table to identify the specific variant of a product in the cart. The VariantPrices
table stores price information for each product variant based on different currencies.
As always, database design can be adjusted to fit the specific requirements of your project and how you want to manage the shopping cart and products.