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

Can I create a “composite” attribute? 
 
feuerbach
Jr. Member
 
Total Posts:  4
Joined:  2011-07-14
 

Hello,

I would like Magento to create an attribute made by other attributes: to be specific a single attribute that retrieves values from “manufacturer” “name” “sku” and one more custom attribute.

Is it possible? If so, how?

Thanks for any kind of help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magestore
Mentor
 
Avatar
Total Posts:  1015
Joined:  2009-08-07
Viet Nam
 

Hi Feuerbach,
It is ok. To insert to an attribute, Magento supports feature “source” so that you can customize insert data as you want. In the array that is to insert to attribute you can set ‘source’ as “name class get value to other attribute”. For example:

$data = array(
  
'group' => 'General',
  
'type' => 'int',
  
'input' => 'select',
  
'label' => 'Wrappable',
  
'backend' => '',
  
'frontend' => '',
  
'source' => 'giftwrap/attribute_wrappable',
  
'visible' => 1,
  
'required' => 1,
  
'user_defined' => 1,
  
'is_searchable' => 1,
  
'is_filterable' => 0,
  
'is_comparable' => 1,
  
'is_visible_on_front' => 0,
  
'is_visible_in_advanced_search' => 1,
  
'used_for_sort_by' => 0,
  
'used_in_product_listing' => 1,
  
'used_for_price_rules' => 1,
  
'is_used_for_promo_rules' => 1,
  
'position' => 2,
  
'unique' => 0,
  
'is_configurable' => 1,
  
'default' => 0,
  
'is_global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE
 
);

 
$setup->addAttribute('catalog_product','giftwrap',$data);
As the code above you can see ‘source’ => ‘giftwrap/attribute_wrappable’, I used class ‘giftwrap/attribute_wrappable’ to insert value for a new attribute ‘giftwrap’.
Hope you are succeed.
 
Magento Community Magento Community
Magento Community
Magento Community
 
feuerbach
Jr. Member
 
Total Posts:  4
Joined:  2011-07-14
 

Thanks for the prompt response!

I am pretty confident with interface customization but not too much with backend coding.

What file am I supposed to search in order to apply this customization?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magestore
Mentor
 
Avatar
Total Posts:  1015
Joined:  2009-08-07
Viet Nam
 

Hi Feuerbach,
You can create a setup sql file and a file to get source for attribute example as below:

- File sql setup:

<?php
$setup 
=  new Mage_Eav_Model_Entity_Setup('core_setup');
$installer $this;
$installer->startSetup();

//Giftwrap attribute
$entity_type Mage::getSingleton("eav/entity_type")->loadByCode("catalog_product");
$entity_type_id $entity_type->getId();
$collection Mage::getModel("eav/entity_attribute")
            ->
getCollection()
            ->
addFieldToFilter("entity_type_id",$entity_type_id)
            ->
addFieldToFilter("attribute_code","giftwrap");
            
