Is there a way to find out what each argument of attribute does?
-
05-10-2020 - |
Domanda
What i want to know is that exactly how much arguments an attribute has and how can we know what each argument does ?
e.g. Consider adding an attribue for customer.
Here's the code where you can find some of the parameters.
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "verified_buyer", array(
"type" => "integer",
"backend" => "",
"label" => "Verified Buyer",
"input" => "checkbox",
"source" => "",
"visible" => true,
"required" => false,
"default" => 0,
"frontend" => "",
"unique" => false,
"note" => "",
"sort_order" => "100"
));
Let me know if there is any resource/article about it.
Thanks :)
Soluzione
You can find an attribute description in the Magento\Eav
module:
app/code/Magento/Eav
The main model for the attribute is Magento\Eav\Model\Attribute
. The addAttribute
method is defined in the Magento\Eav\Setup\EavSetup
class. All properties was mapped to the eav attribute columns in the Magento\Catalog\Model\ResourceModel\Eav\Attribute\PropertyMapper
:
/**
* Map input attribute properties to storage representation
*
* @param array $input
* @param int $entityTypeId
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function map(array $input, $entityTypeId)
{
return [
'attribute_model' => $this->_getValue($input, 'attribute_model'),
'backend_model' => $this->_getValue($input, 'backend'),
'backend_type' => $this->_getValue($input, 'type', 'varchar'),
'backend_table' => $this->_getValue($input, 'table'),
'frontend_model' => $this->_getValue($input, 'frontend'),
'frontend_input' => $this->_getValue($input, 'input', 'text'),
'frontend_label' => $this->_getValue($input, 'label'),
'frontend_class' => $this->_getValue($input, 'frontend_class'),
'source_model' => $this->_getValue($input, 'source'),
'is_required' => $this->_getValue($input, 'required', 1),
'is_user_defined' => $this->_getValue($input, 'user_defined', 0),
'default_value' => $this->_getValue($input, 'default'),
'is_unique' => $this->_getValue($input, 'unique', 0),
'note' => $this->_getValue($input, 'note'),
'is_global' => $this->_getValue(
$input,
'global',
\Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL
)
];
}
I can't answer all your questions, but I think this information will help you to find the correct way.