1. 获取全部
//get Product
$cProduct = Mage::getModel('catalog/product')->load($_product->getId());
//check if product is a configurable type or not
if ($cProduct->getData('type_id') == "configurable")
{
//get the configurable data from the product
$config = $cProduct->getTypeInstance(true);
//loop through the attributes
foreach($config->getConfigurableAttributesAsArray($cProduct) as $attributes)
{
echo $attributes["label"];
foreach($attributes["values"] as $values)
{
echo $values["label"];
}
// do stuff....
}
}
NOTE: This does not get all the values possible, it only gets what you have in stock.
ie. For my configurable product, I have the options of Colors: R,B,G,Y,W,B and Sizes: S, M, L, but I only had stock for Colors R,B,G and Sizes S and L.
来源:http://www.magentocommerce.com/boards/v/viewthread/69838/#t199215
2. 获取单项(size为例)
When dealing with configurable products (or any time you're dealing with a concept for only one type of product, as configurable attributes are), you'll probably be working with getTypeInstance . See below, I grab the configurable attributes for the product, then find the one for size. You could also just run through every configurable attribute if you wanted. Or if size is the only configurable attribute, just skip that if() .
$attrs = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
foreach($attrs as $attr) {
if(0 == strcmp("size", $attr['attribute_code'])) {
$options = $attr['values'];
foreach($options as $option) {
print "{$option['store_label']}<br />";
}
}
}
来源: http://stackoverflow.com/questions/2742707/magento-and-configurable-product-attributes
更多参考: magento 获取产品存货量以及configurable product 下associated children product信息
本文详细介绍了在 Magento 平台上处理配置型产品的属性获取与展示方法,包括如何获取所有配置项以及单项属性如尺寸的具体实现。
3049

被折叠的 条评论
为什么被折叠?



