cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Category attribute not loaded

Custom Category attribute not loaded

Hi,

 

I'm trying to create a custom category attibute. I've succeeded to add it in the backend, it's showing and saving well, but I can't use it in the category frontend template (template/catalog/category/view.phtml), as it is not loaded in $_category->_data array.

 

Here is the code I've used to add this attribute : 

$installer = $this;

$installer->startSetup();

$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'General Information');

$installer->addAttribute('catalog_category', 'class_css', array(
                        'type'              => 'text',
                        'backend'           => '',
                        'frontend'          => '',
                        'label'             => 'Classe css',
                        'input'             => 'text',
                        'class'             => '',
                        'source'            => '',
                        'global'            => 1,
                        'visible'           => 1,
                        'required'          => 0,
                        'user_defined'      => 0,
                        'default'           => '',
                        'searchable'        => 0,
                        'filterable'        => 0,
                        'comparable'        => 0,
                        'visible_on_front'  => 1,
                        'unique'            => 0,
                        'position'     => 1,
                        'used_in_product_listing' => 1,
                    ));

$installer->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'class_css',
    '11' //last Magento's attribute position in General tab is 10
);

$installer->endSetup();

 

$_category->getData('class-css') returns an empty string and $_category->getClassCss() aswell.

 

Can you say me what I'm doing wrong?

 

Many thanks for your help

 

1 REPLY 1

Re: Custom Category attribute not loaded

Give this a try:

 

$_val = Mage::getResourceModel('catalog/category')->getAttributeRawValue($_category->getId(), "class-css", Mage::app()->getStore()->getId());