Creating Configurable Products

Creating Configurable Products

Basically there are different ways for creating Configurable Products in Magento2 (like in Magento1).
You can create it using the Admin Panel, using a Setup\InstallData or Setup\UpgradeData class or during a custom import.

ADDING THE ATTRIBUTE

Let’s assume we are creating our attribute using the Setup\UpgradeData class in our module.
The code we might initially create could look something like the following:

The above code will create an attribute with the attribute-code ‘dev98_diameter’, which is available for simple and configurable products, within the group ‘General’ and is searchable, filterable etc… Futhermore we are adding some attribute options as well.

CREATING A CONFIGURABLE PRODUCT

Now if you add this attribute to an attribute-set and try creating a configurable product for this attribute it won’t work out as you might expect.
You will not see the attribute in the overlay ‘Create Product Configurations’  where you choose the attributes you want your product to be configurable with.

In Magento 2 the Admin Edit Form for Products changed quite a bit.

The most important change is, that the type of a product e.g. simple, configurable, etc. is no longer selected but determined automatically when saving the product.

So the product type you select using the DropDown in the Admin Product Grid is obsolete and not really used.

IMPROVING OUR UPDATEDATA CLASS

Knowing that the product is virtual at the moment of creating our configurable product, we have to add to type ‘virtual’ to the apply_to parameter in our ‘Setup\UpgradeData’ class.

After running the ‘setup:upgrade’ command, flushing the cache and reloading our Admin Product Edit Form we can now see the attribute ‘dev98_diameter’ in the ‘Create Product Configurations’ overlay.

From here-on we can create configurable products with our attribute as we please.

SUMMARY

To sum it up in short, you have to make your product attribute apply to type virtual to create configurable products.
At least when you are creating you attributes programmatically like in InstallData/ UpgradeData or using a attributes import.

Magento1 since 2008 / Magento2 since 2015
Passionate Road Bike Rider (~3.500km/yr)
Loves building software with a elaborate architecture and design
3x Magento Certified
Software Developer >10 years
Head of Magento Development @ netz98

Leave a Reply

%d bloggers like this: