get configurable product attributes labels and id of current product in magento

get configurable product attributes labels and id of current product in magento

July 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
get configurable product attributes labels and id of current product in magento

Configuring Product Attributes Labels and IDs in Magento

As a developer working on a Magento-powered e-commerce site, you might find yourself needing to access specific configurable product attributes labels and their corresponding identifiers for the current product being displayed. In this post, we’ll guide you through achieving this goal while also addressing the issue of enabling default configurable options with a custom theme.

Understanding the Current Approach

Let’s first examine the provided code snippet:

<?php
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
foreach ($attribute->getSource()->getAllOptions(true, true) as $instance)
{
    $myArray[$instance['value']] = $instance['label'];
}
print_r($myArray);
?>

This script retrieves the color attribute for catalog products and populates an array $myArray with all available color options and their respective labels. The getAllOptions() method fetches both the option values and labels, which are then printed using print_r().

While this approach works for displaying all color attributes, it doesn’t satisfy your requirement to display only those attributes that are actually used by the current product being viewed.

Retrieving Used Attributes Only

To achieve this, you’ll need to access the current product object and extract its configurable options. Here’s an updated version of the code:

<?php
$product = Mage::registry('current_product');
if ($product->isConfigurable()) {
    $usedAttributes = array();
    foreach($product->getTypeInstance()->getUsedProductAttributeIds() as $attributeId){
        $attribute = Mage::getModel('catalog/product')->load($attributeId);
        $usedAttributes[$attribute->getId()] = $attribute->getData('attribute_code');
    }
}
print_r($usedAttributes);
?>

In this version, we first check if the current product is configurable using isConfigurable(). If true, we retrieve all used product attribute IDs via $product->getTypeInstance()->getUsedProductAttributeIds().

Next, we iterate through these IDs and load each attribute model using Mage::getModel('catalog/product')->load($attributeId). We then store the attribute ID as the key and its code (i.e., label) as the value in the $usedAttributes array.

The final result is an array containing only those attributes actually used by the current product, along with their respective IDs and labels.

Enabling Default Configurable Options

Regarding your concern about enabling default configurable options when using a custom theme, this issue often arises due to theme-specific modifications or overrides of the configurable products template files. To resolve this:

  1. Ensure that you have the Magento default theme installed (not necessarily active). The default theme serves as a fallback for any missing or overridden templates in your custom theme.

  2. Check if your custom theme contains an override for the catalog/product/view/type_configurable.phtml file used to display configurable product options. If so, compare it with the default version located at app/design/frontend/base/default/template/catalog/product/view TYPE_CONFIGURABLE.phtml.

  3. If there are significant differences or missing elements in your custom template compared to the default one, you can either:

    • Refactor the custom theme file to include all necessary elements for displaying configurable options.
    • Revert back to using the default template by removing or commenting out any customizations.

Conclusion

In this post, we’ve addressed two key aspects of working with product attributes in Magento:

  1. Retrieving only those attribute labels and IDs that are actually used by the currently displayed product. This is achieved by loading the current product object and extracting its used product attribute IDs.

  2. Enabling default configurable options when using a custom theme. We’ve discussed the importance of having the default theme installed as a fallback, reviewing any overrides in your custom template, and ensuring all necessary elements for displaying configurable options are present.

Remember that proper access to Magento’s registry and model objects is crucial for efficiently retrieving product data. Always ensure you have the appropriate permissions and follow best practices when working with Magento’s core functionalities.

For more in-depth guidance on Magento development best practices and theme customization techniques, feel free to explore our comprehensive resources at Laravel Company.

Catalog Themes Configuration Errors

Our network