Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7609963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:18:16+00:00 2026-05-31T01:18:16+00:00

How I can get attribute values for some attribute that are used at least

  • 0

How I can get attribute values for some attribute that are used at least in one product?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:18:17+00:00Added an answer on May 31, 2026 at 1:18 am

    I believe you are not trying to read an attribute value of a product model, but get a list of all used values for a specific attribute.

    “Plain” attributes

    Plain attributes are all attributes that don’t use a select or multiselect for input, but a text or textarea field or something similar.

    For these attributes use this:

    // specify the attribute code
    $attributeCode = 'name';
    
    // build and filter the product collection
    $products = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToFilter($attributeCode, array('notnull' => true))
            ->addAttributeToFilter($attributeCode, array('neq' => ''))
            ->addAttributeToSelect($attributeCode);
    
    // get all distinct attribute values
    $usedAttributeValues = array_unique($products->getColumnValues($attributeCode));
    

    “Option” attributes

    If it is a select or multiselect attribute, you still need to map the option ID’s to option values. That is the case if you are getting a list of integers instead of human readable labels (e.g. for the color or manufacturer attribute).

    // specify the select or multiselect attribute code
    $attributeCode = 'color';
    
    // build and filter the product collection
    $products = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToFilter($attributeCode, array('notnull' => true))
            ->addAttributeToFilter($attributeCode, array('neq' => ''))
            ->addAttributeToSelect($attributeCode);
    
    $usedAttributeValues = array_unique($products->getColumnValues($attributeCode));
    
    // ---- this is the different part compared to the previous example ----
    
    // fetch the attribute model
    $attributeModel = Mage::getSingleton('eav/config')
            ->getAttribute('catalog_product', $attributeCode);
    
    // map the option id's to option labels
    $usedAttributeValues = $attributeModel->getSource()->getOptionText(
        implode(',', $usedAttributeValues)
    );
    
    // $usedAttributeValues now contains an array of used values in human readable format
    

    Direct DB query example

    Depending on where you want to do this, here is an example of fetching the values without using a product collection. It is slightly more efficient.
    Only use the following code in resource models, as thats where DB related code belongs.
    This is meant as an educational example to show how to work with Magento’s EAV tables.

    // specify the attribute code
    $attributeCode = 'color';
    
    // get attribute model by attribute code, e.g. 'color'
    $attributeModel = Mage::getSingleton('eav/config')
            ->getAttribute('catalog_product', $attributeCode);
    
    // build select to fetch used attribute value id's
    $select = Mage::getSingleton('core/resource')
            ->getConnection('default_read')->select()
            ->from($attributeModel->getBackend()->getTable(), 'value')
            ->where('attribute_id=?', $attributeModel->getId())
            ->distinct();
    
    // read used values from the db
    $usedAttributeValues = Mage::getSingleton('core/resource')
            ->getConnection('default_read')
            ->fetchCol($select);
    
    // map used id's to the value labels using the source model
    if ($attributeModel->usesSource())
    {
        $usedAttributeValues = $attributeModel->getSource()->getOptionText(
            implode(',', $usedAttributeValues)
        );
    }
    
    // $usedAttributeValues now contains an array of used option value labels
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Logging can get complicated, quickly. Considering that you have some code, how do you
How can I get all tr elements without id attribute? <tr id=name>...</tr> <tr>...</tr> <tr>...</tr>
Can anyone tell me how can I get the xpath of the name attribute
I have an attribute declared on property. How can I get the property name
How can i create an attribute with a namespace? To get the following output?
I have one table having ID and other attributes. How can I get list
Some frameworks (Spring, Tomcat itself) add servlet request attributes that cannot be used within
I'm working on a class that is going to be used by some people
Can get all triples with value null in specific field? All people with date_of_birth
I can get easily see what projects and dlls a single project references from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.