Magento – Add Input Validation to Product Attribute with MySQL Install Script

attributesinstallmodulevalidation

I have a shipping plugin that creates 3 product attributes, namely length, width and height.

I have the following code in my install script:

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$setup->addAttribute('catalog_product', 'length', array(
    'group'         => 'General',
    'input'         => 'text',
    'type'          => 'text',
    'label'         => 'Length',
    'backend'       => '',
    'visible'       => TRUE,
    'required'      => TRUE,
    'user_defined'  => TRUE,
    'searchable'    => FALSE,
    'filterable'    => FALSE,
    'comparable'    => FALSE,
    'visible_on_front' => FALSE,
    'visible_in_advanced_search'  => FALSE,
    'is_html_allowed_on_front' => FALSE,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

I wish add "Decimal Number" "Input Validation for Store Owner".

I tried changing type to 'int', but that didn't seem to work.

Using Magento Version 1.7.0.2. Here is the project on github and here is the Install File

Any help would be appreciated!

Best Answer

Tested and working:

'frontend_class' => 'validate-number'

Here you can find further reference: Adding Magento custom attributes through setup scripts with all the validation options