Skip to content

Instantly share code, notes, and snippets.

@hyhoocchan
Last active September 23, 2015 07:54
Show Gist options
  • Select an option

  • Save hyhoocchan/faf9891e1488b2555ef0 to your computer and use it in GitHub Desktop.

Select an option

Save hyhoocchan/faf9891e1488b2555ef0 to your computer and use it in GitHub Desktop.
[Catalog/Product] - Create product attribute - multiselect
<?php
// Used for multi select
$installer->addAttribute('catalog_product', "hair_style", array(
'group' => 'Your Group',
'type' => 'varchar',
'input' => 'multiselect',
'label' => 'Hair Style',
'visible' => 1,
'sort_order' => 20,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'used_in_product_listing' => 1,
'visible_in_advanced_search' => 1,
'is_configurable' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'backend' => 'eav/entity_attribute_backend_array',
'option' => array(
"values" => array(
0 => "Straight",
1 => "Wavy",
2 => "Curly",
)
)
));
//For single select attribute
$installer->addAttribute('catalog_product', "hair_special_needs", array(
'group' => 'Your Group',
'type' => 'int',
'input' => 'select',
'label' => 'Hair Special Needs',
'visible' => 1,
'sort_order' => 50,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'used_in_product_listing' => 1,
'visible_in_advanced_search' => 1,
'is_configurable' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'backend' => 'eav/entity_attribute_backend_array',
'option' => array(
"values" => array(
0 => "Sulfate Free",
1 => "Paraben Free",
2 => "Anit-Humidity",
3 => "Gluten Free",
4 => "UV Protectant",
5 => "None"
)
)
));
//Used for boolean attribute
$installer->addAttribute('catalog_product', "hair_sale_bag", array(
'group' => 'Your Group',
'type' => 'int',
'input' => 'boolean',
'label' => 'Sale Bag',
'visible' => 1,
'sort_order' => 1000,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'used_in_product_listing' => 1,
'visible_in_advanced_search' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'source' => 'eav/entity_attribute_source_boolean'
));
// Used for images attribute
$installer->addAttribute('catalog_product', "image_attribute", array(
'group' => 'Your Group',
'type' => 'varchar',
'input' => 'media_image',
'label' => 'Awards Icon',
'visible' => 1,
'sort_order' => 801,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'used_in_product_listing' => 0,
'visible_in_advanced_search' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
//Text Area type
$installer->addAttribute('catalog_product', "hair_questions", array(
'group' => 'Sexy Hair',
'type' => 'text',
'input' => 'textarea',
'label' => 'Hair Questions',
'visible' => 1,
'sort_order' => 999,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'used_in_product_listing' => 0,
'visible_in_advanced_search' => 0,
'wysiwyg_enabled' => 1, // IF used wygwys
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
@hyhoocchan

Copy link
Copy Markdown
Author
Remember setup module class is Mage_Catalog_Model_Resource_Setup
<resources>
      <custom_setup>
           <setup>
                <module>Forix_Custom</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
       </custom_setup> 
</resources>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment