I install the attribute with the following script:

$installer = $this;

$installer->removeAttribute('catalog_product', 'customizableonly');
$installer->addAttribute('catalog_product', 'customizableonly', array(
        'group'                     => 'General',
        'input'                     => 'select',
        'type'                      => 'int',
        'label'                     => 'Customizable Only',
        'source'                    => 'eav/entity_attribute_source_boolean',
        'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'                   => 1,
        'required'                  => 0,
        'visible_on_front'          => 0,
        'is_html_allowed_on_front'  => 0,
        'is_configurable'           => 0,
        'searchable'                => 0,
        'filterable'                => 0,
        'comparable'                => 0,
        'unique'                    => false,
        'user_defined'              => false,
        'default'           => 0,
        'is_user_defined'           => false,
        'used_in_product_listing'   => true


Also tried with $installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');

And then I am using the value of the attribute in some other code. But I always get null. I found out that, the attribute does not get set a default value. When I open a product - the dropdown shows No, but when I get its value in code it's null. If I just click the dropdown, simply set No and save the product - everything works.

How to overcome this?


5 Answers 5


Try to set default value as string

'default' => '0'

or empty

'default' => ''


The default values are added when you add new product for old ones it not affects.

Try to fix that in Product management with mass action

Inside manage products, there is a action called “Update Attributes”. Select all the products that you want to update and then select Update Attributes and add all the new information in.

  • 1
    I tried that already and doesn't work. :(
    – Syspect
    Commented Jan 30, 2014 at 14:53

I had the problem that with the code snippets above a select-attribute was created instead of a yes/no attribute. To fix this I had to use

'input'             => 'boolean'

instead of:

'input'             => 'select'

You should set value for all existing entity manually:

$productIds = Mage::getResourceModel('catalog/product_collection')

// Now create an array of attribute_code => values
$attributeData = array("my_attribute_code" =>"my_attribute_value");

// Set the store to affect. I used admin to change all default values
$storeId = 0; 

// Now update the attribute for the given products.
    ->updateAttributes($productIds, $attributeData, $storeId);

source: https://stackoverflow.com/questions/4906497/default-attribute-value-for-all-product-in-magento. See Asrar Malik's answer.


I was not able to add a default value 0 to a yes/no attribute too.

Therefore I used an event to add the default value 0



public function customerSaveBefore(Varien_Event_Observer $observer)
    try {
        $customer = $observer->getCustomer();
        if (!$customer->getYourCustomAttribute()) {
    } catch ( Exception $e ) {
        Mage::log( "customer_save_before observer failed: ".$e->getMessage());

For adding yes/no custom attribute to magento create module as shown below.


$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',


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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