1

I want to remove all the default attribute from my newly created product attribute set

My script is :

public function __construct(EavSetupFactory $eavSetupFactory, AttributeSetFactory $attributeSetFactory, CategorySetupFactory $categorySetupFactory)
{
    $this->eavSetupFactory = $eavSetupFactory;
    $this->attributeSetFactory = $attributeSetFactory; 
    $this->categorySetupFactory = $categorySetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    // CREATE ATTRIBUTE SET 
    $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);

    $attributeSet = $this->attributeSetFactory->create();
    $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
    $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
    $datas = [
        [
            'attribute_set_name' => 'Testing', 
            'entity_type_id' => $entityTypeId,
            'sort_order' => 200,
        ]

    ];

    foreach ($datas as $data) {
        $attributeSet->setData($data);
        $attributeSet->validate();
        $attributeSet->save();
        $attributeSet->initFromSkeleton($attributeSetId);
        $attributeSet->save();
    }

    // CREATE PRODUCT ATTRIBUTE
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

    // CREATE PRODUCT ATTRIBUTE
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'blockcontent',
        [
            'type' => 'text',
            'label' => 'Block Content',
            'input' => 'multiselect',
            'source' => \Test\ProductAttribute\Model\Product\Attribute\Source\Blockcontent::class,
            'frontend' => '',
            'required' => false,
            'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
            'sort_order' => '30',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'default' => null,
            'visible' => true,
            'user_defined' => true,
            'searchable' => true,
            'filterable' => true,
            'comparable' => true,
            'visible_on_front' => true,
            'unique' => false,


            'used_in_product_listing' => true,
            'is_used_in_grid' => true,
            'is_visible_in_grid' => true,
            'is_filterable_in_grid' => true,
            'option' => ''
        ]
    );
    $eavSetup->addAttributeToGroup(
        \Magento\Catalog\Model\Product::ENTITY,
        'Testing',
        'General', // group
        'blockcontent'
    );



    $setup->endSetup();
}

}

Everything is working fine but in my custom attribute set all default attribute "name, description etc" also coming which i dont want.

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.