if(!
count($collection))
{
    $data 
= array(
        
'group'    =>    'General',
        
'type'    =>    'int',
        
'input'    =>    'select',
        
'label'    =>    'Wrappable',
        
'backend'    =>    '',
        
'frontend'    =>    '',
        
'source'    => 'giftwrap/attribute_wrappable',
        
'visible'    =>    1,
        
'required'    =>    1,
        
'user_defined'    =>    1,
        
'is_searchable'    =>    1,
        
'is_filterable'    =>    0,
        
'is_comparable'    =>    1,
        
'is_visible_on_front'    =>    0,
        
'is_visible_in_advanced_search'    => 1,
        
'used_for_sort_by'    => 0,
        
'used_in_product_listing'    => 1,
        
'used_for_price_rules'    => 1,
        
'is_used_for_promo_rules'    => 1,
        
'position'    => 2,
        
'unique'    =>    0,
        
'is_configurable'    =>    1,
        
'default'    => 0,
        
'is_global'    =>    Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE
    
);

    
$setup->addAttribute('catalog_product','giftwrap',$data);

    
$entity_type_id $setup->getEntityTypeId('catalog_product');
    
$data['entity_type_id'$entity_type_id;
    
$attribute Mage::getModel("eav/entity_attribute")
        ->
setData($data)
        ->
setId($setup->getAttributeId('catalog_product','giftwrap'));
    
$attribute->save();
}

$installer
->run("

"
);
        
$installer->endSetup();

- File get source for attribute:

<?php


class Magestore_Giftwrap_Model_Attribute_Wrappable extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    
    
/**
     * Retrieve all options array
     *
     * @return array
     */
    
public function getAllOptions()
    
{
        
if (is_null($this->_options)) {
            $this
->_options = array(
                array(
                    
'label' => Mage::helper('eav')->__('Yes'),
                    
'value' =>  0
                
),
                array(
                    
'label' => Mage::helper('eav')->__('No'),
                    
'value' =>  1
                
),
            );
        
}
        
return $this->_options;
    
}

    
/**
     * Retrieve option array
     *
     * @return array
     */
    
public function getOptionArray()
    
{
        $_options 
= array();
        foreach (
$this->getAllOptions() as $option{
            $_options[$option[
'value']] $option['label'];
        
}
        
return $_options;
    
}

    
/**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string
     */
    
public function getOptionText($value)
    
{
        $options 
$this->getAllOptions();
        foreach (
$options as $option{
            
if ($option['value'== $value{
                
return $option['label'];
            
}
        }
        
return false;
    
}

    
/**
     * Retrieve Column(s) for Flat
     *
     * @return array
     */
    
public function getFlatColums()
    
{
        $columns 
= array();
        
$columns[$this->getAttribute()->getAttributeCode()= array(
            
'type'      => 'tinyint(1)',
            
'unsigned'  => false,
            
'is_null'   => true,
            
'default'   => null,
            
'extra'     => null
        
);

        return 
$columns;
    
}

    
/**
     * Retrieve Indexes(s) for Flat
     *
     * @return array
     */
    
public function getFlatIndexes()
    
{
        $indexes 
= array();

        
$index 'IDX_' strtoupper($this->getAttribute()->getAttributeCode());
        
$indexes[$index] = array(
            
'type'      => 'index',
            
'fields'    => array($this->getAttribute()->getAttributeCode())
        );

        return 
$indexes;
    
}

    
/**
     * Retrieve Select For Flat Attribute update
     *
     * @param int $store
     * @return Varien_Db_Select|null
     */
    
public function getFlatUpdateSelect($store)
    
{
        
return Mage::getResourceModel('eav/entity_attribute')
            ->
getFlatUpdateSelect($this->getAttribute(), $store);
    
}
}

Hope you succeed,
Magestore

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sergefactor
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2012-04-08
 

Hi I’m having a Reindex Required issue. I just installed the Gift Card extension that I purchased and flushed the cache, when I try to reindex the Catalog Search Index I keep getting this warning [ Source model “giftwrap/attribute_wrappable” not found for attribute “giftwrap” ] .

After searching a few forums I found this thread and I believe this is the fix I’m looking for. Can you provide a little more detail on where exactly I need to create and put these files? Are there any other requirements that I’m missing? I followed the install instructions.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
NCMW
Jr. Member
 
Total Posts:  23
Joined:  2008-08-17
 
Sergefactor - 11 December 2012 10:22 AM

Hi I’m having a Reindex Required issue. I just installed the Gift Card extension that I purchased and flushed the cache, when I try to reindex the Catalog Search Index I keep getting this warning [ Source model “giftwrap/attribute_wrappable” not found for attribute “giftwrap” ] .

After searching a few forums I found this thread and I believe this is the fix I’m looking for. Can you provide a little more detail on where exactly I need to create and put these files? Are there any other requirements that I’m missing? I followed the install instructions.

Thanks.

We are getting the same error when trying to edit items within the admin.

Contacted magestore support and havent heard back yet.

Any advice would be greatly appreciated.

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