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.
// 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'];
}
}