Magento: Adding simple products from a bundle to separate lines in the cart

Magento: Adding simple products from a bundle to separate lines in the cart

July 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Adding simple products from a bundle to separate lines in the cart

Handling Bundled Products Separately in Magento Cart

In Magento, when you add a bundled product to your cart, it appears as a single line item containing all the bundle components as an array. However, there are scenarios where you might require each simple product within the bundle to be added as a separate line item in the cart.

Let’s explore how to achieve this using custom code. I’ll guide you through the necessary steps to modify Magento’s default behavior for adding bundled products to the cart.

Understanding the Process

When a user adds a bundled product to their cart, Magento uses the bundle quote item type by default. This creates a single line item in the cart that includes all the configured simple products as an array within the bundle item data.

To separate these items into individual lines, we need to override this behavior and create multiple quote items for each simple product inside the bundle.

Implementing the Solution

Step 1: Create a custom controller action

Firstly, let’s create a new controller action that will handle the logic for adding bundled items to the cart separately. We’ll extend the bundle module and override the default behavior of the add action.

Follow these steps:

  • Navigate to your Magento root directory and locate the app/code/core/Mage/Bundle/controllers/CartController.php file.
  • Create a new directory named local within the Mage/Bundle/controllers/ folder, if it doesn’t exist already. This is where we’ll place our custom module files.

Step 2: Modify the addAction method

Open the newly created CartController.php file in your text editor or IDE. Locate the addAction() method within the Mage_Bundle_CartController class.

public function addAction()
{
    // Existing code...

    $productId = (int)$this->getRequest()->getParam('product');

    if ($productId) {
        $product = Mage::getModel('catalog/product')->load($productId);
    }

    // Custom logic to handle bundled products separately
    if ($product && $product->getTypeId() == 'bundle') {
        $this->_addBundleItemsToCart($product);

        $this->_goBack();
    } else {
        parent::addAction();
    }
}

Step 3: Create the addBundleItemsToCart method

Add a new private method named _addBundleItemsToCart() to handle the logic for adding bundle items separately.

private function _addBundleItemsToCart($bundleProduct)
{
    $bundleOptionCollection = $bundleProduct->getTypeInstance(true)->getSelectionsCollection(
        $bundleProduct,
        Mage::getSingleton('checkout/session')->getQuoteId()
    );

    foreach ($bundleOptionCollection as $option) {
        $quoteItem = Mage::getModel('sales/quote_item');
        $quoteItem->setProduct($option->getProduct());
        $quoteItem->setQty($option->getSelectedQty());
        $quoteItem->setSku($option->getProduct()->getSku());

        // Set additional quote item data as required
        // Example: $quoteItem->setName('Custom Item Name');

        Mage::getSingleton('checkout/session')->getQuote()->addItem($quoteItem);
    }
}

Step 4: Flush the cache

After implementing these changes, make sure to flush Magento’s cache. You can do this manually by navigating to System > Cache Management in your Magento admin panel and selecting the “Flush Magento Cache” option.

Conclusion

By following these steps, you should now have a custom solution that separates each simple product within a bundled item into individual line items when added to the cart.

Remember, it’s crucial to thoroughly test this implementation to ensure proper functionality. If any unexpected behavior occurs, make sure to double-check your code and consult Magento’s documentation or seek assistance from experienced developers or support services like those offered by Laravel Company.

This custom solution provides a clean way to modify the default cart behavior without significantly altering core files, ensuring better maintainability and ease of updating in future releases.

Checkout Catalog Extensions Configuration

Our network