1

Tell me how to implement attribute transfer to the desired group.

I have attribute set

            $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);

            $attributeSet = $this->attributeSetFactory->create();
            $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
            $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
            $data = [
                'attribute_set_name' => 'Bed Attribute Set',
                'entity_type_id' => $entityTypeId,
                'sort_order' => 200,
            ];
            $attributeSet->setData($data);
            $attributeSet->validate();
            $attributeSet->save();
            $attributeSet->initFromSkeleton($attributeSetId);
            $attributeSet->save();

and attribute

            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'Bed Left Image',
                [
                    'type' => 'text',
                    'label' => 'YOUR ATTRIBUTE LABEL',
                    'backend' => '',
                    'frontend' => '',
                    'input' => 'textarea',
                    'wysiwyg_enabled'   => true,
                    'source' => '',
                    'required' => false,
                    'sort_order' => 19,
                    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                    'used_in_product_listing' => true,
                    'visible_on_front' => true,
                    'attribute_set_id' => $attributeSet->getId(),
                    'is_html_allowed_on_front' => true,
                    'visible' => true,
                    'user_defined' => true,
                    'searchable' => false,
                    'filterable' => false,
                    'comparable' => false,
                    'visible_in_advanced_search' => false,
                    'unique' => false,
                    'apply_to' => ''
                ]
            );

and I want to make it so that the created attribute was available only in this attribute set set and was added to the 'Content' group.

I add the attribute to the attribute set

'attribute_set_id' => $ attributeSet-> getId ()

and to the group

'Group' => 'Content'

but after that the attribute is available on all products and atribute set.

I tried not to add the attribute to the group, so that it would appear in my admin panel in unussigned attributes and I could add it manually to the desired group through the admin interface, and it worked as needed. enter image description here

But now i'am need to do this programmatically, tell me how plz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.