Category: Magento — admin @ 6:54 pm — Comments (10)

The goal of this article is to show to add new image type to product in Magento.

By default Magento has 3 type of images:

  1. Base image
  2. Small image
  3. Thumbnail image

Typically these types of images is sufficient. But sometimes it becomes necessary to add a new type of image. Add a new type of image is easy as Magento in the gallery displays all the attributes for which the attribute ‘input_type’ equals ‘media_image’.

Code, described below adds a new type of image «small_image_two». It should be executed as an SQL update.

<?php
$installer = $this;
$installer->startSetup();
$this->addAttribute(
    'catalog_product',
    'small_image_two',
    array (
        'group'             => 'Images',
        'type'              => 'varchar',
        'frontend'          => 'catalog/product_attribute_frontend_image',
        'label'             => 'Small Image Two',
        'input'             => 'media_image',
        'class'             => '',
        'source'            => '',
        'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'visible'           => true,
        'required'          => false,
        'user_defined'      => false,
        'default'           => '',
        'searchable'        => false,
        'filterable'        => false,
        'comparable'        => false,
        'visible_on_front'  => false,
        'unique'            => false,
    )
);
$installer->endSetup();

After adding the attribute you will see the following:

New image type for product in Magento

Horaayy..there are 10 comment(s) for me so far ;)

#1

hi,

where i can execute this code?

thanks

t0th: wrote on August 31, 2010 - 10:24 pm
#2

hello, t0th
You should execute it in sql update script. Please, see as example any file in the folder: /app/code/core/Mage/Catalog/sql/catalog_setup

admin: wrote on September 1, 2010 - 9:38 am
#3

having a hard time getting this. how do I actually run the script? it looks like it runs when Mage_catalog is updated but how to I do that. I tried running ./pear intall Mage_Catalog and ./pear upgrade Mage_Catalog Any help would be appreciated.

thanks

Josh: wrote on September 28, 2010 - 9:44 pm
#4

I need to know how to execute the update SQL script?

I agree with others, the instructions are lacking.

I get it that files in /app/code/core/Mage/Catalog/sql/catalog_setup/ are in same format but it does not help newbie.

If I create own file to that directory and throw the code above to there it does not magically get executed, I need to know how to execute the update SQL?

Btw if it is just SQL why not paste SQL statements those are simple to execute with phpmyadmin…

Ciantic: wrote on April 28, 2011 - 9:32 pm
#5

How to i start the “Magento update script”?

KOmaSHOOTER: wrote on May 17, 2011 - 3:12 pm
#6

How do i start the “Magento update script”?

KOmaSHOOTER: wrote on May 17, 2011 - 3:12 pm
#7

the best way is too reinstall magento.
Put the new code in
app\code\core\Mage\Resource\Eav\Mysql4\Setup.php line: 888

KOmaSHOOTER: wrote on May 19, 2011 - 11:50 am
#8

So,

I got this working by creating a custom module. Adding this to my custom module setup.

My config.xml looked like:

0.1.0

Renove_Vectorimage
Mage_Catalog_Model_Resource_Eav_Mysql4_Setup

core_setup

Felipe Leusin: wrote on June 27, 2011 - 7:52 pm
#9

Thanks.. Great Code..:)

Avtar: wrote on November 1, 2011 - 3:18 pm
#10

Great, exactly what I was looking for, although a companion post on where to put the code might be helpful to all the commenters above!

Edward: wrote on February 17, 2012 - 11:13 am
You can leave a response, or trackback from your own site.

Write Your Comment

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs will be generated automatically.

You should have a name, right? 
Your email address, I promised I won't tell it to anyone. 
This is where you type your comments. 
Remember my information for the next time I visit.