2

I have a product attribute, which is populated by a source model which is extended from AbstractSource. Because of this the attribute is not set with 'is_user_defined' = 1 and therefore I am not able to use this attribute as a configurable option.

So my question is... How can I create an attribute that can be used as a configurable option whilst being populated from the database?

Thanks.

1 Answer 1

0

General info:
Here are the rules for using an attribute in a configurable product.
They come from \Magento\ConfigurableProduct\Model\Product\Type\Configurable::canUseAttribute

public function canUseAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute)
{
    return $attribute->getIsGlobal() == \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL &&
        $attribute->getIsVisible() &&
        $attribute->usesSource() &&
        $attribute->getIsUserDefined();
}

So basically, the attribute should be global (is_global = 1 in talbe catalog_eav_attribute), is visible (is_visible = 1 in table catalog_eav_attribute), usesSource (type is select or multiselect and source_model is not empty - all in table eav_attribute) and is user defined (is_user_defined = 1 in the eav_attribute table)

Now for your specific problem. You can change is_user_defined to 1 in the eav_attribute table for your specific product.

1
  • Thank you, this seems to have done the job, I did set 'is_user_defined' when creating the attribute with code, but this didn't seem to work so I am not sure why it works when I have set it to true in the eav table.
    – NetStorm
    Commented Feb 22, 2019 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.