Magento: Programmatically add Bundle product to cart

Sometimes we want to add bundle product to cart, but most of beginner developer find it difficult to add bundle to cart on the fly. This is actually  also simple like adding simple product to cart,  but we just need to create array of bundle product with bundle_option_qty and bundle_option.

Let’s look at the typical bundle option array and how we can add it into the cart.

 

But now the question is how we can make this for the products we want to add in cart.
It is also simple, just manually add bundle product in cart and then add below code anywhere in checkout page or product page or in observer,
to check how magento create array for bundle product.

This will give you array of bundle product.
So, now you can simply add this product in cart like we did before.

Leave a Reply

Your email address will not be published. Required fields are marked *

10 − 2 =