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

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值