4

How to create a customer attribute is explained in various answers such as this or this. What they all have in common, is that when creating the attribute its properties user_defined and system are always defined like this:

'user_defined' => true,
'system' => false,

For me this doesn't work. When setting the properties as seen above the attribute is not visible in the adminhtml customer edit form. When setting user_defined => false and system => true it is shown but now saved. It only works (showing in form and saving) when both properties are set to false.

So my question is what is the difference between the two properties and what are they used for?

I am aware that these properties are used to mark "system attributes" which cannot be deleted easily like describes in this answer. I am looking for a more in depth answer what the difference between user_defined and system is. In addition what are both properties used for individually?

3
  • check this link magento.stackexchange.com/questions/191523/… . In this link it explain good one
    – Jinesh
    Commented Apr 8, 2020 at 10:31
  • 2
    Unfortunately this answer only says that user_defined marks attributes as "system attributes" I am aware that both properties are marking attributes as "system attributes". I am looking for an answer that describes the differences between them both and a more in depth approach in what they are used for. Like: "It is used in X places to determine X"
    – Daniel
    Commented Apr 8, 2020 at 12:26
  • 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.
    – Jinesh
    Commented Apr 8, 2020 at 13:24

2 Answers 2

1

The user_defined property has already been explained, so let's have a look at system.

First, note that system is only used for customer and customer address attributes, while user_defined is a core property of all EAV attributes. They map to the following database tables and columns:

  • user_defined => eav_attribute.is_user_defined
  • system => customer_eav_attribute.is_system

I never paid much attention to system because it seems redundant, but looking at the code, it is only ever used in two occasions:

  • customer system attributes (except password_hash) are not imported with the customer import, if they are also set to not visible, see \Magento\CustomerImportExport\Model\Import\Customer
  • customer address system atttributes are not imported with the customer import, if they are also set to not visible, see \Magento\CustomerImportExport\Model\Import\Address

I can only guess why they don't use user_defined for the same purpose.

It is also interesting that the filter methods are implemented in the generic Magento_Eav model (see \Magento\Eav\Model\ResourceModel\Attribute\Collection::addSystemHiddenFilter() and \Magento\Eav\Model\ResourceModel\Attribute\Collection::addSystemHiddenFilterWithPasswordHash) although it obviously only is applicable to the customer attributes.

0

system > you cannot delete it this attribute from admin and it is created by magento core user_defined : you can delete it and generally when u create custom attribute it will be user_defined.

1
  • 1
    Unfortunately this does not answer my question.
    – Daniel
    Commented Apr 9, 2020 at 9:05

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.