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