Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ProductFilterInterface::getChannel to allow further extension #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/Filter/ProductFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(EntityRepository $productFiltersRulesRepository, Syl
$this->syliusAkeneoLocaleCodeProvider = $syliusAkeneoLocaleCodeProvider;
}

public function getProductModelFilters(): array
public function getModelQueryParameters(): array
{
/** @var ProductFiltersRules $productFilterRules */
$productFilterRules = $this->productFiltersRulesRepository->findOneBy([]);
Expand Down Expand Up @@ -75,7 +75,7 @@ public function getProductModelFilters(): array
return $queryParameters;
}

public function getProductFilters(): array
public function getQueryParameters(): array
{
/** @var ProductFiltersRules $productFilterRules */
$productFilterRules = $this->productFiltersRulesRepository->findOneBy([]);
Expand Down Expand Up @@ -108,6 +108,17 @@ public function getProductFilters(): array
return $queryParameters;
}

public function getChannel(): ?string
{
/** @var ProductFiltersRules $productFilterRules */
$productFilterRules = $this->productFiltersRulesRepository->findOneBy([]);
if (!$productFilterRules instanceof ProductFiltersRules) {
return null;
}

return $productFilterRules->getChannel();
}

private function getStatus(ProductFiltersRules $productFilterRules, SearchBuilder $queryParameters): SearchBuilder
{
$status = $productFilterRules->getStatus();
Expand Down
6 changes: 4 additions & 2 deletions src/Filter/ProductFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

interface ProductFilterInterface
{
public function getProductModelFilters(): array;
public function getModelQueryParameters(): array;

public function getProductFilters(): array;
public function getQueryParameters(): array;

public function getChannel(): ?string;
}
19 changes: 9 additions & 10 deletions src/Task/Product/CreateConfigurableProductEntitiesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Synolia\SyliusAkeneoPlugin\Entity\ProductFiltersRules;
use Synolia\SyliusAkeneoPlugin\Entity\ProductGroup;
use Synolia\SyliusAkeneoPlugin\Event\ProductVariant\AfterProcessingProductVariantEvent;
use Synolia\SyliusAkeneoPlugin\Event\ProductVariant\BeforeProcessingProductVariantEvent;
use Synolia\SyliusAkeneoPlugin\Exceptions\NoProductFiltersConfigurationException;
use Synolia\SyliusAkeneoPlugin\Exceptions\Processor\MissingAkeneoAttributeProcessorException;
use Synolia\SyliusAkeneoPlugin\Filter\ProductFilterInterface;
use Synolia\SyliusAkeneoPlugin\Logger\Messages;
use Synolia\SyliusAkeneoPlugin\Manager\ProductOptionManager;
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface;
Expand All @@ -31,7 +31,6 @@
use Synolia\SyliusAkeneoPlugin\Provider\AkeneoAttributeProcessorProviderInterface;
use Synolia\SyliusAkeneoPlugin\Provider\AkeneoTaskProvider;
use Synolia\SyliusAkeneoPlugin\Repository\ChannelRepository;
use Synolia\SyliusAkeneoPlugin\Repository\ProductFiltersRulesRepository;
use Synolia\SyliusAkeneoPlugin\Repository\ProductGroupRepository;
use Synolia\SyliusAkeneoPlugin\Task\AkeneoTaskInterface;
use Synolia\SyliusAkeneoPlugin\Task\AttributeOption\CreateUpdateDeleteTask;
Expand Down Expand Up @@ -71,8 +70,8 @@ final class CreateConfigurableProductEntitiesTask extends AbstractCreateProductE
/** @var string */
private $type;

/** @var \Synolia\SyliusAkeneoPlugin\Repository\ProductFiltersRulesRepository */
private $productFiltersRulesRepository;
/** @var \Synolia\SyliusAkeneoPlugin\Filter\ProductFilterInterface */
private $productFilter;

/** @var string */
private $scope;
Expand Down Expand Up @@ -105,7 +104,7 @@ public function __construct(
FactoryInterface $productOptionValueFactory,
RepositoryInterface $productVariantTranslationRepository,
FactoryInterface $productVariantTranslationFactory,
ProductFiltersRulesRepository $productFiltersRulesRepository,
ProductFilterInterface $productFilter,
AkeneoAttributeProcessorProviderInterface $akeneoAttributeProcessorProvider,
EventDispatcherInterface $dispatcher
) {
Expand All @@ -130,7 +129,7 @@ public function __construct(
$this->productOptionValueFactory = $productOptionValueFactory;
$this->productVariantTranslationRepository = $productVariantTranslationRepository;
$this->productVariantTranslationFactory = $productVariantTranslationFactory;
$this->productFiltersRulesRepository = $productFiltersRulesRepository;
$this->productFilter = $productFilter;
$this->akeneoAttributeProcessorProvider = $akeneoAttributeProcessorProvider;
$this->dispatcher = $dispatcher;
}
Expand All @@ -146,12 +145,12 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte
$this->logger->debug(self::class);
$this->type = 'ConfigurableProduct';
$this->logger->notice(Messages::createOrUpdate($this->type));
/** @var \Synolia\SyliusAkeneoPlugin\Entity\ProductFiltersRules $filters */
$filters = $this->productFiltersRulesRepository->findOneBy([]);
if (!$filters instanceof ProductFiltersRules) {

$scope = $this->productFilter->getChannel();
if ($scope === null) {
throw new NoProductFiltersConfigurationException('Product filters must be configured before importing product attributes.');
}
$this->scope = $filters->getChannel();
$this->scope = $scope;

$processedCount = 0;
$totalItemsCount = $this->countTotalProducts(false);
Expand Down
18 changes: 8 additions & 10 deletions src/Task/Product/CreateSimpleProductEntitiesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Synolia\SyliusAkeneoPlugin\Entity\ProductConfiguration;
use Synolia\SyliusAkeneoPlugin\Entity\ProductFiltersRules;
use Synolia\SyliusAkeneoPlugin\Event\Product\AfterProcessingProductEvent;
use Synolia\SyliusAkeneoPlugin\Event\Product\BeforeProcessingProductEvent;
use Synolia\SyliusAkeneoPlugin\Event\ProductVariant\AfterProcessingProductVariantEvent;
use Synolia\SyliusAkeneoPlugin\Event\ProductVariant\BeforeProcessingProductVariantEvent;
use Synolia\SyliusAkeneoPlugin\Exceptions\Attribute\MissingLocaleTranslationException;
use Synolia\SyliusAkeneoPlugin\Exceptions\NoProductFiltersConfigurationException;
use Synolia\SyliusAkeneoPlugin\Filter\ProductFilterInterface;
use Synolia\SyliusAkeneoPlugin\Logger\Messages;
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface;
use Synolia\SyliusAkeneoPlugin\Payload\Product\ProductCategoriesPayload;
Expand All @@ -31,7 +31,6 @@
use Synolia\SyliusAkeneoPlugin\Provider\AkeneoAttributeDataProviderInterface;
use Synolia\SyliusAkeneoPlugin\Provider\AkeneoTaskProvider;
use Synolia\SyliusAkeneoPlugin\Repository\ChannelRepository;
use Synolia\SyliusAkeneoPlugin\Repository\ProductFiltersRulesRepository;
use Synolia\SyliusAkeneoPlugin\Service\SyliusAkeneoLocaleCodeProvider;
use Synolia\SyliusAkeneoPlugin\Task\AkeneoTaskInterface;

Expand Down Expand Up @@ -67,8 +66,8 @@ final class CreateSimpleProductEntitiesTask extends AbstractCreateProductEntitie
/** @var \Sylius\Component\Product\Generator\SlugGeneratorInterface */
private $productSlugGenerator;

/** @var \Synolia\SyliusAkeneoPlugin\Repository\ProductFiltersRulesRepository */
private $productFiltersRulesRepository;
/** @var \Synolia\SyliusAkeneoPlugin\Filter\ProductFilterInterface */
private $productFilter;

/** @var \Synolia\SyliusAkeneoPlugin\Service\SyliusAkeneoLocaleCodeProvider */
private $syliusAkeneoLocaleCodeProvider;
Expand Down Expand Up @@ -98,7 +97,7 @@ public function __construct(
EntityManagerInterface $entityManager,
AkeneoTaskProvider $taskProvider,
LoggerInterface $akeneoLogger,
ProductFiltersRulesRepository $productFiltersRulesRepository,
ProductFilterInterface $productFilter,
RepositoryInterface $productTranslationRepository,
FactoryInterface $productTranslationFactory,
SlugGeneratorInterface $productSlugGenerator,
Expand All @@ -121,7 +120,7 @@ public function __construct(

$this->productFactory = $productFactory;
$this->taskProvider = $taskProvider;
$this->productFiltersRulesRepository = $productFiltersRulesRepository;
$this->productFilter = $productFilter;
$this->productTranslationRepository = $productTranslationRepository;
$this->productTranslationFactory = $productTranslationFactory;
$this->productSlugGenerator = $productSlugGenerator;
Expand All @@ -142,12 +141,11 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte
$this->logger->notice(Messages::createOrUpdate($this->type));
$this->productConfiguration = $this->productConfigurationRepository->findOneBy([]);

/** @var \Synolia\SyliusAkeneoPlugin\Entity\ProductFiltersRules $filters */
$filters = $this->productFiltersRulesRepository->findOneBy([]);
if (!$filters instanceof ProductFiltersRules) {
$scope = $this->productFilter->getChannel();
if ($scope === null) {
throw new NoProductFiltersConfigurationException('Product filters must be configured before importing product attributes.');
}
$this->scope = $filters->getChannel();
$this->scope = $scope;

$processedCount = 0;
$totalItemsCount = $this->countTotalProducts(true);
Expand Down
2 changes: 1 addition & 1 deletion src/Task/Product/RetrieveProductsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte
$this->logger->debug(self::class);
$this->logger->notice(Messages::retrieveFromAPI($payload->getType()));

$queryParameters = $this->productFilter->getProductFilters();
$queryParameters = $this->productFilter->getQueryParameters();
$queryParameters['pagination_type'] = 'search_after';

/** @var \Akeneo\Pim\ApiClient\Pagination\PageInterface|null $resources */
Expand Down
2 changes: 1 addition & 1 deletion src/Task/ProductModel/RetrieveProductModelsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(
*/
public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInterface
{
$queryParameters = $this->productFilter->getProductModelFilters();
$queryParameters = $this->productFilter->getModelQueryParameters();

$this->logger->debug(self::class);
$this->logger->notice(Messages::retrieveFromAPI($payload->getType()));
Expand Down