How to get attribute codes of super product attributes of a configurable product

How to get attribute codes of super product attributes of a configurable product

August 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get attribute codes of super product attributes of a configurable product

Checking Super Product Attributes of Configurable Products

In Magento, configuring products often involves multiple attributes like Size, Color, Material, etc. These are known as super product attributes or configurable attributes. While working on your eCommerce site, you might need to check if a specific attribute is used to configure a particular product.

For instance, suppose you have a T-shirt that’s available in Small (Size) and Red (Color). You want to know which attributes (Size & Color) are being used to make this configurable product. In this guide, I’ll walk you through how to achieve this using Magento 2’s built-in functionality and some custom code snippets.

Understanding Configurable Products

A configurable product in Magento is a type of virtual product that has multiple simple products associated with it—each representing a variation, or “version,” of the configurable product. The attributes used to determine these variations are called super attributes.

Retrieving Super Product Attributes

To get the attribute codes of these super attributes for a specific configurable product, you can use Magento’s EAV model and retrieve the data from the eav_attribute table.

Here is some sample code that demonstrates this:

use Magento\Eav\Model\Entity\Attribute;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->create('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();

$productId = 1; // Replace with your product ID

$sql = "SELECT entity_type_id, attribute_code
        FROM eav_attribute
        WHERE entity_type_id = (SELECT entity_type_id
                                FROM eav_entity_type
                                WHERE entity_type_code = 'catalog_product')
          AND attribute_set_id IN (
            SELECT attribute_set_id
            FROM catalog_product_super_link
            WHERE product_id = {$productId})";

$results = $connection->fetchAll($sql);

foreach ($results as $row) {
    echo "Entity Type ID: " . $row['entity_type_id'] . PHP_EOL;
    echo "Attribute Code: " . $row['attribute_code'] . PHP_EOL;
}

This script first fetches all configurable attributes related to the specified product. It then prints out their entity type IDs and attribute codes.

Checking Attribute Usage in Configurable Products

Now, let’s say you want to check if an attribute is used to configure any products at all—not just a specific one. For this, you can query the catalog_product_super_link table which stores data about configurable products and their super attributes.

Here’s how you can do it:

use Magento\Eav\Model\Entity\Attribute;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->create('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();

$attributeCode = 'size'; // Replace with the attribute code you want to check

$sql = "SELECT COUNT(*) AS total
        FROM catalog_product_super_link
        WHERE product_id IN (
            SELECT product_id
            FROM catalog_product_entity
            WHERE attribute_set_id IN (
                SELECT attribute_set_id
                FROM eav_attribute_set
                WHERE attribute_set_name LIKE '%%" . $attributeCode . "%%'))";

$count = $connection->fetchOne($sql);

if ($count > 0) {
    echo "The attribute '$attributeCode' is used to configure products." . PHP_EOL;
} else {
    echo "The attribute '$attributeCode' is not used in any configurable product." . PHP_EOL;
}

This script checks if the given attribute code appears anywhere in the catalog_product_entity table alongside the eav_attribute_set table. If it finds a match, that means at least one product uses this attribute for configuration.

Remember to replace ‘size’ with your desired attribute code and adapt these snippets according to your project’s specific needs.

Conclusion

In this guide, we explored how to retrieve super attributes of configurable products in Magento 2 using direct database queries. This approach is straightforward but may not be optimal for large-scale applications due to performance implications.

For production use cases, I recommend leveraging Magento’s API and EAV model for a more secure and efficient approach. You can create custom plugins or observers to intercept relevant events like attribute save or product save and record the associations in your own database table.

This way, you maintain data consistency while reducing the load on the core eav_attribute set relations. It also provides better flexibility for reporting and future extensions.

For more advanced techniques and best practices with Magento 2 development, consider checking out Laravel Company’s resources. They offer a wealth of information on performance optimization, customization, and extension development in the Magento ecosystem.

Magento 2 Catalog Database Configuration

Our network