Tuesday, 11 March 2014

create product attribute programmatically magento

Hello Friends

To create product attribute programmatically use below code,Just replace with your id and label.

But Make sure that this script run only once so out this script in contact page and and run contact page after remove this script.



$installer = $this;
$installer->startSetup();
$this->addAttribute('catalog_product','new_image_attribute',
    array (
        'group'             => 'Images',
        'type'              => 'varchar',
        'frontend'          => 'catalog/product_attribute_frontend_image',
        'label'             => 'New Image Attribute',
        'input'             => 'media_image',
        'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'visible'           => true,
        'default'           => '',
        'class'             => '',
        'source'            => ''
    )
);
$installer->endSetup();


Textbox Attribute

$setup->addAttribute('catalog_product', 'custom_mprice', array(
'group' => 'Keyur Shah',
'input' => 'text',
'type' => 'text',
'label' => 'Enter Max Price',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'sort_order' => 30,
'comparable' => 0,
'visible_on_front' => 0,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'is_configurable' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, ));

Dropdown Attribute

$setup->addAttribute('catalog_product', "price_status", array(
'group' => '
Keyur Shah',
    'type'       => 'int',
    'input'      => 'select',
    'label'      => 'Allow check price ?',
    'visible' => 1, 
    'sort_order' => 10,
    'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'is_configurable' => 1,
    'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'backend'    => 'eav/entity_attribute_backend_array',
    'option'     => array (
        'values' => array(
            0 => 'No',
            1 => 'Yes',
        )
    ),

));

1 comment:

  1. How do I use your code? What are the necessary steps in order for the script to run?

    ReplyDelete