Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. <?php
  2. require __DIR__ . '/app/bootstrap.php';
  3. $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
  4. /** @var MagentoFrameworkAppHttp $app */
  5. $app = $bootstrap->createApplication('AttributeSet');
  6. $bootstrap->run($app);
  7.  
  8. <?php
  9. use MagentoFrameworkAppBootstrap;
  10. //include('../app/bootstrap.php');
  11. use MagentoCatalogApiCategoryRepositoryInterface;
  12. class AttributeSet extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
  13. {
  14. protected $_moduleDataSetup;
  15. protected $_eavSetupFactory;
  16.  
  17. public function __construct( //not sure if i can include construct here
  18. ObjectManagerInterface $objectManager,
  19. ModuleDataSetupInterface $moduleDataSetup,
  20. EavSetupFactory $eavSetupFactory,
  21. ) {
  22.  
  23. $this->_objectManager = $objectManager;
  24. $this->_moduleDataSetup = $moduleDataSetup;
  25. $this->_eavSetupFactory = $eavSetupFactory;
  26. }
  27.  
  28. public function launch()
  29. {
  30. $eavSetup = $this->_eavSetupFactory->create([
  31. 'setup' => $this->_moduleDataSetup
  32. ]);
  33.  
  34. $defaultId = $eavSetup->getDefaultAttributeSetId(self::ENTITY_TYPE);
  35.  
  36. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  37. //$entityTypeId = $objectManager->create('MagentoCatalogModelProduct');
  38. $entityTypeId = $objectManager->create('MagentoEavModelConfig')
  39. ->getEntityType(MagentoCatalogApiDataProductAttributeInterface::ENTITY_TYPE_CODE)
  40. ->getEntityTypeId(); // to get entity_type_id by entity_type_code
  41.  
  42. $model = $objectManager->create('MagentoEavApiDataAttributeSetInterface')
  43. ->setId(null)
  44. ->setEntityTypeId(4)
  45. ->setAttributeSetName($name);
  46.  
  47. $objectManager->create('MagentoEavApiAttributeSetManagementInterface')
  48. ->create(self::ENTITY_TYPE, $model, $defaultId)
  49. ->save();
  50. }
  51.  
  52.  
  53. public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
  54. {
  55. return false;
  56. }
  57.  
  58. }
  59.  
  60. use MagentoEavModelEntityTypeFactory;
  61. use MagentoEavModelEntityAttributeSetFactory;
  62. use MagentoEavModelAttributeSetManagement;
  63. use MagentoEavModelAttributeManagement;
  64.  
  65. public function createAttributeSets() {
  66. $entityTypeCode = 'catalog_product';
  67. $entityType = $this->eavTypeFactory->create()->loadByCode($entityTypeCode);
  68. $defaultSetId = $entityType->getDefaultAttributeSetId();
  69.  
  70. $attributeSet = $this->attributeSetFactory->create();
  71. $data = [
  72. 'attribute_set_name' => 'attribute_set_name',
  73. 'entity_type_id' => $entityType->getId(),
  74. 'sort_order' => 200,
  75. ];
  76. $attributeSet->setData($data);
  77.  
  78. $this->attributeSetManagement->create($entityTypeCode, $attributeSet, $defaultSetId);
  79.  
  80. $this->attributeManagement->assign(
  81. 'catalog_product',
  82. $attributeSet->getId(),
  83. $attributeSet->getDefaultGroupId(),
  84. 'attribute_code',
  85. $attributeSet->getCollection()->count() * 10
  86. );
  87. }
  88.  
  89. public function createAttributeSets() {
  90. $entityTypeCode = 'catalog_product';
  91. $entityType = $this->eavTypeFactory->create()->loadByCode($entityTypeCode);
  92. $defaultSetId = $entityType->getDefaultAttributeSetId();
  93.  
  94. $datas = [
  95. [
  96. 'attribute_set_name' => 'attribute_set_name',
  97. 'entity_type_id' => $entityType->getId(),
  98. 'sort_order' => 200,
  99. ],
  100. [
  101. 'attribute_set_name' => 'attribute_set_name_2',
  102. 'entity_type_id' => $entityType->getId(),
  103. 'sort_order' => 300,
  104. ]
  105. ];
  106.  
  107. foreach ($datas as $data) {
  108. $attributeSet = $this->attributeSetFactory->create();
  109.  
  110. $attributeSet->setData($data);
  111.  
  112. $this->attributeSetManagement->create($entityTypeCode, $attributeSet, $defaultSetId);
  113.  
  114. $this->attributeManagement->assign(
  115. 'catalog_product',
  116. $attributeSet->getId(),
  117. $attributeSet->getDefaultGroupId(),
  118. 'attribute_code',
  119. $attributeSet->getCollection()->count() * 10
  120. );
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement