0

I want to add a picture on top of category name in frontend. I tried creating a custom field for the category and adding a picture that way. I can't see anything I type in the custom textarea. I tried flushing cache and reindexing data.

Atwix_CustomCategoryAttribute.xml

 <?xml version="1.0"?>
    <config>
        <modules>
            <Atwix_CustomCategoryAttribute>
                <active>true</active>
                <codePool>local</codePool>
            </Atwix_CustomCategoryAttribute>
        </modules>
    </config>

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Atwix_CustomCategoryAttribute>
            <version>0.0.1</version>
        </Atwix_CustomCategoryAttribute>
    </modules>

    <global>
        <resources>
            <add_category_attribute>
                <setup>
                    <module>Atwix_CustomCategoryAttribute</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </add_category_attribute>
            <add_category_attribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </add_category_attribute_write>
            <add_category_attribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </add_category_attribute_read>
        </resources>
    </global>
</config>

mysql4-install-0.0.1.php

<?php
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'custom_attribute', array(
    'group'         => 'General Information',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'Custom attribute',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

$this->endSetup();
2
  • Can you post your template where you are trying to get the field by getCustomAttribute()? Apr 7, 2017 at 12:04
  • I didn't try to get the field. Where can i do that?
    – Rufas
    Apr 7, 2017 at 14:05

1 Answer 1

0

Try Below code to get category attribute value.

app/design/frontend/package/theme/template/catalog/category/view.phtml

<?php if($_customAttribute = $this->getCurrentCategory()->getCustomAttribute()): ?>
    <?php echo $_helper->categoryAttribute($_category, $_customAttribute, 'custom_attribute') ?>
<?php endif; ?>
1
  • When i try this code my products disappear and i still can't see the attribute value
    – Rufas
    Apr 10, 2017 at 6:24

Your Answer

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

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