10

I have an customer attribute defined as follows:

$customerSetup->addAttribute(Customer::ENTITY, "attr_code",  [
            "type"     => "varchar",
            "backend"  => "",
            "label"    => "Attribute Label",
            "input"    => "text",
            "source"   => "Magento\Eav\Model\Entity\Attribute\Source\Table",
            "visible"  => true,
            "required" => false,
            "default"  => "",
            "frontend" => "",
            "unique"   => false,
            "note"     => "",
            'system'   => 0,
            'user_defined' => true
]);

My question is: what's the difference on the attribute if I set user_defined to false? And in which situations I should set user_defined to true or false?

19

Actually Magento user_defined = false attributes are known as system attributes. So Magento has some of their system attribute, which we can not delete from admin panel. So magento won't allow system attribute to be deleted. We can delete them through database but it is not safe.

So Attributes which are highly required to run a system that type of attribute we can create as system attributes. But in opposite side, we can easily delete user defined attributes from admin panel.

Hope it helps Thanks.

5

Magento system attributes are set to false for user_defined so our custom attributes should be set to true. System attributes can not be deleted so if you set false to user_defined, your attribute will work as system attribute.

  • 1
    So you mean it's just for indication, no real differences between them? – PY Yick Sep 1 '17 at 5:41
3

To add to this:

If you add attributes via Install-/ UpdateSchema make sure to add to 'user_defined' => true. Only non system attributes (eg. is_user_defined = 1) can be used for configurable products.

2

In fact, I notice a big difference when I learnt Magento 1. If an attribute is set to be user_defined = true, it then won't be created in table eav_entity_attribute. But still you can find it in table eav_attribute. If set user_defined = false, then when it's created it will appear in both eav_entity_attribute and eav_attribute tables. But in return, I don't know why this make the difference / affect.

I'm not sure about Magento 2, but I guess you can verify it easily and let others know.

1

If an attribute is set as 'user_defined' then a user may define the option values inside the attribute user interface.

However if you are using a source model then 'user_defined' must be set to false, otherwise the options from the source model are not loaded.

1

user_defined = true attributes are generally created by catalog manager to have product specific information.
user_defined = false for Magento default attributes which are required for some functionalities to work or any module providing some additional feature based on attribute, like sku, qty, website_ids, product_online are system attributes required to manage quantity and scope of product, same way is_featured or show_on_homepage can be some attribute doing something in backend to provide some feature and shouldn't be deleted by admin user that may break the functionality.

1

Another thing that user defined does is that it determines if you can edit or not the options of the attribute from the attribute edit page in back office, therefor if you have an attribute with specific labels that you do not want an admin user to change, you should set "user_defined" to false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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