Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeSetsFixture.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Setup\Fixtures;
8 
25 {
27  const PRODUCT_SET_NAME = 'Product Set ';
28 
32  protected $priority = 25;
33 
37  private $attributeSetsFixture;
38 
42  private $pattern;
43 
49  public function __construct(
51  AttributeSet\AttributeSetFixture $attributeSetsFixture,
52  \Magento\Setup\Fixtures\AttributeSet\Pattern $pattern
53  ) {
54  parent::__construct($fixtureModel);
55  $this->attributeSetsFixture = $attributeSetsFixture;
56  $this->pattern = $pattern;
57  }
58 
62  public function execute()
63  {
64  $attributeSets = $this->fixtureModel->getValue('attribute_sets', null);
65  if ($attributeSets !== null) {
66  foreach ($attributeSets['attribute_set'] as $attributeSetData) {
67  $this->attributeSetsFixture->createAttributeSet($attributeSetData);
68  }
69  }
70 
71  $attributeSetsCount = $this->fixtureModel->getValue('product_attribute_sets', null);
72  if ($attributeSetsCount !== null) {
73  for ($index = 1; $index <= $attributeSetsCount; $index++) {
74  $this->attributeSetsFixture->createAttributeSet(
75  $this->pattern->generateAttributeSet(
76  self::PRODUCT_SET_NAME . $index,
77  $this->fixtureModel->getValue('product_attribute_sets_attributes', 3),
78  $this->fixtureModel->getValue('product_attribute_sets_attributes_values', 3),
79  function ($attributeIndex, $attribute) use ($index) {
80  return array_replace_recursive(
81  $attribute,
82  [
83  'attribute_code' => "attribute_set{$index}_" . $attributeIndex,
84  ]
85  );
86  }
87  )
88  );
89  }
90  }
91  }
92 
96  public function getActionTitle()
97  {
98  return 'Generating attribute sets';
99  }
100 
104  public function introduceParamLabels()
105  {
106  return [
107  'attribute_sets' => 'Attribute Sets (Default)',
108  'product_attribute_sets' => 'Attribute Sets (Extra)'
109  ];
110  }
111 }
$pattern
Definition: website.php:22
__construct(FixtureModel $fixtureModel, AttributeSet\AttributeSetFixture $attributeSetsFixture, \Magento\Setup\Fixtures\AttributeSet\Pattern $pattern)
$index
Definition: list.phtml:44