-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
139 additions
and
7 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
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusCatalogPromotionPlugin\DataProvider; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use Setono\Doctrine\ORMTrait; | ||
use Setono\SyliusCatalogPromotionPlugin\Event\DataProviderQueryBuilderCreatedEvent; | ||
use Setono\SyliusCatalogPromotionPlugin\Model\ProductInterface; | ||
|
||
final class ProductDataProvider implements ProductDataProviderInterface | ||
{ | ||
use ORMTrait; | ||
|
||
public function __construct( | ||
ManagerRegistry $managerRegistry, | ||
private readonly EventDispatcherInterface $eventDispatcher, | ||
|
||
/** @var class-string<ProductInterface> $productClass */ | ||
private readonly string $productClass, | ||
) { | ||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
public function getProducts(): \Generator | ||
{ | ||
$qb = $this | ||
->getManager($this->productClass) | ||
->createQueryBuilder() | ||
->select('product') | ||
->from($this->productClass, 'product') | ||
; | ||
|
||
$this->eventDispatcher->dispatch(new DataProviderQueryBuilderCreatedEvent($qb)); | ||
|
||
/** @var SimpleBatchIteratorAggregate<array-key, ProductInterface> $iterator */ | ||
$iterator = SimpleBatchIteratorAggregate::fromQuery($qb->getQuery(), 100); | ||
|
||
yield from $iterator; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusCatalogPromotionPlugin\Event; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
|
||
final class DataProviderQueryBuilderCreatedEvent | ||
{ | ||
public function __construct(public readonly QueryBuilder $queryBuilder) | ||
{ | ||
} | ||
} |
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
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
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
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 @@ | ||
<?xml version="1.0" encoding="UTF-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> | ||
<service id="Setono\SyliusCatalogPromotionPlugin\DataProvider\ProductDataProviderInterface" | ||
alias="Setono\SyliusCatalogPromotionPlugin\DataProvider\ProductDataProvider"/> | ||
|
||
<service id="Setono\SyliusCatalogPromotionPlugin\DataProvider\ProductDataProvider"> | ||
<argument type="service" id="doctrine"/> | ||
<argument type="service" id="event_dispatcher"/> | ||
<argument>%sylius.model.product.class%</argument> | ||
</service> | ||
</services> | ||
</container> |
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 @@ | ||
<?xml version="1.0" encoding="UTF-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> | ||
<service id="Setono\SyliusCatalogPromotionPlugin\Message\CommandHandler\ProcessCatalogPromotionsHandler"> | ||
<argument type="service" id="Setono\SyliusCatalogPromotionPlugin\DataProvider\ProductDataProviderInterface"/> | ||
<argument type="service" id="setono_sylius_catalog_promotion.repository.promotion"/> | ||
<argument type="service" id="Setono\SyliusCatalogPromotionPlugin\Checker\PreQualification\PreQualificationCheckerInterface"/> | ||
<argument type="service" id="doctrine"/> | ||
|
||
<tag name="messenger.message_handler"/> | ||
</service> | ||
</services> | ||
</container> |