You will need an observer:
<checkout_cart_product_add_after> <observers> <reporting> <type>singleton</type> <class>Yourcompany_yourmodelname_Model_Observer</class> <method>onCartProductAdd</method> </reporting> </observers> </checkout_cart_product_add_after>
Then the observer:
class ourcompany_yourmodelname_Model_Observer extends Mage_Core_Model_Abstract { public function onCartProductAdd($observer){ $product = $observer->getProduct(); $isProductBundle = ($product->getTypeId() == 'bundle'); $items_to_add = array(); $oTypeInstance = $oProduct->getTypeInstance(true); $aSelections = $oTypeInstance->getSelectionsCollection($aOptionIds, $product ); $aOptions = $oTypeInstance->getOptionsByIds($aOptionIds, $product); $bundleOptions = $aOptions->appendSelections($aSelections, true); foreach ($bundleOptions as $bundleOption) { if ($bundleOption->getSelections()) { $bundleSelections = $bundleOption->getSelections(); foreach ($bundleSelections as $bundleSelection) { $items_to_add[] = $bundleSelection.getID(); } } } insertExtractedProducts($items_to_add); } public function insertExtractedProducts($items_to_add){ $cart = Mage::helper('checkout/cart')->getCart(); $ids_to_add = array(); foreach($items_to_add as $item_to_be_added){ $ids_to_add[] = $item_to_be_added->getProductId(); } $cart->addProductsByIDs($ids_to_add); $cart->save(); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); } }
Just a simple example, but it can help.
Related products can be difficult to understand when working with it through code: Here is an example image: 
Each batch product has one, many options, which at the end will be links to products that will be added to the package in the shopping cart.
Each option consists of one, many options, which will be related products that will fall into the shopping cart for this complete product. One choice, as a rule, can be set by default and is already selected on the product page. More information can be found at this link on how to create and customize related products, because in this document we will discuss only its programming side. The related products display page will look like this: 
It might look like this in a shopping cart as soon as you click "Add to Cart": Sample bundle
Sample Shampoo 1 x Moisturiser-125ml $29.95 Default Conditioner 1 x Moisturiser-60g $99.95
When polling this product through code, you download it like any normal product:
$oProduct->load($vProductId);
After downloading it, you need to get an instance of the product type so that you can load the parameters for this product type.
$oTypeInstance = $oProduct->getTypeInstance(true);
Now we can get the list of parameter identifiers for this product in this way:
$oTypeInstance = $oProduct->getTypeInstance(true);
To poll selections, we add a list of options to the collection, then we get a collection of options, as well as their corresponding selections:
$aSelections = $oTypeInstance->getSelectionsCollection($aOptionIds, $oProduct ); $aOptions = $oTypeInstance->getOptionsByIds($aOptionIds, $oProduct); $bundleOptions = $aOptions->appendSelections($aSelections, true);
Now we have a collection of options, and each option will have a set of Selections. Now we can look at the options and see their Selctions.
foreach ($bundleOptions as $bundleOption) { if ($bundleOption->getSelections()) { $bundleSelections = $bundleOption->getSelections(); foreach ($bundleSelections as $bundleSelection) {
To get the list of required products for the supplied product, you can use the following code:
$requiredChildren = $this->getChildrenIds($product->getId(),$required=true);
You can then iterate over the array of identifiers and load products by their identifiers to get more information about these products.
Related products in the basket
To scroll through the selected paired product options in the shopping card, you can use something like this:
/** * @var Mage_Bundle_Model_Product_Type */ $typeInstance = $this->getProduct()->getTypeInstance(true); // get bundle options $optionsQuoteItemOption = $this->getItem()->getOptionByCode('bundle_option_ids'); $bundleOptionsIds = unserialize($optionsQuoteItemOption->getValue()); if ($bundleOptionsIds) { /** * @var Mage_Bundle_Model_Mysql4_Option_Collection */ $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $this->getProduct()); // get and add bundle selections collection $selectionsQuoteItemOption = $this->getItem()->getOptionByCode('bundle_selection_ids'); $selectionsCollection = $typeInstance->getSelectionsByIds( unserialize($selectionsQuoteItemOption->getValue()), $this->getProduct() ); $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true); foreach ($bundleOptions as $bundleOption) { if ($bundleOption->getSelections()) { $label = $bundleOption->getTitle() $bundleSelections = $bundleOption->getSelections(); foreach ($bundleSelections as $bundleSelection) { $sName = $bundleSelection->getName(); } // some more code here to do stuff } } }
This code gets the parameters from the related product Quote Item, and then gets the options for this product in the collection, and then finds the selection "Selected".
NTN, Shaun