2

I feel like the flexibility of Magento would allow for my problem to be fixed but I haven't found anything as of yet.

So essentially I need to get the attribute value for a child product of a configurable product. So far all I can do is in the view.phtml file:

if ($_product->getTypeId() == 'configurable')
{
    $confAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
    print_r($confAttributes);
}

But that is from the parent scope of things. Basically my problem is that I need to get the images of the child products but when I go through a loop like this...

if ($_product->getTypeId() == 'configurable')
  $_child_products = $_configurable_model->getUsedProducts(null, $_product);
for ($i = 0; $i < count ($_child_products); $i++){
    <?php echo $this->helper('catalog/image')->init($_child_products[$i], 'image'); ?>
}

But now that is the scope from the perspective of the child product. I need to somehow correlate the child product with the attribute value that it takes on (for use with jQuery and image manipulation).

So is there any way that I can get some information from the child_product's perspective that can link it to the attribute?

halfer
  • 19,824
  • 17
  • 99
  • 186
Nathaniel Wendt
  • 1,194
  • 4
  • 23
  • 49
  • I'm not sure to have got what you exactly need. What's wrong with the second code snipped? – Fabrizio D'Ammassa Jul 22 '11 at 20:20
  • The second snippet only gets the child product images. I need a way for those images to know what variation they are from. The first snippet provides me with an array of applicable variations, but I cant link the image URL's with the variation... – Nathaniel Wendt Jul 22 '11 at 20:26
  • Have you tried loading $_child_products[$i] as magento model? or collection? – Nasaralla Jul 25 '11 at 16:26
  • The second snippet above gets `$_child_products` as `$_configurable_model -> getUsedProducts(null, $_product);`. I am not extremely familiar with Magento but I believe that is by model then..correct me if not – Nathaniel Wendt Jul 25 '11 at 16:35

1 Answers1

2

This might help you:

    $product = Mage::getModel('catalog/product')->load($id);
    
    $childIds = Mage::getModel('catalog/product_type_grouped')
    ->getChildrenIds($product->getId());
    
    $i = 1;
    
    foreach ($childIds as $key => $val){
        
        foreach($vals as $keyy => $vall){
            $arr[$i] = $vall;
            $i++;
        }
        
    }

$id -> is the product id of the group product.

$arr -> array which contains the id's of child products.

        $collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('price')
    ->addFieldToFilter('entity_id',array('in' =>array($arr)));

above code snippet shows how the way to retrieve the child products.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nazneen
  • 789
  • 3
  • 12
  • 23