2012-12-05 4 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>'; 
         } 


        } 

은에/응용 프로그램/코드/지역/마법사/Catalo g/모델 /app/code/core/Mage/Catalog/Model/Product.php에서 관리자 레이블을 얻을 수 있습니다 /Product.php crete 함수 :

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); 
    } 
관련 문제