Skip to content

Commit

Permalink
Added command for creating upload product variant requests
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 6, 2024
1 parent ec3e1fc commit 327d26f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Command/CreateUploadProductVariantRequestsCommand.php
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;
}
}
24 changes: 24 additions & 0 deletions src/Factory/UploadProductVariantRequestFactory.php
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 src/Factory/UploadProductVariantRequestFactoryInterface.php
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;
}
8 changes: 8 additions & 0 deletions src/Resources/config/services/command.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="Setono\SyliusPeakPlugin\Command\CreateUploadProductVariantRequestsCommand">
<argument type="service" id="doctrine"/>
<argument type="service" id="setono_sylius_peak.factory.upload_product_variant_request"/>
<argument>%sylius.model.product_variant.class%</argument>

<tag name="console.command"/>
</service>

<service id="Setono\SyliusPeakPlugin\Command\ProcessUploadOrderRequestsCommand">
<argument type="service" id="Setono\SyliusPeakPlugin\Processor\UploadOrderRequestProcessorInterface"/>

Expand Down
7 changes: 7 additions & 0 deletions src/Resources/config/services/factory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- todo missing aliases -->

<service id="Setono\SyliusPeakPlugin\Factory\RegisteredWebhooksFactory"
decorates="setono_sylius_peak.factory.registered_webhooks" decoration-priority="64">
<argument type="service" id="Setono\SyliusPeakPlugin\Factory\RegisteredWebhooksFactory.inner"/>
Expand All @@ -11,5 +13,10 @@
decorates="setono_sylius_peak.factory.upload_order_request" decoration-priority="64">
<argument type="service" id="Setono\SyliusPeakPlugin\Factory\UploadOrderRequestFactory.inner"/>
</service>

<service id="Setono\SyliusPeakPlugin\Factory\UploadProductVariantRequestFactory"
decorates="setono_sylius_peak.factory.upload_product_variant_request" decoration-priority="64">
<argument type="service" id="Setono\SyliusPeakPlugin\Factory\UploadProductVariantRequestFactory.inner"/>
</service>
</services>
</container>

0 comments on commit 327d26f

Please sign in to comment.