How To Programmatically Create Bundled Product In Magento 2

How To Programmatically Create Bundled Product In Magento 2

Magento 2 Bundle Product is simply “build your own” customizable product.

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

Each item in a bundle can be either a simple product or a grouped product and thus, can be bought individually or as a combo. The perfect example of a bundle product is a corporate menswear combo including a shirt, formal pants, tie, blazer, etc.

On click of “Customize” or “Add to Cart” button, the option for the selection is displayed.  The bundle can consist of varied products and hence, the SKU, price, and weight is set to either dynamic or fixed value.

Here’s the code to programmatically create bundled product in Magento 2 store easily!

Method to programmatically create bundled product in Magento 2:

 

That’s it.

Any doubts in the code to create Magento 2 bundled products? If so, please mention them in the Comments section below. I’d be glad to be of any help.

Do share the post with Magento peeps via social media.

Thank you.

Get Weekly Updates

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

Thank you for subscribing.

Something went wrong.

5
(based on 17 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 Bundled Product In Magento 2

  • Hi there Sanjay,

    Its very nice your tutorials, and this snippet helped me a lot.. But I have a doubt and maybe you can help me..
    I’ve created a bundle product successfully with your example here, but in my situation, I have to give to customer the option to select more products to be inserted in frontend, for example, I have my bundle products with my options selected, and the customer can add more products from a different list, and this bundle product will be inserted with more products than originally was created in admin panel, is that possible using an observer event like: controller_action_catalog_product_save_entity_after

    I will really appreciate your help

  • Hi
    I am running this code in controller. I am getting an error like 1 exception(s):
    Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Vendor\Import\Controller\Index\Bundle\Interceptor

    • Hello Upendra Kumar,
      The error is caused due to the changes in the constructor argument.
      You either need to run the command or delete the file from the generator.
      Thank you.

Leave a reply:

Your email address will not be published.