1

I have created a custom category attribute using this tutorial http://gauss-development.com/blog/tutorials/adding-custom-category-attributes-magento/.

<?php
$installer = $this;
$installer->startSetup();
$attribute = array(
 'type' => 'text',
 'label' => 'Extra Title',
 'input' => 'text',
 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
 'visible' => true,
 'required' => false,
 'user_defined' => true,
 'default' => "",
 'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'cat_extra_title', $attribute);
$installer->endSetup();
?>

I have checked that the attribute is stored in eav_attribute table normally, but I can't get it's value.

$category = Mage::registry('current_category');
if ($category){
 $value = $category->getData('cat_extra_title'); //value is empty
}

Any ideas?

Baby in Magento
2,97517 gold badges85 silver badges227 bronze badges
asked May 4, 2016 at 5:46
11
  • 1
    which page you are showing the value? Commented May 4, 2016 at 6:28
  • 1
    First you try to print the values of the current category by using var_dump($category->getData()). Whether the values of 'cat_extra_title' is retrieving or not. Commented May 4, 2016 at 6:40
  • @Manikandan there are values retrieved but the 'cat_extra_title' value is not included in them. Why? Commented May 4, 2016 at 8:12
  • 2
    try $category->getCatExtraTitle(); Commented May 4, 2016 at 9:05
  • 1
    Can you print the values and share the link Commented May 4, 2016 at 9:15

3 Answers 3

4

After testing many possible solutions, this was the only one that worked for me:

$cat_extra_title = Mage::getModel('catalog/category')->load($category->getId())->getData('cat_extra_title');
answered May 5, 2016 at 7:00
2
  • 3
    It's actually not a good practice to call "->load" every time when you need just one attribute. First of all - if you have Category Flat enabled (check in System - Configuration - Catalog) - do a reindex of Flat Category and check if column for your attribute appeared in flat table. And second - check my reply below Commented May 5, 2016 at 7:02
  • I was looking for something like this today and your solution works. Thanx Commented May 11, 2018 at 16:09
1

when adding new attribute for Category or Product, we need to put this attribute in Attribute Set and Attribute Group. So your code should look like this:

$installer->addAttribute('catalog_category', 'cat_extra_title', array(
 'type' => 'text',
 'label' => 'Extra Title',
 'input' => 'text',
 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
 'required' => false,
 'default' => '',
 'user_defined' => true,
 'default' => "",
));
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'cat_extra_title'
);
answered May 5, 2016 at 7:10
1

I ran into the same issue today. I created a new custom category attribute (an int/select one), and I would try this, in list.phtml, and get an empty value:

$value = Mage::registry('current_category')->getData('my_custom_Attribute');

However, this was solved by re-indexing catalog_category_flat; with n98:

n98-magerun.phar index:reindex catalog_category_flat

Now, the same code produces the value, so long as a value exists for the category (if the value is empty/NULL, then, of course, it will still produce a NULL value).

answered May 10, 2019 at 0:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.