2012-12-05 65 views

回答

1

在我的情況下,屬性名稱是confi_color。因此,對list.phtml

if($_product->getTypeId()=='configurable'){ 
         $colorList  = array(); 
         $attrs = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product); 
         foreach($attrs as $attr) { 
          if(0 == strcmp("config_color", $attr['attribute_code'])) { 
           $options = $attr['values']; 
           $arr  = array(); 
           $count  = 0; 
           foreach($options as $option) { 
            //print_r($option); 
            $arr[$count] = $option['value_index']; 
            $count++; 
           } 
           $colorList   = $_product->getAdminAttributeText($attr['attribute_id'],$arr); 
           //echo getAdminAttributeText($attributeCode);  
          } 
         } 
         echo '<div style="float:right;">'; 
         if(count($colorList > 1)){ 
          for($i=1;$i<count($colorList);$i++) { 
           echo '<div style="background:'.$colorList[$i].';float:left;display:block;width:16px;border:1px solid #B6B6B6;margin-right:2px;">&nbsp;</div>'; 
          //$optStr .= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>"; 
          } 
          echo '</div><div style="clear:left;"></div>'; 
         } 


        } 

我們得到管理員標籤中/app/code/core/Mage/Catalog/Model/Product.php到/應用/代碼/本地/法師/ Catalo 克/型號/Product.php克里特島功能:

public function getAdminAttributeText($attributeCode,$arr) { 
     $_attribute= $this->getResource()->getAttribute($attributeCode); 
     $_options= $_attribute->getSource()->getAllOptions(true, true); 
     $count  = 0; 
     $flag   = 0; 
     $returnArr = array(); 
     foreach($_options as $option){ 
      for($count=0;$count<=count($arr);$count++){ 
       if ($option['value'] == $arr[$count]){ 
        $returnArr[$flag]  = $option['label']; 
        $flag++; 
       } 
      } 
     } 
     return($returnArr); 
    } 
相關問題