1

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();
2
  • Your wording seems ambiguous. Are you trying to ask how you can provide a list of options to choose from whenever you want to set this value?
    – benmarks
    Commented Sep 29, 2013 at 11:21
  • Yes, I want to provide an option list with the values of my custom attribute. But I'm getting stuck trying to populate the values.
    – Wakanina
    Commented Sep 29, 2013 at 11:35

2 Answers 2

1

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>
0

I need to the something very similar to this but I can't get it to work. I hope get some answers from the wise guys out her.

I need to get a attribute collection of the current category for example. I have 4 custom attributes (images) that I would like to use for category slider

<?php $category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
      $categories =$category->getCollection()
      ->addAttributeToSelect(array('sliderimg1','sliderimg2','sliderimg3','sliderimg4'))
    ->addAttributeToFilter('is_active', 1)
    ->addIdFilter($category->getChildren())
    ->addAttributeToSort('position', ASC);?>

with this code I can get the attributes to show but, how can I add it to my slider? please help. I tried

 <div id="capabilities" class="detail detail--capabilities">
<div class="gallery" data-flickity='{ "imagesLoaded": true, "wrapAround": true, "autoPlay": 10000}'>
     <?php foreach ($categories as $category): ?>
    <div class="gallery-row gallery-one-column">
        <div class="gallery-item gallery-item--features gallery-item--left">
            <div class="gallery-image"><img class="imgl" style="width:100%; height:100%; object-fit: cover;  object-position: 69% 37%;" src="<?php echo Mage::getBaseUrl('media') . 'catalog' . '/' . 'category' . '/' . $category->getSliderimg1() ?>"></div>
            <div class="gallery-features">
                 <p class="hro1"><i> <?php echo $category->getName() ?></i></p>
                <h1 class="hro"><?php echo $category->getF_title1() ?></h1>
                <!--<p><?php echo $category->getF_desc1() ?><p/>-->
                <div class="hromsrp"><p>MSRP <span><strong><?php echo $category->getMsrp() ?></strong></span></p></div>
                <button type="button" class="btn btn1 menu-btn-brp-default" onClick="location.href='<?php echo $category->getUrl(); ?>'">VIEW DETAILS&nbsp;<span class="glyphicon glyphicon-chevron-down"></span></button>
            </div>
        </div>
    </div>
    <?php endforeach; ?>
</div>

This gets the attribute image for each category... but I need to create a slider for each category how can I get the other 3 attributes (sliderimg2,sliderimg3,sliderimg4 ) in to my category slider for the current category only.

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.