diff --git a/src/Command/ProductCreatorCommand.php b/src/Command/ProductCreatorCommand.php index 28601fe..b30b98b 100644 --- a/src/Command/ProductCreatorCommand.php +++ b/src/Command/ProductCreatorCommand.php @@ -108,6 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $numberOfFeatures, $numberOfFeatureValues, $numberOfImages, + $numberOfStockMovements, $shopId ); $output->writeln(sprintf('%s product(s) with combinations created', $productsWithCombinations)); diff --git a/src/Creator/AbstractProductCreator.php b/src/Creator/AbstractProductCreator.php index b5787c8..5b07f3e 100644 --- a/src/Creator/AbstractProductCreator.php +++ b/src/Creator/AbstractProductCreator.php @@ -85,13 +85,13 @@ protected function associateFeatureValues(int $productId, int $featureId, array } } - protected function associateStockMovements(int $productId, int $numberOfStockMovements): void + protected function associateStockMovements(int $productId, array $combinationsId, int $numberOfStockMovements): void { if ($numberOfStockMovements <= 0) { return; } - $this->stockMovementCreator->generate($numberOfStockMovements, $productId); + $this->stockMovementCreator->generate($numberOfStockMovements, $productId, $combinationsId); } protected function associateImages(int $productId, array $combinationsId, int $numberOfImages): void diff --git a/src/Creator/ProductCombinationCreator.php b/src/Creator/ProductCombinationCreator.php index 784bcfc..cf6e375 100644 --- a/src/Creator/ProductCombinationCreator.php +++ b/src/Creator/ProductCombinationCreator.php @@ -54,6 +54,7 @@ public function generate( int $numberOfFeatures, int $numberOfFeatureValues, int $numberOfImages, + int $numberOfStockMovements, int $shopId ): void { $attributeGroups = $this->getAttributeGroupWithAtLeast($attributeValuePerGroupNumber); @@ -107,6 +108,7 @@ public function generate( }, $combinationsIds); $this->associateImages($newProductId->getValue(), $combinationsIds, $numberOfImages); + $this->associateStockMovements($newProductId->getValue(), $combinationsIds, $numberOfStockMovements); $this->associateFeatures($newProductId->getValue(), $numberOfFeatures, $numberOfFeatureValues, $shopId); } } diff --git a/src/Creator/ProductCreator.php b/src/Creator/ProductCreator.php index fd4c7e1..f2deb50 100644 --- a/src/Creator/ProductCreator.php +++ b/src/Creator/ProductCreator.php @@ -36,7 +36,7 @@ public function generate( for ($i = 0; $i < $number; ++$i) { $productId = $this->createProduct($shopId); $this->associateImages($productId, [], $numberOfImages); - $this->associateStockMovements($productId, $numberOfStockMovements); + $this->associateStockMovements($productId, [null], $numberOfStockMovements); $this->associateFeatures($productId, $numberOfFeatures, $numberOfFeatureValues, $shopId); } } diff --git a/src/Creator/StockMovementCreator.php b/src/Creator/StockMovementCreator.php index e26b4c2..5f8af04 100644 --- a/src/Creator/StockMovementCreator.php +++ b/src/Creator/StockMovementCreator.php @@ -1,5 +1,7 @@ employee = new Employee(1); } - public function generate(int $number, int $productId): void + public function generate(int $number, int $productId, array $combinationsId = []): void { - // Start - $qtyProduct = 500; + foreach ($combinationsId as $combinationId) { + // Start + $qtyProduct = 500; - StockAvailable::setQuantity($productId, 0, $qtyProduct, null, false); + StockAvailable::setQuantity($productId, $combinationId, $qtyProduct, null, false); - for ($i = 0; $i < $number; ++$i) { - $deltaQuantity = rand(-10, 10); + for ($i = 0; $i < $number; ++$i) { + $deltaQuantity = rand(-10, 10); - $qtyProduct += $deltaQuantity; - $this->createStockMovement($productId, $deltaQuantity); - } + $qtyProduct += $deltaQuantity; + $this->createStockMovement($productId, $combinationId, $deltaQuantity); + } - StockAvailable::setQuantity($productId, 0, $qtyProduct, null, false); + StockAvailable::setQuantity($productId, $combinationId, $qtyProduct, null, false); + } } - public function createStockMovement(int $productId, int $deltaQuantity): void + public function createStockMovement(int $productId, ?int $combinationId, int $deltaQuantity): void { - $stockAvailable = $this->stockManager->getStockAvailableByProduct(new Product($productId)); + $stockAvailable = $this->stockManager->getStockAvailableByProduct(new Product($productId), $combinationId); $stockMvt = new StockMvt(); $stockMvt->setIdStock((int) $stockAvailable->id);