7
'system' => 0

What that property of (product - only?) does or means? I've noticed that all built-in Magento attribute has it with value 1. So my custom attributes should have 0? is it only for marking custom and built-in attributes?

2 Answers 2

6

System attributes are the default attributes shipped natively with the software.

The purpose is to be able to differentiate Magento system attributes and custom attributes.

I reckon it is similar to Magento 1 as system attributes are used directly in the code logic of Magento 2

7

If some attribute is flagged as "is_system" = true

Then such attribute deny to change some specific options on attribute edit page, as shown below

vendor/magento/module-customer-custom-attributes/Block/Adminhtml/Customer/Address/Attribute/Edit/Tab/General.php

if ($attribute->getIsSystem()) {
    $elements = ['sort_order', 'is_visible', 'is_required', 'used_in_forms'];
}
if (!$attribute->getIsUserDefined() && !$attribute->getIsSystem()) {
    $elements = ['sort_order', 'used_in_forms'];
}
foreach ($elements as $elementId) {
    $form->getElement($elementId)->setDisabled(true);
}

Other place where this attribute is used is EAV Attribute Metadata. But there is one difference in method name: isSystem instead of getIsSystem:

vendor/magento/module-customer/Model/Metadata/AddressMetadata.php

public function getCustomAttributesMetadata($dataObjectClassName = AddressMetadataInterface::DATA_INTERFACE_NAME)
{
    //...
    $customAttributes = [];
    foreach ($this->getAllAttributesMetadata() as $attributeMetadata) {
        // ...
        if (!$isDataObjectMethod && !$attributeMetadata->isSystem()) {
            $customAttributes[] = $attributeMetadata;
        }
    }
    return $customAttributes;
}

Same for Customer you may find here:

\Magento\Customer\Model\Metadata\CustomerMetadata::getCustomAttributesMetadata

These methods are deciding to add or not to add your created attributes to custom_attributes array. It means that these attributes will not be accessible for CRUD operations in Repositories.

And here, as for me, logical bug in magento.

Custom attributes metadata isn't responsible for rendering forms in magento admin.

It means that if attribute has following configuration

is_system = 0
is_required = 1
used_in_forms = [] or with default value ['adminhtml_customer_address']
Attempt to save empty value

Following attribute will not appear on adminhtml customer address edit page, but the model will claiming on saving empty value, when this field does not shown due insufficient value in "used_in_forms" option.

At the same time when you have following configuration:

is_system = 1
is_required = 1
used_in_forms = ['adminhtml_customer_address', 'customer_address_edit']
Attempt to save "blabla"

This attribute does not present inside metadata and will not be saved. Page will be reloaded and no value being saved.

2
  • Thanks a ton! I debugged for hours and luckily happen to went through this. I was in similar situation and your post gives me an idea of where to look at! Kudos!
    – Harish ST
    Aug 14, 2021 at 15:47
  • Do you know if this "system" field also makes the attribute updatable via the Magento API? This is the only difference I see between one attribute I can update via API and one I can't. Nov 4, 2021 at 16:56

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.