Agregar atributo personalizado de categoría con menú desplegable

10

Necesito agregar a la categoría un atributo personalizado, una selección con 2 valores:

  • 0 - "No"
  • 1 - "Sí"

Creé un módulo y usé este código en el archivo de instalación:

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

El atributo aparece en el panel de administración pero el valor agregado en la selección para "No" es 3 y para "Sí" es 4. ¿Cómo hacer que el valor 0 y 1?

usuario4157
fuente
@ User4157: ¿Dónde me puedo añadir este sentido,
Gema

Respuestas:

11

Prueba esto:

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

Agregué en eav/entity_attribute_source_booleancuanto sourcea su atributo.

Marius
fuente
@Maurius gracias por la respuesta. Pero, ¿cómo funcionaría el modelo fuente eav/entity_attribute_source_booleanpara la opción de selección múltiple?
Slimshadddyyy
2
@Vikram Si usa ese modelo fuente para una selección múltiple, verá una selección múltiple con 2 opciones. Yes/No.
Marius
@Marius i pálido a Sí o No atributo donde tengo que añadir el archivo o crear nuevo módulo para este
Magento 2
2

Intente usar el siguiente código para crear el atributo top_brand en la categoría:

   $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
fuente
1

Para agregar el atributo personalizado sí / no en la sección de categoría, cree el módulo e ingrese el siguiente código.

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

Por favor, consulte mi tutorial también.

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

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

usuario46226
fuente