We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    If you want to create a product attribute programmatically, but not by admin then this blog post is right the solution for you.

    Create file app/code/Magemonkey/CustomAttribute/Setup/InstallData.php

    <?php
    namespace MagemonkeyCustomAttributeSetup;
    
    use MagentoEavSetupEavSetup;
    use MagentoEavSetupEavSetupFactory;
    use MagentoFrameworkSetupInstallDataInterface;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupModuleDataSetupInterface;
    
    class InstallData implements InstallDataInterface
    {
    	private $eavSetupFactory;
    
    	public function __construct(EavSetupFactory $eavSetupFactory)
    	{
    		$this->eavSetupFactory = $eavSetupFactory;
    	}
    	public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    	{
    		$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
    		$eavSetup->addAttribute(
    			MagentoCatalogModelProduct::ENTITY,
    			'custom_attribute',
    			[
    				'type' => 'text',
    				'backend' => '',
    				'frontend' => '',
    				'label' => 'Custom Atrribute',
    				'input' => 'text',
    				'class' => '',
    				'source' => '',
    				'visible' => true,
    				'required' => true,
    				'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
    				'user_defined' => false,
    				'default' => '',
    				'visible_on_front' => false,
    				'used_in_product_listing' => true,
    				'unique' => false,
    				'apply_to' => '',
    				'searchable' => false,
    				'filterable' => false,
    				'comparable' => false
    			]
    		);
    	}
    	
    }

     

    field_5bfb909c5ccae

      Get a Free Quote