How to Create Configurable Products Programmatically in Magento 2? can anyone tell me about the solution to how to do this?



Programmatically create configurable products in magnto2

//configurable product

$configurable_product = $this->_objectManager->create('\Magento\Catalog\Model\Product');
$configurable_product->setName('test name configurable');
    'use_config_manage_stock' => 0, //'Use config settings' checkbox
    'manage_stock' => 1, //manage stock
    'is_in_stock' => 1, //Stock Availability

$configurable_product->getTypeInstance()->setUsedProductAttributeIds(array(152),$configurable_product); //attribute ID of attribute 'size_general' in my store
$configurableAttributesData = $configurable_product->getTypeInstance()->getConfigurableAttributesAsArray($configurable_product);


$configurableProductsData = array();
$configurableProductsData[$simple_product_id] = array( //[$simple_product_id] = id of a simple product associated with this configurable
    '0' => array(
        'label' => 'S', //attribute label
        'attribute_id' => '152', //attribute ID of attribute 'size_general' in my store
        'value_index' => '193', //value of 'S' index of the attribute 'size_general'
        'is_percent'    => 0,
        'pricing_value' => '10',


Try with it.

  • how to get simple product id? if product is not created – Moin Malek Oct 26 '17 at 13:03
  • @MoinMalek First you need to create simple product which assign under configurable one. – Envision Ecommerce Oct 26 '17 at 13:04
  • 1
    Ok Got it. lets try it – Moin Malek Oct 26 '17 at 13:06
  • 1
    @MoinMalek Yes sure, I was able to do that, If any query let me know. If you got success please mark yes to my answer. Thanks – Envision Ecommerce Oct 26 '17 at 13:08
  • Not working at all – Moin Malek Oct 26 '17 at 13:10

Part 1: Create the Configurable Product Step 1: Select the Product Type is Configurable Product Step 2: Select the Product Template Step 3: Complete the Required Fields Step 4: Complete the Remaining Product Details Step 5: Save and Continue Part 2: Add Configurations Step 1: Select the Attributes Step 2: Enter the Attribute Values Step 3: Configure the Images, Price and Quantity Step 4: Generate the Product Configurations Step 5: Publish the Products Step 6: Configure the Shopping Cart Thumbnails (Optional) Step 7: Final, check your result by view the Products in your store

  • I want using Programatocally – Moin Malek Oct 26 '17 at 10:38
  • may be it's working.i have create only simple product programmatically. – Mulay Swapnil Oct 26 '17 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.