`
天梯梦
  • 浏览: 13623455 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

Magento 获取有效属性 Display available options for attributes of Configurable

 
阅读更多

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信息

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics