-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to send product variants instead of products
- Loading branch information
Showing
16 changed files
with
460 additions
and
14 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
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
83 changes: 83 additions & 0 deletions
83
src/DataSyncInfrastructure/Doctrine/ORM/ProductVariantsQueryBuilder.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,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusClerkPlugin\DataSyncInfrastructure\Doctrine\ORM; | ||
|
||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductVariantRepository; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\ProductVariantInterface; | ||
use Webgriffe\SyliusClerkPlugin\DataSyncInfrastructure\Doctrine\ORM\Event\QueryBuilderEvent; | ||
use Webgriffe\SyliusClerkPlugin\DataSyncInfrastructure\Enum\Resource; | ||
use Webgriffe\SyliusClerkPlugin\DataSyncInfrastructure\Model\QueryBuilderInterface; | ||
|
||
/** | ||
* @implements QueryBuilderInterface<ProductVariantInterface> | ||
*/ | ||
final readonly class ProductVariantsQueryBuilder implements QueryBuilderInterface | ||
{ | ||
public function __construct( | ||
private ProductVariantRepository $productVariantRepository, | ||
private EventDispatcherInterface $eventDispatcher, | ||
) { | ||
} | ||
|
||
public function getResource(): Resource | ||
{ | ||
return Resource::PRODUCTS; | ||
} | ||
|
||
public function getResult( | ||
ChannelInterface $channel, | ||
string $localeCode, | ||
?\DateTimeInterface $modifiedAfter = null, | ||
?int $limit = null, | ||
?int $offset = null, | ||
): array { | ||
$queryBuilder = $this->productVariantRepository->createQueryBuilder('pv'); | ||
|
||
$queryBuilder | ||
->join('pv.product', 'p') | ||
->andWhere('pv.enabled = true') | ||
->leftJoin('pv.translations', 'pvt', 'WITH', 'pvt.locale = :localeCode') | ||
->setParameter('localeCode', $localeCode) | ||
; | ||
$queryBuilder | ||
->andWhere(':channel MEMBER OF p.channels') | ||
->andWhere('p.enabled = true') | ||
->setParameter('channel', $channel) | ||
->leftJoin('p.translations', 'pt', 'WITH', 'pt.locale = :localeCode') | ||
; | ||
|
||
if ($modifiedAfter !== null) { | ||
$queryBuilder | ||
->andWhere('pv.updatedAt > :modifiedAfter') | ||
->setParameter('modifiedAfter', $modifiedAfter) | ||
; | ||
} | ||
|
||
if ($limit !== null) { | ||
$queryBuilder->setMaxResults($limit); | ||
} | ||
|
||
if ($offset !== null) { | ||
$queryBuilder->setFirstResult($offset); | ||
} | ||
|
||
$this->eventDispatcher->dispatch(new QueryBuilderEvent( | ||
$this->getResource(), | ||
$queryBuilder, | ||
$channel, | ||
$localeCode, | ||
$modifiedAfter, | ||
$limit, | ||
$offset, | ||
)); | ||
|
||
/** @var ProductVariantInterface[] $result */ | ||
$result = $queryBuilder->getQuery()->getResult(); | ||
|
||
return $result; | ||
} | ||
} |
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
96 changes: 96 additions & 0 deletions
96
src/DataSyncInfrastructure/Normalizer/Event/ProductVariantNormalizerEvent.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,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusClerkPlugin\DataSyncInfrastructure\Normalizer\Event; | ||
|
||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
use Sylius\Component\Core\Model\ProductVariantInterface; | ||
|
||
final class ProductVariantNormalizerEvent | ||
{ | ||
/** | ||
* @param array{ | ||
* id: string|int, | ||
* name: string, | ||
* description?: string, | ||
* price: float, | ||
* list_price: float, | ||
* image?: string, | ||
* url: string, | ||
* categories: array<int|string>, | ||
* created_at: string, | ||
* }&array<string, mixed> $productData | ||
*/ | ||
public function __construct( | ||
private array $productData, | ||
private readonly ProductVariantInterface $productVariant, | ||
private readonly ProductInterface $product, | ||
private readonly ChannelInterface $channel, | ||
private readonly string $localeCode, | ||
private readonly array $context, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array{ | ||
* id: string|int, | ||
* name: string, | ||
* description?: string, | ||
* price: float, | ||
* list_price: float, | ||
* image?: string, | ||
* url: string, | ||
* categories: array<int|string>, | ||
* created_at: string, | ||
* }&array<string, mixed> | ||
*/ | ||
public function getProductData(): array | ||
{ | ||
return $this->productData; | ||
} | ||
|
||
/** | ||
* @param array{ | ||
* id: string|int, | ||
* name: string, | ||
* description?: string, | ||
* price: float, | ||
* list_price: float, | ||
* image?: string, | ||
* url: string, | ||
* categories: array<int|string>, | ||
* created_at: string, | ||
* }&array<string, mixed> $productData | ||
*/ | ||
public function setProductData(array $productData): void | ||
{ | ||
$this->productData = $productData; | ||
} | ||
|
||
public function getProductVariant(): ProductVariantInterface | ||
{ | ||
return $this->productVariant; | ||
} | ||
|
||
public function getProduct(): ProductInterface | ||
{ | ||
return $this->product; | ||
} | ||
|
||
public function getChannel(): ChannelInterface | ||
{ | ||
return $this->channel; | ||
} | ||
|
||
public function getLocaleCode(): string | ||
{ | ||
return $this->localeCode; | ||
} | ||
|
||
public function getContext(): array | ||
{ | ||
return $this->context; | ||
} | ||
} |
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
Oops, something went wrong.