search
top

Get child product in Magento

Hello All,

I am writing here a script for getting all the child products of the required parent product id

<?php
$productId = '123';
$product = Mage::getModel('catalog/product')->load($productId); //$productId for which the child products to be found        
 
$childids = $product->getTypeInstance(true)->getChildrenIds($productId, false);
echo '<pre>';
print_r($childids);
if(!empty($childids))
{
	$allProds = array();
	foreach($childids as $k => $v)
	{
		foreach($v as $pid)
		{
			$allProds[] = $pid;
		}	
	}

}
print_r($allProds);
echo '</pre>';

Hope this is useful

Leave a Reply

top