Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 1);
  5.  
  6. $ATTRIBUTE_CODE = 'attribute_code';
  7. $ATTRIBUTE_GROUP = 'attribute_group'; //General
  8.  
  9. use MagentoFrameworkAppBootstrap;
  10. require __DIR__ . '/app/bootstrap.php';
  11.  
  12. $bootstrap = Bootstrap::create(BP, $_SERVER);
  13.  
  14. $objectManager = $bootstrap->getObjectManager();
  15. $state = $objectManager->get(MagentoFrameworkAppState::class);
  16. $state->setAreaCode('adminhtml');
  17.  
  18. /* Attribute assign logic */
  19. $eavSetup = $objectManager->create(MagentoEavSetupEavSetup::class);
  20. $config = $objectManager->get(MagentoCatalogModelConfig::class);
  21. $attributeManagement = $objectManager->get(MagentoEavApiAttributeManagementInterface::class);
  22.  
  23. $entityTypeId = $eavSetup->getEntityTypeId(MagentoCatalogModelProduct::ENTITY);
  24. $attributeSetIds = $eavSetup->getAllAttributeSetIds($entityTypeId);
  25. foreach ($attributeSetIds as $attributeSetId) {
  26. if ($attributeSetId) {
  27. $group_id = $config->getAttributeGroupId($attributeSetId, $ATTRIBUTE_GROUP);
  28. $attributeManagement->assign(
  29. 'catalog_product',
  30. $attributeSetId,
  31. $group_id,
  32. $ATTRIBUTE_CODE,
  33. 999
  34. );
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement