get simple product with his options from configurable product magento

user3840854 picture user3840854 · Jul 15, 2014 · Viewed 9.9k times · Source

How can I get a simple products (child of configurable Parent) options (like: color = red) if I know the simple products ID and also the parent Products ID? I am new to Magento and I really need some advice.

Answer

Pavel Novitsky picture Pavel Novitsky · Jul 15, 2014
// load configurable product
$product = Mage::getModel('catalog/product')->load($productId);

// get simple produts' ids
$childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($product->getId());

// get simple products
$childProducts = Mage::getModel('catalog/product_type_configurable')
                        ->getUsedProducts(null,$product);

// get configurable options
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
    foreach ($productAttribute['values'] as $attribute) {
        $attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
    }
}