From 0bd534fd9da7a25dd42d0abfafd75e00fb1ea30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Ludvik?= Date: Mon, 28 Aug 2023 13:07:39 +0200 Subject: [PATCH 1/3] fixed black and red color category seo mix in data fixtures --- app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php b/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php index 6bbe04ee91..32760a0c46 100644 --- a/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php +++ b/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php @@ -156,7 +156,7 @@ public function load(ObjectManager $manager) $choseCategorySeoMixCombinationArray['flagId'] = null; $choseCategorySeoMixCombinationArray['parameterValueIdsByParameterIds'] = [ // 'Colour' => 'Black' - 62 => 199, + 63 => 210, ]; $this->createReadyCategorySeoMix( ChoseCategorySeoMixCombination::createFromArray($choseCategorySeoMixCombinationArray), @@ -172,7 +172,7 @@ public function load(ObjectManager $manager) $choseCategorySeoMixCombinationArray['parameterValueIdsByParameterIds'] = [ // 'Colour' => 'Red' - 62 => 197, + 63 => 206, ]; $this->createReadyCategorySeoMix( ChoseCategorySeoMixCombination::createFromArray($choseCategorySeoMixCombinationArray), From f8114f03cbf2ad58df3f1810cf267c313d4afc5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Ludvik?= Date: Mon, 28 Aug 2023 14:24:34 +0200 Subject: [PATCH 2/3] fixed default ordering for seo category mixes --- app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php b/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php index 32760a0c46..6c529e3727 100644 --- a/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php +++ b/app/src/DataFixtures/Demo/ReadyCategorySeoDataFixture.php @@ -132,6 +132,7 @@ public function load(ObjectManager $manager) t('meta description of Electronics from most expensive seo category', [], Translator::DATA_FIXTURES_TRANSLATION_DOMAIN, $firstDomainLocale), ); + $choseCategorySeoMixCombinationArray['ordering'] = ProductListOrderingConfig::ORDER_BY_PRIORITY; $choseCategorySeoMixCombinationArray['flagId'] = null; $choseCategorySeoMixCombinationArray['parameterValueIdsByParameterIds'] = [ // 'USB' => 'Yes' From fd45b4e87b7b512d353823d4e0507a63d0a5e286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Ludvik?= Date: Wed, 30 Aug 2023 12:34:02 +0200 Subject: [PATCH 3/3] frontend API: SEO categories are always correctly resolved in CategoryQuery --- .../Resolver/Category/CategoryQuery.php | 31 ++++++++++--------- .../CategorySeo/ReadyCategorySeoMixFacade.php | 19 +++++++++++- .../ReadyCategorySeoMixTest.php | 2 +- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/src/FrontendApi/Resolver/Category/CategoryQuery.php b/app/src/FrontendApi/Resolver/Category/CategoryQuery.php index b0bac6d0f2..5043b2ba05 100644 --- a/app/src/FrontendApi/Resolver/Category/CategoryQuery.php +++ b/app/src/FrontendApi/Resolver/Category/CategoryQuery.php @@ -14,6 +14,7 @@ use App\Model\CategorySeo\ReadyCategorySeoMix; use App\Model\CategorySeo\ReadyCategorySeoMixFacade; use App\Model\Product\Flag\Flag; +use App\Model\Product\Parameter\Exception\ParameterValueNotFoundException; use App\Model\Product\Parameter\ParameterFacade; use GraphQL\Type\Definition\ResolveInfo; use Overblog\GraphQLBundle\Definition\Argument; @@ -22,6 +23,7 @@ use Shopsys\FrameworkBundle\Model\Category\Category as BaseCategory; use Shopsys\FrameworkBundle\Model\Category\CategoryFacade; use Shopsys\FrameworkBundle\Model\Category\Exception\CategoryNotFoundException; +use Shopsys\FrameworkBundle\Model\Product\Parameter\Exception\ParameterNotFoundException; use Shopsys\FrontendApiBundle\Model\Error\InvalidArgumentUserError; use Shopsys\FrontendApiBundle\Model\FriendlyUrl\FriendlyUrlFacade; use Shopsys\FrontendApiBundle\Model\Resolver\Category\CategoryQuery as BaseCategoryQuery; @@ -121,8 +123,13 @@ public function categoryOrSeoMixByUuidOrUrlSlugQuery( throw new ReadyCategorySeoMixNotFoundUserError(sprintf('ReadyCategorySeoMix with URL slug "%s" does not exist.', $urlSlug)); } - if ($this->isSortingDifferentFromReadyCategorySeoMix($info, $readyCategorySeoMix) || $this->isFilterSet($info)) { - return $readyCategorySeoMix->getCategory(); + $matchingReadyCategorySeoMix = $this->findMatchingReadyCategorySeoMix($info, $readyCategorySeoMix->getCategory()); + + if ( + $matchingReadyCategorySeoMix !== $readyCategorySeoMix && + ($this->isFilterSet($info) || $this->isSortingDifferentFromReadyCategorySeoMix($info, $readyCategorySeoMix)) + ) { + return $matchingReadyCategorySeoMix ?? $readyCategorySeoMix->getCategory(); } return $readyCategorySeoMix; @@ -161,21 +168,17 @@ public function categoriesFilteredByProductFilterForFlagQuery(Argument $argument private function findMatchingReadyCategorySeoMix(ResolveInfo $info, Category $category): ?ReadyCategorySeoMix { $variableValues = $info->variableValues; - $onlyInStock = $variableValues['filter']['onlyInStock'] ?? false; - $minimalPrice = $variableValues['filter']['minimalPrice'] ?? null; - $maximalPrice = $variableValues['filter']['maximalPrice'] ?? null; - $brandChoices = $variableValues['filter']['brands'] ?? []; - if ($onlyInStock || isset($minimalPrice) || isset($maximalPrice) || count($brandChoices) > 0) { + try { + return $this->readyCategorySeoMixFacade->findReadyCategorySeoMixByQueryInputData( + $category->getId(), + $variableValues['filter']['parameters'] ?? [], + $variableValues['filter']['flags'] ?? [], + $variableValues['orderingMode'] ?? ProductsQuery::getDefaultOrderingModeForListing(), + ); + } catch (ParameterValueNotFoundException | ParameterNotFoundException) { return null; } - - return $this->readyCategorySeoMixFacade->findReadyCategorySeoMixByQueryInputData( - $category->getId(), - $variableValues['filter']['parameters'] ?? [], - $variableValues['filter']['flags'] ?? [], - $variableValues['orderingMode'] ?? ProductsQuery::getDefaultOrderingModeForListing(), - ); } /** diff --git a/app/src/Model/CategorySeo/ReadyCategorySeoMixFacade.php b/app/src/Model/CategorySeo/ReadyCategorySeoMixFacade.php index bfa77465aa..07493a1bd1 100644 --- a/app/src/Model/CategorySeo/ReadyCategorySeoMixFacade.php +++ b/app/src/Model/CategorySeo/ReadyCategorySeoMixFacade.php @@ -18,6 +18,7 @@ use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Component\Router\FriendlyUrl\UrlListData; +use Shopsys\FrameworkBundle\Model\Product\Parameter\Exception\ParameterNotFoundException; use Shopsys\FrameworkBundle\Model\Product\Parameter\Parameter; class ReadyCategorySeoMixFacade @@ -311,6 +312,13 @@ private function getParameterValueIdsByParameterId(array $parametersFilterData, $parameterValueIdsByParameterId = []; foreach ($parametersFilterData as $parameterFilterData) { + if (array_key_exists($parameterFilterData['parameter'], $parameterIdsByUuids) === false) { + throw new ParameterNotFoundException(sprintf( + 'Parameter with uuid "%s" was not found', + $parameterFilterData['parameter'], + )); + } + $parameterId = $parameterIdsByUuids[$parameterFilterData['parameter']]; if (count($parameterFilterData['values']) === 0) { @@ -319,7 +327,16 @@ private function getParameterValueIdsByParameterId(array $parametersFilterData, $text = $parameterFilterData['minimalValue']; $parameterValueId = $this->parameterFacade->getParameterValueIdByText((string)$text, $currentLocale); } else { - $parameterValueId = $parameterValueIdsByUuids[reset($parameterFilterData['values'])]; + $parameterUuid = reset($parameterFilterData['values']); + + if (array_key_exists($parameterUuid, $parameterValueIdsByUuids) === false) { + throw new ParameterValueNotFoundException(sprintf( + 'Parameter value with uuid "%s" was not found', + $parameterUuid, + )); + } + + $parameterValueId = $parameterValueIdsByUuids[$parameterUuid]; } $parameterValueIdsByParameterId[$parameterId] = $parameterValueId; } diff --git a/app/tests/FrontendApiBundle/Functional/Category/ReadyCategorySeoMix/ReadyCategorySeoMixTest.php b/app/tests/FrontendApiBundle/Functional/Category/ReadyCategorySeoMix/ReadyCategorySeoMixTest.php index d144610bf6..2997154607 100644 --- a/app/tests/FrontendApiBundle/Functional/Category/ReadyCategorySeoMix/ReadyCategorySeoMixTest.php +++ b/app/tests/FrontendApiBundle/Functional/Category/ReadyCategorySeoMix/ReadyCategorySeoMixTest.php @@ -286,7 +286,7 @@ public function testCategoryDataAreReturnedWhenSeoCategoryWithOrderingIsQueried( $categoryPc = $this->getReference(CategoryDataFixture::CATEGORY_PC); $categoryPcSlug = $this->urlGenerator->generate('front_product_list', ['id' => $categoryPc->getId()]); $data = $this->getDataForCategorySeoMixPcNewWithUsb(__DIR__ . '/../../_graphql/query/ReadyCategorySeoMixQuery.graphql', [ - 'orderingMode' => 'PRIORITY', + 'orderingMode' => 'NAME_ASC', ]); $this->assertNull($data['originalCategorySlug']);