Magento – Add custom Dropdown Column to Manage Product > Images Tab in Admin section

admince-1.9.1.0product-attributeproduct-images

Magento 1.9.1.0 version

My Requirement is to add a new DropDown type Column in "Images" Tab in "Manage Products"Section in Admin Section.

enter image description here

It may be more helpful if anybody can tell me that how magento is saving images details and fetching them.

[EDITED]

I have gone through the detailed issue and find out that there is a function
getImagesJson()
in
/app/code/core/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery/Content.php

which is responsible to show content in Images tab, but still want to find out that how and where magento used to save data for images, i gone through saveAction() in productController, but get unsaved JSON data of new added image.

Any one can help me that how can i get value Id of newly saved image.

Best Answer

You can do that via the menu Catalog > Attributes > Manage Attributes and creating an attribute with a Dropdown type.

After that, you can add it to the attribute set of your choice in Catalog > Attributes > Manage Attribute Sets. Select your Set, then drag your attribute in the right column, and drop it in the left one, under the group "Images". Your attribute should then display in "Manage Products".

If you want to add this attribute programmatically, you can do it with an installer, and a code like that :

<?php
$installer = $this;

$installer->startSetup();

// Group : General
$attributeSetDefault = 'Default';
$attributeGroup = 'Images';
$attributeSetId = $installer->getAttributeSetId('catalog_product', $attributeSetDefault);
if($attributeSetId){
    $attributeGroupId = $installer->getAttributeGroupId('catalog_product', $attributeSetId, $attributeGroup);
}

// Attribute : attribute_code
$attributeCode = 'attribute_code';
$attribute = $installer->getAttribute('catalog_product', $attributeCode);
if (empty($attribute['attribute_id'])) {

    $options = array();
    $options['value']['option0'][0] = 'Option 0';
    $options['value']['option1'][0] = 'Option 1';

    $installer->addAttribute(
        'catalog_product',
        $attributeCode,
        array(
            'label'                         => 'Attribute',
            'type'                          => 'varchar',
            'backend'                       => 'eav/entity_attribute_backend_array',
            'frontend'                      => '',
            'input'                         => 'select',
            'frontend_class'                => '',
            'source'                        => '',
            'required'                      => false,
            'user_defined'                  => true,
            'default'                       => '',
            'unique'                        => false,
            'global'                        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'option'                        => $options,
        )
    );

    $attributeId = $installer->getAttributeId('catalog_product', $attributeCode);

    if($attributeGroupId && $attributeId){
        $installer->addAttributeToGroup('catalog_product', $attributeSetId, $attributeGroupId, $attributeId);
    }
}


$installer->endSetup();