Lorena
Lorena

Reputation: 193

Magento How to add a varchar attribute whit addAttribute specifiying a max length

I'm working with magento and I'm trying to add a new category attribute with type varchar(50). I've added the new attribute with:

$installer->addAttribute('catalog_category', 'shortdesc', array(
                    'type'              => 'varchar',
                    'backend'           => '',
                    'frontend'          => '',
                    'label'             => 'Descripción Corta',
                    'input'             => 'textarea',
                    'class'             => '',
                    'source'            => '',
                    'global'            => 1,
                    'visible'           => 1,
                    'required'          => 0,
                    'user_defined'      => 0,
                    'default'           => '',
                    'searchable'        => 0,
                    'filterable'        => 0,
                    'comparable'        => 0,
                    'visible_on_front'  => 0,
                    'unique'            => 0,
                    'position'          => 1,
                ));

But the max lenth is 255. How can I change attribute length to 50?

Upvotes: 1

Views: 2388

Answers (1)

Cristian Quiroz
Cristian Quiroz

Reputation: 367

Indeed, Magento hardcodes the 255 value (as of Community Edition 1.8.1.0) and doesn't accept parameters to replace it.

This should not be a problem for you, as VARCHAR(255) is the max number of characters that can be stored, but it wont take more space than it needs if you store any less than that. If you really need a hard limit, you can always add code to observe the before save event for categories and strip your string there.

Or, in the extreme case you really want this hard limit on the database, you could alter the table and modify the column.

Upvotes: 1

Related Questions