Here is my installation method. Why, after installation, in the default attribute set, I see only the attributes https://prnt.sc/s20b3a, https://prnt.sc/s20czw? They should not be here. How to fix?
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);
$categorySetup = $this->_categorySetupFactoryProduct->create(['setup' => $setup]);
// version 1.4.34
// get default attribute set id
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId); // default attribute set
foreach ($this->dataAttrProduct as $section) {
// add attribute set
$attributeSet = $this->_attributeSetFactoryProduct->create();
$data = [
'attribute_set_name' => $section['attr_set_name'],
'entity_type_id' => $entityTypeId,
'sort_order' => 100,
];
$attributeSet->setData($data);
$attributeSet->validate();
$attributeSet->save();
$attributeSet->initFromSkeleton($attributeSetId);
$attributeSet->save();
// add attributes
foreach ($section['attrs'] as $attr) {
if (empty($attr['code']) && empty($attr['label'])) continue;
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
$attr['code'],
[
'type' => $attr['type'],
'backend' => '',
'frontend' => '',
'label' => $attr['label'],
'input' => $attr['input'],
'class' => '',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => $attr['visible'],
'required' => $attr['required'],
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => $attr['visible_on_front'],
'used_in_product_listing' => $attr['used_in_product_listing'],
'unique' => false,
'apply_to' => '',
'attribute_set' => $section['attr_set_name']
]
);
}
// add attributes group in attribute set
$attributeSetIdNomenclatures = $eavSetup->getAttributeSetId($entityTypeId,$section['attr_set_name']);
$eavSetup->addAttributeGroup(
$entityTypeId,
$attributeSetIdNomenclatures,
$section['attr_group_name'],
100
);
// add attribute to group
$attributeGroupId = $eavSetup->getAttributeGroupId($entityTypeId, $attributeSetIdNomenclatures, $section['attr_group_name']);
foreach ($section['attrs'] as $attr) {
$categorySetup->addAttributeToGroup(
$entityTypeId,
$attributeSetIdNomenclatures,
$attributeGroupId,
$attr['code'],
10
);
}
}
$setup->endSetup();
}
Values $ this-> dataAttrProduct . What should happen https://prnt.sc/s28b9p
'fastener' => [
'attr_group_name' => 'Fastener',
'attr_set_name' => 'Fastener',
'attrs' => [
0 => [
'code' =>'fasteners_sub_type',
'type' => 'text',
'input' => 'text',
'label' =>'Подраздел',
'visible' => true,
'required' => false,
'visible_on_front' => false,
'used_in_product_listing' => false
],
1 => [
'code' =>'fasteners_brand',
'type' => 'int',
'input' => 'select',
'label' =>'Бренд',
'visible' => true,
'required' => false,
'visible_on_front' => true,
'used_in_product_listing' => true
],
],
]