There is a tutorial about this topic at https://developers.shopware.com/developers-guide/attribute-system