1

I need to get details of all simple products associated with Configurable product along with product attributes

I used the existing magento functionality which returns empty value.

function getConfig($productIds) { $configurableData = array(); $configProdCollctn = Mage::getResourceModel('catalog/product_collection'); $configProdCollctn->addAttributeToFilter('entity_id',array('in'=> $productIds)) ->addAttributeToFilter('type_id', array('eq'=> Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE)); while ($product = $configProdCollctn->fetchItem()) { $prodAttrOptions = $product->getTypeInstance(true)->getConfigurableOptions($product); foreach ($prodAttrOptions as $prodAttrOption) { $configurableData[$product->getId()] = array(); foreach ($prodAttrOption as $optionValues) { $val = $optionValues['option_title']; $configurableData[$product->getId()][] = array( $optionValues['sku'] => $optionValues['attribute_code']."=".$val ); } } } return ($configurableData); } 

This returns empty array.

for eg if config prod (A) has option of color and size. i need simple product A1,A2,A3 with color and size associated with options A1 = array(color => red,size => M) A2 = array(color => red,size => S)

Kindly Let me know how can I achieve this

1
  • I have updated with example if the question was unclear... Commented Nov 23, 2014 at 17:21

2 Answers 2

3

I got the solution to the above requirment..

$product= Mage::getModel('catalog/product')->load($configId); #Check if the product has children if ($product->type_id == 'configurable') { $options = array(); // Get any super_attribute settings we need $productAttributesOptions = $product->getTypeInstance(true)->getConfigurableOptions($product); foreach ($productAttributesOptions as $productAttributeOption) { $options[$product->getId()] = array(); foreach ($productAttributeOption as $optionValues) { $val = $this->trimValue($optionValues['option_title']); $options[$product->getId()][] = array ( $optionValues['sku'] => $optionValues['attribute_code']."=".$val ) ; } } 
0
2

Take a look at Getting attribute from simple products of configurable products

$productId = 1; //config product id $product = Mage::getModel('catalog/product')->load($productId); $configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($product); $simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); foreach($simpleCollection as $simple){ //$simple->getName(); } 

See Get simple products belonging to configurable products in magento

1
  • The code which you suggested will return simple products.. i also require configurable option associated with that simple product.. for eg if config prod (A) has option of color and size. i need simple product A1,A2,A3 with color and size associated with options A1 = array(color => red,size => L) Commented Nov 23, 2014 at 17:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.