10 use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
42 private $storeManager;
47 private $attributeSet;
52 private $attributeFactory;
69 AttributeFactory $attributeFactory
76 $this->attributeFactory = $attributeFactory;
84 if (!$this->fixtureModel->getValue(
'configurable_products', [])
85 || in_array($this->getAttributeCode(), $this->eavConfig->getEntityAttributeCodes(
Product::ENTITY))) {
89 $this->generateAttribute($this->fixtureModel->getValue(
'configurable_products_variation', 3));
92 $this->cache->remove($cacheKey);
100 return 'Generating configurable EAV variations';
115 private function generateAttribute($optionCount)
117 $storeIds = array_keys($this->storeManager->getStores(
true));
127 'frontend_label' => array_fill_keys($storeIds,
'configurable variations'),
128 'frontend_input' =>
'select',
129 'is_required' =>
'0',
131 'default' => [
'option_0'],
132 'attribute_code' => $this->getAttributeCode(),
134 'default_value_text' =>
'',
135 'default_value_yesno' =>
'0',
136 'default_value_date' =>
'',
137 'default_value_textarea' =>
'',
139 'is_searchable' =>
'1',
140 'is_visible_in_advanced_search' =>
'0',
141 'is_comparable' =>
'0',
142 'is_filterable' =>
'1',
143 'is_filterable_in_search' =>
'0',
144 'is_used_for_promo_rules' =>
'0',
145 'is_html_allowed_on_front' =>
'1',
146 'is_visible_on_front' =>
'0',
147 'used_in_product_listing' =>
'0',
148 'used_for_sort_by' =>
'0',
149 'source_model' =>
null,
150 'backend_model' =>
null,
152 'backend_type' =>
'int',
153 'entity_type_id' => 4,
154 'is_user_defined' => 1,
158 $data[
'swatchvisual'][
'value'] = array_reduce(
159 range(1, $optionCount),
163 dechex(255 *
$index / $optionCount),
170 $data[
'optionvisual'][
'value'] = array_reduce(
171 range(1, $optionCount),
185 $model = $this->attributeFactory->create([
'data' =>
$data]);
186 $attributeSet = $this->attributeSet->load(self::ATTRIBUTE_SET_ID);
188 $model->setAttributeSetId(self::ATTRIBUTE_SET_ID);
189 $model->setAttributeGroupId($attributeSet->getDefaultGroupId(4));
192 $model->setAttributeSetId(self::ATTRIBUTE_SET_ID);
199 private function getAttributeCode()
201 return 'configurable_variation';
__construct(FixtureModel $fixtureModel, Config $eavConfig, CacheInterface $cache, StoreManager $storeManager, Set $attributeSet, AttributeFactory $attributeFactory)
const SWATCH_INPUT_TYPE_VISUAL