Get a simple product with its options from a custom magento product

How can I get simple products (custom child elements Parent) (for example:) color = redif I know a simple product identifier as well as the parent product identifier? I'm new to Magento and I really need some advice.

+4
source share
1 answer
// 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'];
    }
}
+3
source

Source: https://habr.com/ru/post/1548516/


All Articles