42 private $productGenerator;
47 private $bundleProductGenerator;
52 private $productCollectionFactory;
57 private $productStartIndex;
62 private $productsAmountProvider;
67 private $websiteCategoryProvider;
72 private $priceProvider;
86 \
Magento\Setup\Model\FixtureGenerator\BundleProductGenerator $bundleProductGenerator,
93 $this->productGenerator = $productGenerator;
94 $this->bundleProductGenerator = $bundleProductGenerator;
95 $this->productCollectionFactory = $productCollectionFactory;
96 $this->productsAmountProvider = $productsAmountProvider;
97 $this->websiteCategoryProvider = $websiteCategoryProvider;
98 $this->priceProvider = $priceProvider;
107 $bundlesAmount = $this->fixtureModel->getValue(
'bundle_products', 0);
108 $bundleOptions = $this->fixtureModel->getValue(
'bundle_products_options', 1);
109 $bundleProductsPerOption = $this->fixtureModel->getValue(
'bundle_products_variation', 10);
110 $bundleOptionSuffix =
$bundleOptions .
'-' . $bundleProductsPerOption;
112 $bundlesAmount = $this->productsAmountProvider->getAmount(
114 $this->getBundleSkuPattern($bundleOptionSuffix)
117 if (!$bundlesAmount) {
120 $variationSkuClosure =
function (
$productId, $entityNumber) use ($bundleOptionSuffix, $variationCount) {
121 $productIndex = $this->getBundleProductIndex($entityNumber, $variationCount);
122 $variationIndex = $this->getBundleVariationIndex($entityNumber, $variationCount);
124 return sprintf($this->getBundleOptionItemSkuPattern($bundleOptionSuffix), $productIndex, $variationIndex);
127 'name' => $variationSkuClosure,
128 'sku' => $variationSkuClosure,
129 'price' =>
function (
$index, $entityNumber) {
130 return $this->priceProvider->getPrice($entityNumber);
132 'website_ids' =>
function (
$index, $entityNumber) use ($variationCount) {
133 $configurableIndex = $this->getBundleProductIndex($entityNumber, $variationCount);
135 return $this->websiteCategoryProvider->getWebsiteIds($configurableIndex);
139 $this->productGenerator->generate($bundlesAmount *
$bundleOptions * $bundleProductsPerOption, $fixtureMap);
145 $priceTypeClosure =
function (
$index) use ($optionPriceType) {
146 return $optionPriceType[
$index % count($optionPriceType)];
148 $skuClosure =
function (
$index, $entityNumber) use ($bundleOptionSuffix) {
150 $this->getBundleSkuPattern($bundleOptionSuffix),
151 $entityNumber + $this->getNewProductStartIndex()
156 '_bundle_products_per_option' => $bundleProductsPerOption,
157 '_bundle_variation_sku_pattern' => sprintf(
158 $this->getBundleOptionItemSkuPattern($bundleOptionSuffix),
159 $this->getNewProductStartIndex(),
163 'name' => $skuClosure,
164 'sku' => $skuClosure,
165 'meta_title' => $skuClosure,
166 'price' =>
function (
$index) use ($priceTypeClosure) {
169 : $this->priceProvider->getPrice(
$index);
171 'priceType' => $priceTypeClosure,
172 'website_ids' =>
function (
$index, $entityNumber) {
173 return $this->websiteCategoryProvider->getWebsiteIds($entityNumber + $this->getNewProductStartIndex());
175 'category_ids' =>
function (
$index, $entityNumber) {
176 return $this->websiteCategoryProvider->getCategoryId($entityNumber + $this->getNewProductStartIndex());
179 $this->bundleProductGenerator->generate($bundlesAmount, $fixtureMap);
188 private function getBundleOptionItemSkuPattern($bundleOptionSuffix)
190 return $this->getBundleSkuPattern($bundleOptionSuffix) .
' - option %s';
199 private function getBundleSkuPattern($bundleOptionSuffix)
201 return sprintf(self::SKU_PATTERN,
'%s', $bundleOptionSuffix);
209 private function getNewProductStartIndex()
211 if (
null === $this->productStartIndex) {
212 $this->productStartIndex = $this->productCollectionFactory->create()
217 return $this->productStartIndex;
227 private function getBundleProductIndex($entityNumber, $variationCount)
229 return floor($entityNumber / $variationCount) + $this->getNewProductStartIndex();
239 private function getBundleVariationIndex($entityNumber, $variationCount)
241 return $entityNumber % $variationCount + 1;
249 return 'Generating bundle products';
258 'bundle_products' =>
'Bundle products',
__construct(FixtureModel $fixtureModel, \Magento\Setup\Model\FixtureGenerator\ProductGenerator $productGenerator, \Magento\Setup\Model\FixtureGenerator\BundleProductGenerator $bundleProductGenerator, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, ProductsAmountProvider $productsAmountProvider, WebsiteCategoryProvider $websiteCategoryProvider, PriceProvider $priceProvider)
const VISIBILITY_NOT_VISIBLE