Feb 22

Creating Configurable Products: Magento's Undocumented Requirements for Configurable Attributes

I ran into this issue recently, while trying to create a configurable product in Magento. After clicking the Add Product button and selecting Configurable Product ...

Create Product Settings form
I encountered a dead end and the following message:This attribute set does not have attributes which we can use for configurable product”
Select Configurable Attributes form - None Available!
I was surprised because I had already created several eligible attributes, I began double-checking my attribute configuration. Magento provides this helpful(?) tip:
Only attributes with scope "Global", input type "Dropdown" and Use To Create Configurable Product "Yes" are available.
Seems simple enough, but it's not quite. After many hours double checking my attributes, creating new attribute sets, disabling modules, reinstalling my database from scratch and attempting all sorts of desperate debugging tactics, I was surprised to learn that there are actually two more requirements: the attribute must be visible (not an issue for me) and the attribute must be set to user defined. The following code from the class Mage_Catalog_Model_Product_Type_Configurable shows the true requirements for a configurable attribute:
/**
* Checkin attribute availability for create superproduct
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @return bool
*/
public function canUseAttribute(Mage_Eav_Model_Entity_Attribute $attribute)
{
    $allow = $attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL // GLOBAL
    && $attribute->getIsVisible()      // VISIBLE
    && $attribute->getIsConfigurable() // CONFIGURABLE
    && $attribute->usesSource()        // DROPDOWN
    && $attribute->getIsUserDefined(); // USER DEFINED
    return $allow;
}
The key, for me, was setting the attributes' user_defined property to true. If you create your attributes through the Admin UI, then user_defined will automatically be set to true. However, if you define your attributes in a setup script, as I did, you must set it manually.
$installer->addAttribute('catalog_product', 'color', array(
    'type' => 'int',
    'label' => 'Color',
    'input' => 'select',
    // THIS IS NECESSARY FOR ATTRIBUTES USED TO CREATE CONFIGURABLE PRODUCTS
    'user_defined' => true,
    'required' => true,
    'filterable' => 1,
    ...
    'option' => array(
        'values' => array(
            'Black',
            'Brown',
            'Grey',
        )
    ),
));
To modify this field for an existing attribute, edit the database table. There is no way to edit this property through Magento's admin interface. UPDATE `eav_attribute` SET `is_user_defined`=1 WHERE `attribute_code`='color'; EAV Attribute Table Data EAV Attribute Table Data Continued Refresh the page you were stuck on and you should now see a configurable attribute: Select Configurable Attributes form That's it! I hope this saves you some debugging time! Matt Olsen a Senior Developer at DO, was recently Magento Certified