Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Multiple Category Images Can this be done? 
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

hi all,

i was wondering, has anyone tried to create a way to store multiple images against a category. Presently you can only store one image per category. I wouldnt mind having the ability to add more than 1 image and then in the front end i can then randomise these images being displayed.

Anyone done work around this?

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
quanza
Sr. Member
 
Avatar
Total Posts:  97
Joined:  2008-12-02
Tokyo, Japan
 

bump - i’d very much like this feature too!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

i created a new php file in my own module. Namespace f.e. Extcat. Crete File in folder local/Mage/Extcat/Entity/Setup.php

class Mage_Extcat_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup
{

    
/**
     * Enter description here...
     *
     * @return array
     */
    
public function getDefaultEntities()
    
{
        
return array(
            
'catalog_category' => array(
                
'entity_model'      => 'catalog/category',
                
'attribute_model'   => 'catalog/resource_eav_attribute',
                
'table'             => 'catalog/category',
                
'attributes'        => array(                  
                    
/* HOMEPAGE FIELDS */
                    
'keyvisual_top' => array(
                        
'type'              => 'varchar',
                        
'backend'           => 'catalog/category_attribute_backend_image',
                        
'frontend'          => '',
                        
'label'             => 'Keyvisual at top',
                        
'input'             => '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'  => true,
                        
'unique'            => false,
                    ),                    
                ),
            ),
        );
    
}
}

Now you habe a new category attribute called keyvisual_top which is a image field in backend. Now we have to add this attribute to database while installing the new module.

Create a File /local/Mage/Extcat/sql/extcat/mysql4-install-0.1.0.php with following content:

<?php
$installer 
$this;
$installer->startSetup();
$installer->installEntities();
$installer->endSetup();

Your config.xml of module should own this snippet:

<resources>
            <
extcat_setup>
                <
setup>
                    <
module>Mage_Extcat</module>
                    <class>
Mage_Extcat_Model_Entity_Setup</class>
                </
setup>
                <
connection>
                    <use>
core_setup</use>
                </
connection>
            </
extcat_setup>

Now you can get image source by using $category->getKeyvisualTop();

I think you understand creation of own modules, and please axcuse my bad english smile

Cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
quanza
Sr. Member
 
Avatar
Total Posts:  97
Joined:  2008-12-02
Tokyo, Japan
 

I found (what I think to be) a slightly easier way here:

http://www.magentocommerce.com/boards/viewthread/31728/

thanks though.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top