diff --git a/src/Component/Arguments/AbstractPaginatorArgumentsBuilder.php b/src/Component/Arguments/AbstractPaginatorArgumentsBuilder.php new file mode 100644 index 0000000000..6442f230cb --- /dev/null +++ b/src/Component/Arguments/AbstractPaginatorArgumentsBuilder.php @@ -0,0 +1,32 @@ + [ + 'type' => 'String', + ], + 'first' => [ + 'type' => 'Int', + ], + 'before' => [ + 'type' => 'String', + ], + 'last' => [ + 'type' => 'Int', + ], + ]; + } +} diff --git a/src/Component/Arguments/PaginatorArgumentsBuilder.php b/src/Component/Arguments/AbstractProductPaginatorArgumentsBuilder.php similarity index 61% rename from src/Component/Arguments/PaginatorArgumentsBuilder.php rename to src/Component/Arguments/AbstractProductPaginatorArgumentsBuilder.php index a3a7b5934b..22898f8e5d 100644 --- a/src/Component/Arguments/PaginatorArgumentsBuilder.php +++ b/src/Component/Arguments/AbstractProductPaginatorArgumentsBuilder.php @@ -4,10 +4,9 @@ namespace Shopsys\FrontendApiBundle\Component\Arguments; -use Overblog\GraphQLBundle\Definition\Builder\MappingInterface; use Shopsys\FrontendApiBundle\Component\Arguments\Exception\MandatoryArgumentMissingException; -class PaginatorArgumentsBuilder implements MappingInterface +class AbstractProductPaginatorArgumentsBuilder extends AbstractPaginatorArgumentsBuilder { protected const CONFIG_ORDER_TYPE_KEY = 'orderingModeType'; @@ -19,38 +18,17 @@ public function toMappingDefinition(array $config): array { $this->checkMandatoryFields($config); - return [ - 'after' => [ - 'type' => 'String', - ], - 'first' => [ - 'type' => 'Int', - ], - 'before' => [ - 'type' => 'String', - ], - 'last' => [ - 'type' => 'Int', - ], + $mappingDefinition = parent::toMappingDefinition($config); + + return array_merge($mappingDefinition, [ 'orderingMode' => [ 'type' => $config[static::CONFIG_ORDER_TYPE_KEY], ], 'filter' => [ 'type' => 'ProductFilter', + 'validation' => 'cascade', ], - 'search' => [ - 'type' => 'String', - ], - 'categorySlug' => [ - 'type' => 'String', - ], - 'brandSlug' => [ - 'type' => 'String', - ], - 'flagSlug' => [ - 'type' => 'String', - ], - ]; + ]); } /** diff --git a/src/Component/Arguments/BlogArticlePaginatorArgumentsBuilder.php b/src/Component/Arguments/BlogArticlePaginatorArgumentsBuilder.php index c62729fb9a..73487e9ad1 100644 --- a/src/Component/Arguments/BlogArticlePaginatorArgumentsBuilder.php +++ b/src/Component/Arguments/BlogArticlePaginatorArgumentsBuilder.php @@ -4,9 +4,7 @@ namespace Shopsys\FrontendApiBundle\Component\Arguments; -use Overblog\GraphQLBundle\Definition\Builder\MappingInterface; - -class BlogArticlePaginatorArgumentsBuilder implements MappingInterface +class BlogArticlePaginatorArgumentsBuilder extends AbstractPaginatorArgumentsBuilder { /** * @param array $config @@ -14,23 +12,13 @@ class BlogArticlePaginatorArgumentsBuilder implements MappingInterface */ public function toMappingDefinition(array $config): array { - return [ - 'after' => [ - 'type' => 'String', - ], - 'first' => [ - 'type' => 'Int', - ], - 'before' => [ - 'type' => 'String', - ], - 'last' => [ - 'type' => 'Int', - ], + $mappingDefinition = parent::toMappingDefinition($config); + + return array_merge($mappingDefinition, [ 'onlyHomepageArticles' => [ 'type' => 'Boolean', 'defaultValue' => false, ], - ]; + ]); } } diff --git a/src/Component/Arguments/ProductPaginatorArgumentsBuilder.php b/src/Component/Arguments/ProductPaginatorArgumentsBuilder.php new file mode 100644 index 0000000000..b4f6247c67 --- /dev/null +++ b/src/Component/Arguments/ProductPaginatorArgumentsBuilder.php @@ -0,0 +1,31 @@ +checkMandatoryFields($config); + + $mappingDefinition = parent::toMappingDefinition($config); + + return array_merge($mappingDefinition, [ + 'categorySlug' => [ + 'type' => 'String', + ], + 'brandSlug' => [ + 'type' => 'String', + ], + 'flagSlug' => [ + 'type' => 'String', + ], + ]); + } +} diff --git a/src/Component/Arguments/ProductSearchPaginatorArgumentsBuilder.php b/src/Component/Arguments/ProductSearchPaginatorArgumentsBuilder.php new file mode 100644 index 0000000000..59bc32407a --- /dev/null +++ b/src/Component/Arguments/ProductSearchPaginatorArgumentsBuilder.php @@ -0,0 +1,25 @@ +checkMandatoryFields($config); + + $mappingDefinition = parent::toMappingDefinition($config); + + return array_merge($mappingDefinition, [ + 'search' => [ + 'type' => 'String', + ], + ]); + } +} diff --git a/src/Model/Product/Filter/ProductFilterFacade.php b/src/Model/Product/Filter/ProductFilterFacade.php index f8da8d4922..3c454208a4 100644 --- a/src/Model/Product/Filter/ProductFilterFacade.php +++ b/src/Model/Product/Filter/ProductFilterFacade.php @@ -74,18 +74,16 @@ public function getProductFilterConfigForBrand(Brand $brand): ProductFilterConfi /** * @param \Shopsys\FrameworkBundle\Model\Category\Category $category - * @param string $searchText * @return \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig */ - public function getProductFilterConfigForCategory(Category $category, string $searchText = ''): ProductFilterConfig + public function getProductFilterConfigForCategory(Category $category): ProductFilterConfig { - $cacheKey = 'category_' . $category->getId() . '_search_' . $searchText; + $cacheKey = 'category_' . $category->getId(); if (!array_key_exists($cacheKey, $this->productFilterConfigCache)) { $this->productFilterConfigCache[$cacheKey] = $this->productFilterConfigFactory->createForCategory( $this->domain->getLocale(), $category, - $searchText, ); } diff --git a/src/Model/Product/ProductFacade.php b/src/Model/Product/ProductFacade.php index d698688ba3..42f192559c 100644 --- a/src/Model/Product/ProductFacade.php +++ b/src/Model/Product/ProductFacade.php @@ -42,8 +42,10 @@ public function getSellableByUuid(string $uuid, int $domainId, PricingGroup $pri * @param string $search * @return int */ - public function getFilteredProductsCountOnCurrentDomain(ProductFilterData $productFilterData, string $search): int - { + public function getFilteredProductsCountOnCurrentDomain( + ProductFilterData $productFilterData, + string $search = '', + ): int { $filterQuery = $this->filterQueryFactory->createListableWithProductFilter($productFilterData); if ($search !== '') { @@ -66,7 +68,7 @@ public function getFilteredProductsOnCurrentDomain( int $offset, string $orderingModeId, ProductFilterData $productFilterData, - string $search, + string $search = '', ): array { $filterQuery = $this->filterQueryFactory->createWithProductFilterData( $productFilterData, diff --git a/src/Resources/config/graphql-types/BrandDecorator.types.yaml b/src/Resources/config/graphql-types/BrandDecorator.types.yaml index e496a75d64..1cfd211f48 100644 --- a/src/Resources/config/graphql-types/BrandDecorator.types.yaml +++ b/src/Resources/config/graphql-types/BrandDecorator.types.yaml @@ -37,7 +37,7 @@ BrandDecorator: type: "ProductConnection" description: "Paginated and ordered products of brand" argsBuilder: - builder: "PaginatorArgumentsBuilder" + builder: "ProductPaginatorArgumentsBuilder" config: orderingModeType: 'ProductOrderingModeEnum' resolve: '@=query("productsByBrandQuery", args, value)' diff --git a/src/Resources/config/graphql-types/CategoryDecorator.types.yaml b/src/Resources/config/graphql-types/CategoryDecorator.types.yaml index 75b41a023a..8e1b28630b 100644 --- a/src/Resources/config/graphql-types/CategoryDecorator.types.yaml +++ b/src/Resources/config/graphql-types/CategoryDecorator.types.yaml @@ -28,7 +28,7 @@ CategoryDecorator: type: "ProductConnection" description: "Paginated and ordered products of category" argsBuilder: - builder: "PaginatorArgumentsBuilder" + builder: "ProductPaginatorArgumentsBuilder" config: orderingModeType: 'ProductOrderingModeEnum' resolve: '@=query("productsByCategoryQuery", args, value)' diff --git a/src/Resources/config/graphql-types/QueryDecorator.types.yaml b/src/Resources/config/graphql-types/QueryDecorator.types.yaml index f404401963..d984c5311b 100644 --- a/src/Resources/config/graphql-types/QueryDecorator.types.yaml +++ b/src/Resources/config/graphql-types/QueryDecorator.types.yaml @@ -18,7 +18,7 @@ QueryDecorator: products: type: "ProductConnection" argsBuilder: - builder: "PaginatorArgumentsBuilder" + builder: "ProductPaginatorArgumentsBuilder" config: orderingModeType: 'ProductOrderingModeEnum' resolve: "@=query('productsQuery', args)" @@ -35,7 +35,7 @@ QueryDecorator: productsSearch: type: "ProductConnection!" argsBuilder: - builder: "PaginatorArgumentsBuilder" + builder: "ProductSearchPaginatorArgumentsBuilder" config: orderingModeType: 'ProductOrderingModeEnum' resolve: "@=query('productsSearchQuery', args)"