3

As the title says, i want to be able to create and display custom category attributes.

I tried this extension: http://www.magentocommerce.com/magento-connect/manage-category-customer-and-customer-address-attributes.html

And this extension allows me to create the attributes, but I dont know how to display them in my template files. I tried the following code:

<?php echo Mage::getResourceModel('catalog/category')->getAttributeRawValue($_category->getId(), "subtitel", Mage::app()->getStore()->getId()); ?>

but that did not do the trick.

Any suggestions?

0

In which file are you trying to echo the new attribute (looks like a .phtml). Some times you need to load the category again to load all the attributes, you can't just rely that the new attribute will be already loaded in the object. So first you could use xdebug to check wich attributes are loaded, or if you are not using xdebug I guess you could do var_dump() or print_r(). If the attribute is not there then load the category like this:

$category = Mage::getModel('catalog/category')->load($id);

Then you can check again for your new attribute like this:

$category->getSubtitel(); 
//or like this
$category->getData('subtitel');

Final advice, just make sure you get only the attributes you need, so you could just load the set of attributes you need each time.

  • I am abit new to magento development, so i am not sure how to use xdebug, haven't heard of it before. To answer your quesiton i am trying to output a special titel, specific for each category. So i am trying to output the value from category/view.phtml – Kristian Daugaard Jun 1 '15 at 9:34
  • I tried loading the model like you said, and my attribute data is still not being displayed – Kristian Daugaard Jun 1 '15 at 9:35
  • That is fine, then just place a print_r($_category->getData()) in your .phtml file and you will see all the attributes. There is also another alternative you could use Mage::log() and then instead of printing the output of $_category->getData() you can put that into a log file, if you want to do this then place this in your .phtml Mage::log(print_r($_category->getData()), true), 1, 'nameforyour.log'); Dont worry if the file doesn't exist Magento will create it for you, the file will be located in MAGENTO_ROOT_PATH/var/log/. – lloiacono Jun 1 '15 at 9:39
  • Not sure what's going on. But you can check that your attribute was created like this: select e.* from eav_attribute e join eav_entity_type t on e.entity_type_id = t.entity_type_id where t.entity_type_code = 'catalog_category' and e.attribute_code = 'subtitel'; Take note of the attribute_id and backend_type and then you can check if a given category has the attribute set and what value has like this: select * from catalog_category_entity_varchar where attribute_id = ATTRIBUTE_ID_HERE and entity_id = CATEGORY_ID_HERE; – lloiacono Jun 1 '15 at 9:55
  • Forgot to mention, I just assumed that your attribute was a varchar attribute. So with the first query you will see which type of attribute you created if you don't know already. So if it's indeed a varchar then the second query should work, if it's something else then you need to change the table name: catalog_category_entity_decimal, catalog_category_entity_int, catalog_category_entity_text, catalog_category_entity_datetime – lloiacono Jun 1 '15 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.