Aggiungi l'attributo personalizzato di categoria con il menu a discesa


10

Devo aggiungere alla categoria un attributo personalizzato, una selezione con 2 valori:

  • 0 - "No"
  • 1 - "Sì"

Ho creato un modulo e utilizzato questo codice nel file di installazione:

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

L'attributo appare nel pannello di amministrazione ma il valore aggiunto in select per "No" è 3 e per "Sì" è 4. Come rendere i valori 0 e 1?


@ user4157: dove posso aggiungere questo riguardo,
— Gemma

Risposte:


11

Prova questo:

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

Ho aggiunto eav/entity_attribute_source_booleancome sourceper il tuo attributo.


@Maurius grazie per la risposta. Ma come funzionerebbe il modello sorgente eav/entity_attribute_source_booleanper l'opzione di selezione multipla?
— Slimshadddyyy,

2
@Vikram Se usi quel modello sorgente per una selezione multipla vedrai una selezione multipla con 2 opzioni. Yes/No.
— Marius

@Marius desidero attribuire Sì o No dove devo aggiungere il file o creare un nuovo modulo per questo
— Magento 2

2

Prova a utilizzare il codice seguente per creare l'attributo top_brand nella categoria:

   $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

Per aggiungere l'attributo sì / no personalizzato nella sezione categoria, crea il modulo e inserisci il seguente codice.

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

Si prega di fare riferimento anche al mio tutorial.

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

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

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.