How to get associated child product

This article is full of product related hooks.

How to get product information like creating product object, getting product name, id , sku, associated product, gallery images, etc.
Example 1: How to create product object.
Its very basic, but it will surely help the beginner on how to create product object. Assign current product ID to the variable “$productId” so that it will create the product object “$_product”.

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

Example 2: How to get associated child product.
Before we fetch associated products / child products, one check is added it the product is configurable product or not.

if($_product->getTypeId() == "configurable"){
$AssociatedProduct = $_product->getTypeInstance()->getUsedProducts();

Example 3: Different methods product object which  used very frequently. 

//product name
echo $_product->getName();
// product's long description
echo $_product->getDescription();
//product's short description
echo $_product->getShortDescription();
//product's regular Price
echo $_product->getPrice();
//product's special Price
echo $_product->getSpecialPrice();
//product url
echo $_product->getProductUrl();
//product's image url
echo $_product->getImageUrl();
//product's small image url
echo $_product->getSmallImageUrl();
//product's thumbnail image url
echo $_product->getThumbnailUrl();

Example 4: How to get product collection.

//getting product model
$model = Mage::getModel('catalog/product');
//products collection
$collection = $model->getCollection();
//walk products collection
foreach ($collection as $product) //loop for getting products
    echo $product->getId() ;



Share this nice post:

11 thoughts on “How to get associated child product

  1. This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you. You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  2. Regards for all your efforts that you have put in this. Very interesting information.

  3. I just want to mention I am just new to weblog and actually savored this page. More than likely I’m planning to bookmark your blog post . You definitely come with wonderful articles and reviews. Thanks a bunch for sharing with us your blog.

Comments are closed.