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; ?>

誰かが私を助けることができますか?

4

3 に答える 3

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);
于 2013-01-10T14:21:33.907 に答える
3

解決策はかなり厄介です(私が知っている唯一のもの)。

$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

それをテストしませんでした、それが機能するかどうか私に知らせてください。

PS:あなたのコメントに返信することはできません。理由はわかりません。$ optには何が含まれていますか?

于 2013-01-10T14:15:27.730 に答える
0

返される数値は、ドロップダウンの各値のIDです。ドロップダウン値もロードする必要があります。

次のページを参照してください。それは私がこれを理解するのを助けました。

http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/

于 2013-01-10T14:23:10.350 に答える