get simple product with his options from configura

2019-06-27 06:19发布

问题:

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.

回答1:

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