How To Programmatically Create Configurable Product In Magento 2

How To Programmatically Create Configurable Product In Magento 2

If you are here, then you are a beginner in Magento 2 world! Welcome. It isn’t as hard as people say 😉

Magento 2 configurable product is a single product with variations in it. Each variation is an individual simple product with a unique SKU. Hence, one can track the inventory for each variation.

There are six product types in Magento 2:

  1. Simple Product
  2. Configurable Product
  3. Grouped Product
  4. Virtual Product
  5. Bundle Product
  6. Downloadable Product

Learning how to programmatically create configurable product in Magento 2 makes it easy for the developers while creating an online store.

For example, apparel available in different sizes or colors is an example of a configurable product.

Check the below code to become a pro in creating Magento 2 configurable products!

Method to programmatically create configurable product in Magento 2:

That’s it.

Easy, ain’t it?

Creating Magento 2 configurable product is one of the basics so if you have any doubts on the topic, please mention them in the Comments section below. I’d be happy to help.

Do share the post with fellow Magento beginners via social media.

Thanks.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 8 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

4 comments On How To Programmatically Create Configurable Product In Magento 2

  • How to assign a simple product to an existing configurable product?

  • Hi Sanjay, do you have any example of php code, where we can assign multiple attributes such as color / size and then assign simple products to configurable product via code? Please help if possible.

    • Hello Prashant,
      You’ll have to create the size and color attribute.
      For example:
      $attr = $_product->getResource()->getAttribute('color');
      $avid = $attr->getSource()->getOptionId('Blue');
      $_product->setData('color', $avid);

      Thank you.

Leave a reply:

Your email address will not be published.