Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
unique_input_attribute.php
Go to the documentation of this file.
1 <?php
11  \Magento\Eav\Model\Entity\Type::class
12 );
13 $entityType->loadByCode('catalog_product');
14 $defaultSetId = $entityType->getDefaultAttributeSetId();
17  \Magento\Eav\Model\Entity\Attribute\Set::class
18 );
20 $defaultGroupId = $defaultSet->getDefaultGroupId();
21 
24  \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
25 );
26 $attribute->setAttributeCode(
27  'unique_input_attribute'
28 )->setEntityTypeId(
29  $entityType->getEntityTypeId()
30 )->setAttributeGroupId(
32 )->setAttributeSetId(
34 )->setFrontendInput(
35  'text'
36 )->setFrontendLabel(
37  'Unique Input Attribute'
38 )->setBackendType(
39  'varchar'
40 )->setIsUserDefined(
41  1
42 )->setIsUnique(
43  1
44 )->save();