-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added command for creating upload product variant requests
- Loading branch information
Showing
5 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\Command; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate; | ||
use Setono\Doctrine\ORMTrait; | ||
use Setono\SyliusPeakPlugin\Factory\UploadProductVariantRequestFactoryInterface; | ||
use Setono\SyliusPeakPlugin\Model\ProductVariantInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'setono:sylius-peak-wms:create-upload-product-variant-requests', | ||
description: 'Will create upload product variant requests for variants that are not uploaded yet', | ||
)] | ||
final class CreateUploadProductVariantRequestsCommand extends Command | ||
{ | ||
use ORMTrait; | ||
|
||
/** | ||
* @param class-string<ProductVariantInterface> $productVariantClass | ||
*/ | ||
public function __construct( | ||
ManagerRegistry $managerRegistry, | ||
private readonly UploadProductVariantRequestFactoryInterface $uploadProductVariantRequestFactory, | ||
private readonly string $productVariantClass, | ||
) { | ||
parent::__construct(); | ||
|
||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$qb = $this | ||
->getRepository($this->productVariantClass) | ||
->createQueryBuilder('o') | ||
->andWhere('o.peakUploadProductVariantRequest IS NULL') | ||
; | ||
|
||
/** @var SimpleBatchIteratorAggregate<array-key, ProductVariantInterface> $iterator */ | ||
$iterator = SimpleBatchIteratorAggregate::fromQuery($qb->getQuery(), 100); | ||
|
||
foreach ($iterator as $productVariant) { | ||
$productVariant->setPeakUploadProductVariantRequest($this->uploadProductVariantRequestFactory->createNew()); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\Factory; | ||
|
||
use Setono\SyliusPeakPlugin\Model\UploadProductVariantRequestInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
|
||
final class UploadProductVariantRequestFactory implements UploadProductVariantRequestFactoryInterface | ||
{ | ||
public function __construct( | ||
/** @var FactoryInterface<UploadProductVariantRequestInterface> $decoratedFactory */ | ||
private readonly FactoryInterface $decoratedFactory, | ||
) { | ||
} | ||
|
||
/** @psalm-suppress MoreSpecificReturnType */ | ||
public function createNew(): UploadProductVariantRequestInterface | ||
{ | ||
/** @psalm-suppress LessSpecificReturnStatement */ | ||
return $this->decoratedFactory->createNew(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Factory/UploadProductVariantRequestFactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\Factory; | ||
|
||
use Setono\SyliusPeakPlugin\Model\UploadProductVariantRequestInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
|
||
/** | ||
* @extends FactoryInterface<UploadProductVariantRequestInterface> | ||
*/ | ||
interface UploadProductVariantRequestFactoryInterface extends FactoryInterface | ||
{ | ||
public function createNew(): UploadProductVariantRequestInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters