Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
ConfigurableProductsFixture Class Reference
Inheritance diagram for ConfigurableProductsFixture:
Fixture

Public Member Functions

 __construct (FixtureModel $fixtureModel, \Magento\Setup\Fixtures\AttributeSet\AttributeSetFixture $attributeSetsFixture, \Magento\Setup\Fixtures\AttributeSet\Pattern $attributePattern, ProductGenerator $productGenerator, CollectionFactory $attributeCollectionFactory, ConfigurableProductGenerator $configurableProductGenerator, ProductCollectionFactory $collectionFactory, ProductsAmountProvider $productsAmountProvider, CategoryResolver $categoryResolver, WebsiteCategoryProvider $websiteCategoryProvider, PriceProvider $priceProvider, \Magento\Setup\Fixtures\AttributeSet\SwatchesGenerator $swatchesGenerator, \Magento\Framework\Serialize\SerializerInterface $serializer)
 
 execute ()
 
 getActionTitle ()
 
 introduceParamLabels ()
 
 printInfo (OutputInterface $output)
 
- Public Member Functions inherited from Fixture
 __construct (FixtureModel $fixtureModel)
 
 execute ()
 
 getActionTitle ()
 
 printInfo (OutputInterface $output)
 
 introduceParamLabels ()
 
 getPriority ()
 

Protected Attributes

 $priority = 50
 
- Protected Attributes inherited from Fixture
 $priority
 
 $fixtureModel
 

Detailed Description

Generate configurable products based on profile configuration Generated configurable options are not displayed individually in catalog Support one of two formats:

  1. Distributed per Default and pre-defined attribute sets (
    See also
    setup/performance-toolkit/config/attributeSets.xml) <configurable_products>{products amount}</configurable_products>
    2.1 Generate products based on existing attribute set: <configurable_products> <config> <attributeSet>{Existing attribute set name}</attributeSet> <sku>{Configurable sku pattern with s}</sku> <products>{Amount of configurable products}</products> <category>[{Category Name}]</category> By default category name from CategoriesFixture will be used <swatches>color|image</swatches> Type of Swatch attribute </config> </configurable_products>

2.2 Generate products based on dynamically created attribute set with specified amount of attributes and options <configurable_products> <config> <attributes>{Amount of attributes in configurable product}</attributes> <options>{Amount of options per attribute}</options> <sku>{Configurable sku pattern with s}</sku> <products>{Amount of configurable products}</products> <category>[{Category Name}]</category> By default category name from CategoriesFixture will be used <swatches>color|image</swatches> Type of Swatch attribute </config> </configurable_products>

2.3 Generate products based on dynamically created attribute set with specified configuration per each attribute <configurable_products> <config> <attributes>

<attribute> <options>{Amount of options per attribute}</options> <swatches>color|image</swatches> Type of Swatch attribute </attribute>

<attribute> <options>{Amount of options per attribute}</options> </attribute> </attributes> <sku>{Configurable sku pattern with s}</sku> <products>{Amount of configurable products}</products> </config> </configurable_products>

Products will be uniformly distributed per categories and websites If node "assign_entities_to_all_websites" from profile is set to "1" then products will be assigned to all websites

See also
setup/performance-toolkit/profiles/ce/small.xml @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.TooManyFields)

Definition at line 77 of file ConfigurableProductsFixture.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( FixtureModel  $fixtureModel,
\Magento\Setup\Fixtures\AttributeSet\AttributeSetFixture  $attributeSetsFixture,
\Magento\Setup\Fixtures\AttributeSet\Pattern  $attributePattern,
ProductGenerator  $productGenerator,
CollectionFactory  $attributeCollectionFactory,
ConfigurableProductGenerator  $configurableProductGenerator,
ProductCollectionFactory  $collectionFactory,
ProductsAmountProvider  $productsAmountProvider,
CategoryResolver  $categoryResolver,
WebsiteCategoryProvider  $websiteCategoryProvider,
PriceProvider  $priceProvider,
\Magento\Setup\Fixtures\AttributeSet\SwatchesGenerator  $swatchesGenerator,
\Magento\Framework\Serialize\SerializerInterface  $serializer 
)
Parameters
FixtureModel$fixtureModel
AttributeSet\AttributeSetFixture$attributeSetsFixture
AttributeSet\Pattern$attributePattern
ProductGenerator$productGenerator
CollectionFactory$attributeCollectionFactory
ConfigurableProductGenerator$configurableProductGenerator
ProductCollectionFactory$collectionFactory
ProductsAmountProvider$productsAmountProvider
CategoryResolver$categoryResolver
WebsiteCategoryProvider$websiteCategoryProvider
PriceProvider$priceProvider
AttributeSet\SwatchesGenerator$swatchesGenerator
\Magento\Framework\Serialize\SerializerInterface$serializer@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 175 of file ConfigurableProductsFixture.php.

189  {
190  parent::__construct($fixtureModel);
191  $this->attributeSetsFixture = $attributeSetsFixture;
192  $this->attributePattern = $attributePattern;
193  $this->productGenerator = $productGenerator;
194  $this->attributeCollectionFactory = $attributeCollectionFactory;
195  $this->configurableProductGenerator = $configurableProductGenerator;
196  $this->productCollectionFactory = $collectionFactory;
197  $this->productsAmountProvider = $productsAmountProvider;
198  $this->categoryResolver = $categoryResolver;
199  $this->websiteCategoryProvider = $websiteCategoryProvider;
200  $this->priceProvider = $priceProvider;
201  $this->swatchesGenerator = $swatchesGenerator;
202  $this->serializer = $serializer;
203  }

Member Function Documentation

◆ execute()

execute ( )

{} @SuppressWarnings(PHPMD)

Definition at line 209 of file ConfigurableProductsFixture.php.

210  {
211  if (!$this->fixtureModel->getValue('configurable_products', [])) {
212  return;
213  }
214  $simpleProductsCount = $this->fixtureModel->getValue('simple_products', 0);
215  $maxAmountOfWordsDescription = $this->getSearchConfigValue('max_amount_of_words_description');
216  $maxAmountOfWordsShortDescription = $this->getSearchConfigValue('max_amount_of_words_short_description');
217  $minAmountOfWordsDescription = $this->getSearchConfigValue('min_amount_of_words_description');
218  $minAmountOfWordsShortDescription = $this->getSearchConfigValue('min_amount_of_words_short_description');
219 
220  foreach ($this->getConfigurableProductConfig() as $configurableConfig) {
221  $configurableSku = $configurableConfig['sku'];
222  $productAmount = $this->productsAmountProvider->getAmount(
223  $configurableConfig['products'],
224  $configurableSku
225  );
226  if (!$productAmount) {
227  continue;
228  }
229  $searchTerms = $this->getSearchTerms();
230  $shortDescriptionClosure = $this->getDescriptionClosure(
231  $searchTerms,
232  $simpleProductsCount,
233  $productAmount,
234  $maxAmountOfWordsShortDescription,
235  $minAmountOfWordsShortDescription,
236  'shortDescription'
237  );
238  $descriptionClosure = $this->getDescriptionClosure(
239  $searchTerms,
240  $simpleProductsCount,
241  $productAmount,
242  $maxAmountOfWordsDescription,
243  $minAmountOfWordsDescription,
244  'description'
245  );
246  $variationCount = $configurableConfig['variationCount'];
247  $attributeSet = $configurableConfig['attributeSet'];
248  $variationSkuClosure = function ($productId, $entityNumber) use ($configurableSku, $variationCount) {
249  $variationIndex = $this->getConfigurableVariationIndex($entityNumber, $variationCount);
250  $productId = $this->getConfigurableProductIndex($entityNumber, $variationCount);
251 
252  return sprintf($this->getConfigurableOptionSkuPattern($configurableSku), $productId, $variationIndex);
253  };
254  $fixture = [
255  'name' => $variationSkuClosure,
256  'sku' => $variationSkuClosure,
257  'price' => function ($index, $entityNumber) {
258  return $this->priceProvider->getPrice($entityNumber);
259  },
260  'website_ids' => function ($index, $entityNumber) use ($variationCount) {
261  $configurableIndex = $this->getConfigurableProductIndex($entityNumber, $variationCount);
262 
263  return $this->websiteCategoryProvider->getWebsiteIds($configurableIndex);
264  },
265  'attribute_set_id' => $attributeSet['id'],
266  'additional_attributes' => $this->getAdditionalAttributesClosure(
267  $attributeSet['attributes'],
268  $variationCount
269  ),
270  'visibility' => Visibility::VISIBILITY_NOT_VISIBLE,
271  ];
272  $this->productGenerator->generate($productAmount * $variationCount, $fixture);
273 
274  $skuClosure = function ($productId, $entityNumber) use ($configurableSku) {
275  return sprintf($configurableSku, $entityNumber + $this->getNewProductStartIndex());
276  };
277  $fixture = [
278  '_variation_sku_pattern' => $this->getFirstVariationSkuPattern($configurableConfig),
279  '_attributes_count' => count($attributeSet['attributes']),
280  '_variation_count' => $variationCount,
281  '_attributes' => $attributeSet['attributes'],
282  'type_id' => Configurable::TYPE_CODE,
283  'name' => $skuClosure,
284  'sku' => $skuClosure,
285  'description' => $descriptionClosure,
286  'short_description' => $shortDescriptionClosure,
287  'attribute_set_id' => $attributeSet['id'],
288  'website_ids' => $this->getConfigurableWebsiteIdsClosure(),
289  'category_ids' => $configurableConfig['category'],
290  'meta_keyword' => $skuClosure,
291  'meta_title' => $skuClosure,
292  ];
293 
294  $this->configurableProductGenerator->generate($productAmount, $fixture);
295  }
296  }
$index
Definition: list.phtml:44

◆ getActionTitle()

getActionTitle ( )

{}

Definition at line 404 of file ConfigurableProductsFixture.php.

405  {
406  return 'Generating configurable products';
407  }

◆ introduceParamLabels()

introduceParamLabels ( )

{}

Definition at line 412 of file ConfigurableProductsFixture.php.

413  {
414  return [];
415  }

◆ printInfo()

printInfo ( OutputInterface  $output)

{}

Exceptions
ValidatorException

Definition at line 421 of file ConfigurableProductsFixture.php.

422  {
423  if (!$this->fixtureModel->getValue('configurable_products', [])) {
424  return;
425  }
426 
427  $configurableProductConfig = $this->prepareConfigurableConfig(
428  $this->getDefaultAttributeSetsWithAttributes()
429  );
430  $generalAmount = array_sum(array_column($configurableProductConfig, 'products'));
431 
432  $output->writeln(sprintf('<info> |- Configurable products: %s</info>', $generalAmount));
433  }

Field Documentation

◆ $priority

$priority = 50
protected

Definition at line 82 of file ConfigurableProductsFixture.php.


The documentation for this class was generated from the following file: