Magento – How to Get All Custom Category Attribute Values

categoryeav

I have created module that add custom attribute in Manage Categories section. Say My custom category attribute is category_sku, and it is a text field.

I see that the value of my custom attribute is stored in catalog_category_entity_text table.

But how to populate all the values of it?

I tried using the below code, but it return NULL.

Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'category_sku')->getValue();

Best Answer

I'm doing it in phtml file like this way

<?php $categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*'); ?>

<?php foreach ($categories as $category): ?>
   <?php $categorySku = $category->getCategory_sku(); ?>
   <?php print_r ($categorySku); ?>
<?php endforeach; ?>

That way I can populate all my custom category attribute values which is category_sku :).

And this will make it to a select option list.

    <?php $categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*'); ?>

        <select id="my-id" name="my-name">
            <option value="">Select</option>
            <?php foreach ($categories as $category): ?>
<?php /*magento fetch data by using get and attibute name like banner_id change to getBannerId*/   ?>
                <?php $categorySku = $category->getCategorySku(); ?>
                <option value="<?php echo $categorySku; ?>"><?php echo $categorySku; ?></option>
            <?php endforeach; ?>
        </select>