cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Magento attributes using Magento Extension

SOLVED

Creating Magento attributes using Magento Extension

Hello. I am Marvin. Anyone here can help how to create Magento attributes using Magento Extension. Here is the instruction:

 

  1. I have to create a new Yes/No attribute for products. The code should be display_product.
  2.  The code should be able to install in Magento extension because I will use git and host the code in github. I am using Magento CE 1.9 Thanks.

 

I am Marvin
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Creating Magento attributes using Magento Extension

Thanks. I also tried Silk Software website easily generate files on creating attributes. 

 

 

 

 

I am Marvin

View solution in original post

2 REPLIES 2

Re: Creating Magento attributes using Magento Extension

Hi @Marvin261,

 

You can create an installer script, with something like this:

 

$installer = $this;

$installer->startSetup();

$attribute_set_id = $installer->getDefaultAttributeSetId(Mage_Catalog_Model_Product::ENTITY);
$attribute_group_id = $installer->getAttributeGroupId(Mage_Catalog_Model_Product::ENTITY, $attribute_set_id, 'General');

$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'display_product', array(
    'type'              => 'int',
    'frontend'          => '',
    'label'             => 'Display product',
    'input'             => 'select',
    'backend'           => '',
    'class'             => '',
    'source'            => 'eav/entity_attribute_source_boolean',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
    'visible'           => 1,
    'required'          => 0,
    'user_defined'      => 1,
    'default'           => '',
    'searchable'        => 0,
    'filterable'        => 0,
    'comparable'        => 0,
    'visible_on_front'  => 1,
    'unique'            => 0,
    'position'          => 15,
));

$installer->addAttributeToGroup(
    Mage_Catalog_Model_Product::ENTITY,
    $attribute_set_id,
    $attribute_group_id,
    'display_product',
    '15'
);

$installer->endSetup();

 

Re: Creating Magento attributes using Magento Extension

Thanks. I also tried Silk Software website easily generate files on creating attributes. 

 

 

 

 

I am Marvin