Skip to content

Eav Attributes

Code Slicer edited this page May 18, 2023 · 2 revisions

There are dedicated facades for each type of entity as can be seen here, and all of them share these common methods described below.

create($code, $data)

Create a new attribute with given data, just as you would do in the native $this->eavSetup->addAttribute() method:

// we suggest checking the available fields here: https://mage2gen.com/?main_version=4
$this->categoryAttribute->create('bottom_description', [
    'type' => 'text',
    'label' => 'Description (Bottom)',
    'input' => 'textarea',
    'sort_order' => 50,
    'source' => '',
    'global' => 0,
    'visible' => true,
    'required' => false,
    'user_defined' => false,
    'default' => null,
    'group' => 'General Information',
    'backend' => ''
]);

update($code, $data)

Updates an existent eav attribute of the entity:

$this->productAttribute->create('origin_postcode', [
    'required' => true,
]);

exists($code)

Check if an attribute with given code already exists for the entity:

$this->customerAttribute->exists('is_vip');
Clone this wiki locally