How can I get all Magento Product Brands

How can I get all Magento Product Brands

September 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How can I get all Magento Product Brands

Getting All Magento Product Brands: An Efficient Approach

As a developer working on a Magento project, you might find yourself needing to display all of the product brands on a dynamic page for easy navigation. Instead of iterating through every single product in your collection, which can be resource-intensive and slow, there’s a more efficient way to achieve this.

The Problem

The current approach involves retrieving each individual product from the database, checking its brand attribute, and then filtering out duplicates. While this works, it’s not the most performance-friendly method for large catalogs.

A Better Solution: Direct Brand Retrieval


To optimize this process, we can directly query the eav_attribute table to find all the distinct options assigned to the ‘brand’ attribute. Here’s a step-by-step guide:

  1. Identify the Attribute ID

    First, you need to determine the internal ID of your brand attribute. You can find this by checking the attribute_id column in the eav_attribute table for an entry where attribute_code = 'brand'.

    SELECT entity_type_id, attribute_id FROM eav_attribute WHERE attribute_code = 'brand';
    
  2. Query Distinct Options

    Once you have the ID, you can use it to query all distinct options (brands) directly from the eav_attribute_option table.

    SELECT option_id, value FROM eav_attribute_option WHERE attribute_id = <YOUR_ATTRIBUTE_ID>;
    
  3. Prepare for Use

    With this data in hand, you can create an array or object containing all of your product brands without touching the main catalog_product_entity table. This significantly reduces database queries and improves performance.

Implementing the Solution


To use this approach in your code, you might need to create a helper function or service that handles these database operations:

class BrandHelper {
    public function getAllBrands()
    {
        $connection = $this->resourceConnection->getConnection();
        $brandsQuery = "SELECT option_id, value FROM eav_attribute_option WHERE attribute_id=<YOUR_ATTRIBUTE_ID>";
        return $connection->fetchAll($brandsQuery);
    }
}

Then, in your template or controller:

$brandHelper = $this->_objectManager->get('Vendor\Module\Helper\Brand');
$brands = $brandHelper->getAllBrands();

Conclusion


By directly querying the attribute option table, you can significantly optimize the process of retrieving all product brands in Magento. This approach reduces database load and improves the performance of your dynamic brand page.

Remember to replace <YOUR_ATTRIBUTE_ID> with the actual ID from step 1.

For a more detailed guide on optimizing Magento performance at scale, check out our comprehensive post here.

This method allows you to create dynamic brand links quickly and efficiently, improving your site’s user experience while keeping the database happy. Happy coding!

Catalog Database Performance Errors

Our network