C
C#2mo 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
Angius2mo ago
Well, what would an e-shop need? At bare minimum
Alex
Alex2mo 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
Angius2mo 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
Alex2mo 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
Angius2mo 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
Alex2mo 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
Angius2mo 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
Alex2mo ago
Okay, I understand, thank you
Want results from more Discord servers?
Add your server