Programmatically get product grouped detail by id in magento

Programmatically get product grouped detail by id in magento

In this post we will show cod for how to programmatically get product grouped detail by its id in magento.

By following code we can Programmatically get product grouped detail by id in magento

// pass product id 
$product_id = 15;
 
//pass product id and get product_catagory detail
$product_catagory = Mage::getModel('catalog/product')->load($product_id);

// get product id 
$get_product_data["id"] =  $product_catagory->getId();

// get product sku 
$get_product_data["sku"] =  $product_catagory->getSku();

// get product name 
$get_product_data["name"] = $product_catagory->getName();

// get product type 
$get_product_data["type"] =  $product_catagory->getTypeId();    

// get product description short    
$get_product_data["description"]['short'] =  $product_catagory->getShortDescription();

// get product description full 
$get_product_data["description"]['full'] =  $product_catagory->getDescription();

// get product image
$get_product_data["image"]  = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'media/catalog/product'.$product_catagory->getImage();

// get product category
$get_product_data["category"] =  $product_catagory->getCategoryIds(); 

// Get Grouped Type of Associated Productfor 
$set_product_counter = 0;

$product_group = Mage::getModel('catalog/product_type_grouped')->setProduct($product_catagory);

// get grouped detail
$group_collection = $product_group->getAssociatedProductCollection();
foreach ($group_collection as $group_product_val) 
{
	// get grouped id
    $get_product_data["grouped"]["products"][$set_product_counter]["id"] = $group_product_val->getId();
	
	// get grouped sku
    $get_product_data["grouped"]["products"][$set_product_counter]["sku"] = $group_product_val->getSku();
	
	// get grouped name
    $get_product_data["grouped"]["products"][$set_product_counter]["name"] = $group_product_val->getName();
	
	// get grouped price
    $get_product_data["grouped"]["products"][$set_product_counter]["price"] = $group_product_val->getFinalPrice();
	
	// get grouped stock
    $get_product_data["grouped"]["products"][$set_product_counter]["stock"] =Mage::getModel('cataloginventory/stock_item')->loadByProduct($group_product_val->getId())->getData();
    $set_product_counter++;
}

// get grouped total
$get_product_data["grouped"]["total"] = $set_product_counter;

// print result
echo "<pre>"; 
print_r($get_product_data);
echo "</pre>"; 

Leave a Comment

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

1  +  7  =  

We accept paid advance and paid guest Posting on our Site : Contact US