get simple product with his options from configurable product magento

泄露秘密 提交于 2019-12-10 16:34:10

问题


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


来源:https://stackoverflow.com/questions/24763117/get-simple-product-with-his-options-from-configurable-product-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!