'How to create Product Attribute Combination in asp.net core?

Product Name Color Size
T Shirt Red Small
Pant Yellow Large
Green

Desired results:

T Shirt Red Small 
T Shirt Red Large 
T Shirt Yellow Small
T Shirt Yellow Large
T Shirt Green Small 
T Shirt Green Large 
Pant Red Small 
Pant Red Large 
Pant Yellow Small 
Pant Yellow Large 
Pant Green Small 
Pant Green Large


Solution 1:[1]

As there is no code example, it is not clear what exact thing you would like to achieve.

I am assuming, you are looking for a way to create Custom Attributes in Asp.Net Core. Please correct me if my assumption is wrong.

Custom attributes are essentially traditional classes that derive directly or indirectly from System.Attribute. Just like traditional classes, custom attributes contain methods that store and retrieve data.

Below is the code example of Custom Attribute.

[AttributeUsage(AttributeTargets.All)]
public class DeveloperAttribute : Attribute
{
    // Private fields.
    private string name;
    private string level;
    private bool reviewed;

    // This constructor defines two required parameters: name and level.

    public DeveloperAttribute(string name, string level)
    {
        this.name = name;
        this.level = level;
        this.reviewed = false;
    }

    // Define Name property.
    // This is a read-only attribute.

    public virtual string Name
    {
        get {return name;}
    }

    // Define Level property.
    // This is a read-only attribute.

    public virtual string Level
    {
        get {return level;}
    }

    // Define Reviewed property.
    // This is a read/write attribute.

    public virtual bool Reviewed
    {
        get {return reviewed;}
        set {reviewed = value;}
    }
}

Reference: Writing Custom Attributes

If this is not the thing you are looking for, kindly provide more information about your requirements. I will try to provide you with further suggestions.

Solution 2:[2]

The question is not clear. do you want to implement "product attribute combination" feature like the one that nopCommerce has? or you want to create a product attribute combination for a nopCommerce product? anyways i will try to explain both

The implementation of product attribute combination in nopCommerce

Let's imagine you already have the product and product attribute tables. just create another table for representing product attribute combination. the required fields for that table are Id, ProductId, AttributeId, Quantity and attributeXml. the only filed which may confuse you is attributeXml which for saving the selected value of the attribute. the rest is a simple CRUD for this table. of course you should implement the inventory method of Track inventory by product attributes.

create a product attribute combination for a nopCommerce product

So the basic idea is that when for example you have a shirt(product) to sell and that shirt is available in three different colors(attribute with 3 attribute values) you may have different quantities of that shirt in different colors. this is where attribute combination comes in. go to your products edit page and in the product attribute card you will be able to see two tabs, product attribute and product attribute combination. you can define attribute combination for color attribute and choose the green color for example and insert a quantity and done. now you have a product attribute combination which shows the quantity for that shirt in that color. however there is one thing to remember, if you want the inventory to be calculated from attribute combination, set the Inventory method filed in the Inventory tab in the product edit page to Track inventory by product attributes

Hope this does it for you, if not please do more clarification

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Deepak-MSFT
Solution 2 reza ghasemirad