2013-01-10 2 views
1

Magento의 사용자 정의 범주 속성에서 값을 가져 오려고합니다. 속성은 선택 필드로, 아래의 설치 스크립트로 만들어진되어사용자 정의 범주 속성에서 값 가져 오기

$this->startSetup(); 

$this->addAttribute('catalog_category', 'category_categorycolor', array(
    'group'   => 'General Information', 
    'input'   => 'select', 
    'type'   => 'varchar', 
    'label'   => 'Categorie kleur', 
    'backend'  => '', 
    'visible'  => 1, 
    'required'  => 0, 
    'user_defined' => 1, 
    'option'   => array (
            'value' => array('yellow' => array('Geel'), 
                'purple' => array('Paars'), 
                'blue' => array('Blauw'), 
                'red' => array('Rood'), 
                'orange' => array('Oranje'), 
                'green' => array('Groen'), 
                'darkblue' => array('Donkerblauw'), 
                'lightgreen' => array('Lichtgroen'),            
               ) 
           ), 
    'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
)); 

$this->endSetup(); 

불행하게도에만 점점 숫자와 텍스트가 아닌 값입니다. 이 줄을 사용하여 값을 검색합니다.

<?php $_category_categorycolor = $_category->getData('category_categorycolor'); if($_category_categorycolor): ?> <?php echo $_category_categorycolor; ?> <?php endif; ?> 

누군가 나를 도울 수 있습니까?

답변

3

sollution은 꽤 지저분합니다 (내가 아는 유일한 것).

$opt = array(); // will contain all options in a $key => $value manner 
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'category_categorycolor'); 
    if ($attribute->usesSource()) { 
     $options = $attribute->getSource()->getAllOptions(false); 
     foreach ($options as $o) { 
      $opt[$o['value']] = $o['label']; 
     } 
    } 

$categoryColorId = $_category->getData('category_categorycolor'); 
$categoryColorLabel = $opt[$categoryColorId]; 

// if you have problems, do a Zend_Debug::dump($opt); 
// - it should contain an array of all the options you added 

작동하지 않는지 테스트 해보지 않았습니까?

추신 : 귀하의 댓글에 답장을 보낼 수 없습니다. 그 이유는 확실하지 않습니다. $ opt에는 무엇이 들어 있습니까? 이 같은

+0

안녕 블라드. 같은 결과는 숫자 만 보여줍니다. – Michael

+0

안녕하세요. array (8) { [11] => string (5) "Blauw" [15] => 문자열 (11) "Donkerblauw" [9] => string (4) "Geel "[14] => 문자열 (5)"Groen " [16] ="문자열 "(10)"Lichtgroen " [>] 문자열 (6)"Oranje " [ "Paars" [12] => string (4) "Rood" } – Michael

+0

안녕하세요. 내 잘못. 틀린 echo :-) Michael

4

뭔가 :

$category_id = '10'; 
$attribute_code = 'category_categorycolor'; 
$category = Mage::getModel('catalog/category')->load($category_id); 

echo $category->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($category); 
+0

거의. 특정 카테고리 대신 현재 카테고리 ID가 필요합니다. – Michael

+0

'Mage :: registry ('current_category')'는 현재 카테고리를 저장합니다 –

관련 문제