-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInstallData.php
More file actions
40 lines (35 loc) · 1.48 KB
/
InstallData.php
File metadata and controls
40 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Bdcrops\AttributesSet\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Catalog\Setup\CategorySetupFactory;
class InstallData implements InstallDataInterface {
private $attributeSetFactory;
private $categorySetupFactory;
public function __construct(
AttributeSetFactory $attributeSetFactory,
CategorySetupFactory $categorySetupFactory) {
$this->attributeSetFactory = $attributeSetFactory;
$this->categorySetupFactory = $categorySetupFactory;
}
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context ) {
$setup->startSetup();
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
$attributeSet = $this->attributeSetFactory->create();
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
$data = [
'attribute_set_name' => 'Bdcrops',
'entity_type_id' => $entityTypeId,
'sort_order' => 100,
];
$attributeSet->setData($data);
$attributeSet->validate();
$attributeSet->save();
$attributeSet->initFromSkeleton($attributeSetId)->save();
}
}