Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2. namespace VendorNameModuleNameSetup;
  3. use MagentoEavSetupEavSetup;
  4. use MagentoEavSetupEavSetupFactory;
  5. use MagentoFrameworkSetupInstallDataInterface;
  6. use MagentoFrameworkSetupModuleContextInterface;
  7. use MagentoFrameworkSetupModuleDataSetupInterface;
  8.  
  9. class InstallData implements InstallDataInterface
  10. {
  11.  
  12. private $eavSetupFactory;
  13.  
  14. /**
  15. * Init
  16. *
  17. * @param EavSetupFactory $eavSetupFactory
  18. */
  19. public function __construct(EavSetupFactory $eavSetupFactory)
  20. {
  21. $this->eavSetupFactory = $eavSetupFactory;
  22. }
  23.  
  24. public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  25. {
  26. /** @var EavSetup $eavSetup */
  27. $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
  28. /**
  29. * Add attributes to the eav/attribute
  30. */
  31.  
  32. $eavSetup->addAttribute(
  33. MagentoCatalogModelProduct::ENTITY,
  34. 'custom_attribute',
  35. [
  36. 'group' => 'General',
  37. 'type' => 'int',
  38. 'backend' => '',
  39. 'frontend' => '',
  40. 'label' => 'Custom Label',
  41. 'input' => 'boolean',
  42. 'class' => '',
  43. 'source' => MagentoEavModelEntityAttributeSourceBoolean::class,
  44. 'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
  45. 'visible' => true,
  46. 'required' => false,
  47. 'user_defined' => false,
  48. 'default' => '1',
  49. 'searchable' => false,
  50. 'filterable' => false,
  51. 'comparable' => false,
  52. 'visible_on_front' => false,
  53. 'used_in_product_listing' => false,
  54. 'unique' => false,
  55. 'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
  56. ]
  57. );
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement