3

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!

  • I ended up changing the type to "decimal", which forces a decimal on save, however, it does not warn the admin that the values are entered incorrectly, and simply changes it to 0 if text was entered... – Xethron May 8 '13 at 21:28
3

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

2

try adding :

'class' => 'validate-number' 

That will hook into Magento's prototype driven Validation javascript. Ref http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/installing_custom_attributes_with_your_module

  • Tried adding the class, and also worked through the examples on the link you gave me, but it doesn't seem to work. In that link they also seem to be using a different function. Might be for an older Magento? I'm using Magento ver. 1.7.0.2. – Xethron May 2 '13 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.