Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require __DIR__ . '/app/bootstrap.php';
- $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
- /** @var MagentoFrameworkAppHttp $app */
- $app = $bootstrap->createApplication('AttributeSet');
- $bootstrap->run($app);
- <?php
- use MagentoFrameworkAppBootstrap;
- //include('../app/bootstrap.php');
- use MagentoCatalogApiCategoryRepositoryInterface;
- class AttributeSet extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
- {
- protected $_moduleDataSetup;
- protected $_eavSetupFactory;
- public function __construct( //not sure if i can include construct here
- ObjectManagerInterface $objectManager,
- ModuleDataSetupInterface $moduleDataSetup,
- EavSetupFactory $eavSetupFactory,
- ) {
- $this->_objectManager = $objectManager;
- $this->_moduleDataSetup = $moduleDataSetup;
- $this->_eavSetupFactory = $eavSetupFactory;
- }
- public function launch()
- {
- $eavSetup = $this->_eavSetupFactory->create([
- 'setup' => $this->_moduleDataSetup
- ]);
- $defaultId = $eavSetup->getDefaultAttributeSetId(self::ENTITY_TYPE);
- $objectManager = MagentoFrameworkAppObjectManager::getInstance();
- //$entityTypeId = $objectManager->create('MagentoCatalogModelProduct');
- $entityTypeId = $objectManager->create('MagentoEavModelConfig')
- ->getEntityType(MagentoCatalogApiDataProductAttributeInterface::ENTITY_TYPE_CODE)
- ->getEntityTypeId(); // to get entity_type_id by entity_type_code
- $model = $objectManager->create('MagentoEavApiDataAttributeSetInterface')
- ->setId(null)
- ->setEntityTypeId(4)
- ->setAttributeSetName($name);
- $objectManager->create('MagentoEavApiAttributeSetManagementInterface')
- ->create(self::ENTITY_TYPE, $model, $defaultId)
- ->save();
- }
- public function catchException(MagentoFrameworkAppBootstrap $bootstrap, Exception $exception)
- {
- return false;
- }
- }
- use MagentoEavModelEntityTypeFactory;
- use MagentoEavModelEntityAttributeSetFactory;
- use MagentoEavModelAttributeSetManagement;
- use MagentoEavModelAttributeManagement;
- public function createAttributeSets() {
- $entityTypeCode = 'catalog_product';
- $entityType = $this->eavTypeFactory->create()->loadByCode($entityTypeCode);
- $defaultSetId = $entityType->getDefaultAttributeSetId();
- $attributeSet = $this->attributeSetFactory->create();
- $data = [
- 'attribute_set_name' => 'attribute_set_name',
- 'entity_type_id' => $entityType->getId(),
- 'sort_order' => 200,
- ];
- $attributeSet->setData($data);
- $this->attributeSetManagement->create($entityTypeCode, $attributeSet, $defaultSetId);
- $this->attributeManagement->assign(
- 'catalog_product',
- $attributeSet->getId(),
- $attributeSet->getDefaultGroupId(),
- 'attribute_code',
- $attributeSet->getCollection()->count() * 10
- );
- }
- public function createAttributeSets() {
- $entityTypeCode = 'catalog_product';
- $entityType = $this->eavTypeFactory->create()->loadByCode($entityTypeCode);
- $defaultSetId = $entityType->getDefaultAttributeSetId();
- $datas = [
- [
- 'attribute_set_name' => 'attribute_set_name',
- 'entity_type_id' => $entityType->getId(),
- 'sort_order' => 200,
- ],
- [
- 'attribute_set_name' => 'attribute_set_name_2',
- 'entity_type_id' => $entityType->getId(),
- 'sort_order' => 300,
- ]
- ];
- foreach ($datas as $data) {
- $attributeSet = $this->attributeSetFactory->create();
- $attributeSet->setData($data);
- $this->attributeSetManagement->create($entityTypeCode, $attributeSet, $defaultSetId);
- $this->attributeManagement->assign(
- 'catalog_product',
- $attributeSet->getId(),
- $attributeSet->getDefaultGroupId(),
- 'attribute_code',
- $attributeSet->getCollection()->count() * 10
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement