Tambahkan atribut khusus kategori dengan dropdown

10

Saya perlu menambahkan kategori atribute kustom, pilih dengan 2 nilai:

  • 0 - "Tidak"
  • 1 - "Ya"

Saya membuat modul dan menggunakan kode ini dalam file instalasi:

$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();

Atribut muncul di panel administrasi tetapi nilai tambah pada pilih untuk "Tidak" adalah 3 dan untuk "Ya" adalah 4. Bagaimana cara membuat nilai 0 dan 1?

pengguna4157
sumber
@ user4157: Di mana saya dapat menambahkan hal ini,
Permata

Jawaban:

11

Coba ini:

$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();

Saya menambahkan eav/entity_attribute_source_booleansebagai sourceuntuk atribut Anda.

Marius
sumber
@ Maurius terima kasih atas jawabannya. Tetapi bagaimana model sumber eav/entity_attribute_source_booleanakan bekerja untuk opsi multiselect?
Slimshadddyyy
2
@ Vikram Jika Anda menggunakan model sumber untuk multiselect, Anda akan melihat multiselect dengan 2 opsi. Yes/No.
Marius
@Marius saya ingin atribut Ya atau Tidak di mana saya harus menambahkan file atau membuat modul baru untuk ini
Magento 2
2

Coba gunakan kode di bawah ini untuk membuat atribut top_brand dalam kategori:

   $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, 
            ) );
Bijal Bhavsar
sumber
1

Untuk menambahkan atribut ya / tidak khusus di bagian kategori, harap buat modul dan masukkan kode berikut.

 <?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();`

Silakan merujuk tutorial saya juga.

http://www.pearlbells.co.uk/how-to-add-custom-attribute-dropdown-to-category-section-magento/ (ya / tidak) atribut

http://www.pearlbells.co.uk/how-to-add-custom-dropdown-attribute-to-magento-category-section/ (opsi khusus)

pengguna46226
sumber