AD0-E724 · Question #48
A developer is creating a new EAV attribute for products programmatically using a data patch. They want to ensure this new attribute is automatically included in the "Default" attribute set upon creat
The correct answer is C. Assign the attribute to the desired attribute group and attribute set.. In Magento's EAV system, creating an attribute only defines it in the eav_attribute table - it does not automatically associate it with any attribute set or group. To make it appear in the "Default" attribute set, you must explicitly call addAttribute() on the attribute set, link
Question
A developer is creating a new EAV attribute for products programmatically using a data patch. They want to ensure this new attribute is automatically included in the "Default" attribute set upon creation. Which step is required within the data patch's 'apply()' method, after the attribute itself has been created?
Options
- ASet the 'is_user_defined' property of the attribute to true.
- BRun the 'indexer:reindex' command.
- CAssign the attribute to the desired attribute group and attribute set.
- DFlush the 'eav' cache type.
How the community answered
(33 responses)- A9% (3)
- B18% (6)
- C70% (23)
- D3% (1)
Explanation
In Magento's EAV system, creating an attribute only defines it in the eav_attribute table - it does not automatically associate it with any attribute set or group. To make it appear in the "Default" attribute set, you must explicitly call addAttribute() on the attribute set, linking the attribute to both a set and a group (e.g., "General"). This is done via EavSetup::addAttributeToGroup() or addAttributeToSet() within the apply() method after the attribute is created.
Why the distractors are wrong:
- A -
is_user_definedcontrols whether admins can delete the attribute via the UI; it has no effect on attribute set membership. - B - Reindexing is a post-deployment concern for surfacing data in search/catalog; it plays no role in attribute set assignment during a data patch.
- D - Flushing the EAV cache may be useful after schema changes, but it cannot create a relationship that was never written to the database in the first place.
Memory tip: Think of it as a two-step registration - first you create the attribute (like writing a job description), then you assign it to a set/group (like adding that role to a department). The attribute doesn't know it belongs to "Default" until you explicitly tell the set it exists.
Topics
Community Discussion
No community discussion yet for this question.