3

I have created custom attribute in Magento 1.9.3.

$pro_attribute = [
    'input' => 'text',
    'type' => 'int',
    'label' => 'Pro Position',
    'visible' => true,
    'required' => true,
    'visible_on_front' => true,
    'unique' => true,
    'searchable' => true,
    'filterable' => true,
    'validate' => true,
    'class' => 'validate-number',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//SCOPE_STORE,
];

Field is sucessfully created and has the "required entry" validation. How can I add the "number" validation?

0
0

try adding :

'frontend_class' => 'validate-number'
4
  • i tried this but not working. Nov 24 '16 at 6:49
  • try again with the edited code Nov 24 '16 at 6:53
  • I upgraded the code with the line that you gave.cleared cache too...but no luck. Nov 24 '16 at 6:55
  • 'unique' => true, not working after adding 'frontend_class' => 'validate-number' Nov 24 '16 at 8:28
2

Try this,

I tried out side it's working fine

<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute  = array(
    'group'                => 'General Information',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Pro Position',
    'input'             => 'text', //text, textarea, select, file, image, multilselect
    'default' => array(0),
    'class'             => 'validate-number',
    'source'            => 'eav/entity_attribute_source_text',//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'     => 'validate-number',

    'user_defined'      => true,
    'default'           => '',
    'position'            => 100,//any number will do
);

$installer->addAttribute('catalog_category', 'pro_position', $attribute);
$installer->endSetup();
?>
2
  • After adding this , my unique=>true stopped working .Also , when I click on any category for edit, it is not opening. Nov 24 '16 at 9:04
  • How you add this
    – Magento 2
    Nov 24 '16 at 10:13

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.