ドロップダウンでカテゴリのカスタム属性を追加する


10

カテゴリにカスタム属性、2つの値を持つ選択を追加する必要があります。

  • 0-「いいえ」
  • 1-「はい」

モジュールを作成し、このコードをインストールファイルで使用しました。

$this->startSetup();
$this->addAttribute('catalog_category', 'top_brand', array(
    'group'                => 'General',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Top Hersteller',
    'input'             => 'select', //text, textarea, select, file, image, multilselect
    'option' => array(
        'value' => array(

            'optionone'=> array(
                0 =>'No'),
            'optiontwo'=> array(
                0 =>'Yes')
        ),

    ),
    'default' => array(0),
    'class'             => '',
    // 'source'            => '',//this is necessary for select and multilelect, for the rest leave it blank
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    'visible'           => true,
    'frontend_class'     => '',
    'required'          => false,//or true
    'user_defined'      => true,
    'default'           => '',
    'position'            => 100,//any number will do
));
$this->endSetup();

属性は管理パネルに表示されますが、「いいえ」の選択で追加された値は3で、「はい」の場合は4です。値を0と1にする方法は?


@ user4157:私はこの点を追加できます
Gem

回答:


11

これを試して:

$this->startSetup();
$this->addAttribute('catalog_category', 'top_brand', array(
    'group'                => 'General',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Top Hersteller',
    'input'             => 'select', //text, textarea, select, file, image, multilselect
    'default' => array(0),
    'class'             => '',
    'source'            => 'eav/entity_attribute_source_boolean',//this is necessary for select and multilelect, for the rest leave it blank
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    'visible'           => true,
    'frontend_class'     => '',
    'required'          => false,//or true
    'user_defined'      => true,
    'default'           => '',
    'position'            => 100,//any number will do
));
$this->endSetup();

あなたの属性も追加eav/entity_attribute_source_booleansourceました。


@モーリウス、答えてくれてありがとう。しかし、ソースモデルeav/entity_attribute_source_booleanは複数選択オプションでどのように機能しますか?
Slimshadddyyy 2014

2
@Vikram複数選択にそのソースモデルを使用する場合、2つのオプションを持つ複数選択が表示されます。Yes/No
マリウス

@Marius「はい」または「いいえ」属性を使用して、ファイルを追加するか、このための新しいモジュールを作成する必要があります
Magento 2

2

以下のコードを使用して、カテゴリにtop_brand属性を作成してみてください。

   $this->addAttribute( 'catalog_category', 'top_brand', array(
                'group' => 'General',
                'type' => 'tinyint',
                'backend' => '',
                'frontend' => '',
                'label' => 'Top Hersteller',
                'input' => 'boolean',
                'source' => 'eav/entity_attribute_source_boolean',
                'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => '', 
                'unique' => false, 
            ) );

1

カテゴリセクションにカスタムのyes / no属性を追加するには、モジュールを作成して次のコードを入力してください。

 <?php
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'featured_product', array(
    'group'         => 'General Information',
    'input'         => 'select',
    'type'          => 'text',
    'label'         => 'Featured Product',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'source' => 'eav/entity_attribute_source_boolean',
));

$this->endSetup();`

私のチュートリアルも参照してください。

http://www.pearlbells.co.uk/how-to-add-custom-attribute-dropdown-to-category-section-magento/(yes / no)属性

http://www.pearlbells.co.uk/how-to-add-custom-dropdown-attribute-to-magento-category-section/(カスタムオプション)

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.