C
C#5mo ago
Alex

✅ e-commerce app

Hello, Can you help me with e-commerce product attributes concept, please? I want to build pet project and utilize this feature. But I don't know how to design database the right way, I've checked open source project - nopCommerce, but it's overwhelmed with other features that I won't have in my project. Maybe you have a simple database design with fields that I can start with. Basically I want to have variations of product and categories
8 Replies
Angius
Angius5mo ago
Well, what would an e-shop need? At bare minimum
Alex
AlexOP5mo ago
product can have attributes like color, size (I want to add then dynamically) and options (color: red, green, blue, size l, m, xl) and product can have a category, for example category clothes -> summer -> products
Angius
Angius5mo ago
Yeah So we already have three tables: product, attribute, category Product has a category and a list of attributes Category can have child categories Options could be enums, or two more tables: colors and sizes
Alex
AlexOP5mo ago
Yes, but I need dynamic attributes, I know that it can be done by creating tables attributes(name) attribute_options (attr id, value) and product variant(product id, attribute options). but i don't understand it all would work , should I create all variants of products and store them in database, and how can I display product data on the product page, if I have 3 color * 3 size = 9 products to fetch
Angius
Angius5mo ago
enum Size { XS, S, M, L, XL }
class Product
{
public int Id { get; set; }
public string Name { get; set; }
public List<Attribute> Attributes { get; set; }
public Category Category { get; set; }
public int CategoryId { get; set; }
public List<Size> Sizes { get; set; }
}
class Attribute
{
public int Id { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
class Category
{
public int Id { get; set; }
public string Name { get; set; }
public Category Parent { get; set; }
public int ParentId { get; set; }
}
enum Size { XS, S, M, L, XL }
class Product
{
public int Id { get; set; }
public string Name { get; set; }
public List<Attribute> Attributes { get; set; }
public Category Category { get; set; }
public int CategoryId { get; set; }
public List<Size> Sizes { get; set; }
}
class Attribute
{
public int Id { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
class Category
{
public int Id { get; set; }
public string Name { get; set; }
public Category Parent { get; set; }
public int ParentId { get; set; }
}
would be more or less the structure By fetching a single product, say one with ID 781, you would also fetch all of its attributes, sizes, and the category You don't save individual permutations in the database
Alex
AlexOP5mo ago
So I add (color,red), (color,blue), (color, green) to the attribute list? Because nopCommerce concept is to create product variations (color red, size l), (color green, size xl)
Angius
Angius5mo ago
product.Attributes.Add(new() {
Name = "color",
Value = "red",
});
product.Attributes.Add(new() {
Name = "color",
Value = "red",
});
for example yes And then you have the "output" product, that has just a single of each For example, not a list of sizes but a single size A list of attributes, but only one with a given name Etc
Alex
AlexOP5mo ago
Okay, I understand, thank you
Want results from more Discord servers?
Add your server