From 1c847f120293d73102bac5faddecf0768b191e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Ludvik?= Date: Tue, 19 Nov 2024 15:36:19 +0100 Subject: [PATCH 1/2] slug of Seo Pages is no longer generated via friendly URLs, but is simple text --- .../shopsys-routing/routing_friendly_url.yaml | 3 - .../DataFixtures/Demo/SeoPageDataFixture.php | 28 +++----- .../Functional/Model/SeoPage/SeoPageTest.php | 5 +- .../Functional/Hreflang/HreflangLinksTest.php | 71 ++++++++++++------- 4 files changed, 57 insertions(+), 50 deletions(-) diff --git a/app/config/shopsys-routing/routing_friendly_url.yaml b/app/config/shopsys-routing/routing_friendly_url.yaml index bb4270b0a7..494982b4e8 100644 --- a/app/config/shopsys-routing/routing_friendly_url.yaml +++ b/app/config/shopsys-routing/routing_friendly_url.yaml @@ -27,6 +27,3 @@ front_stores_detail: front_flag_detail: path: friendly-url - -front_page_seo: - path: friendly-url diff --git a/app/src/DataFixtures/Demo/SeoPageDataFixture.php b/app/src/DataFixtures/Demo/SeoPageDataFixture.php index 5d159eead7..1afde1ba36 100644 --- a/app/src/DataFixtures/Demo/SeoPageDataFixture.php +++ b/app/src/DataFixtures/Demo/SeoPageDataFixture.php @@ -6,15 +6,14 @@ use Doctrine\Persistence\ObjectManager; use Shopsys\FrameworkBundle\Component\DataFixture\AbstractReferenceFixture; +use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig; use Shopsys\FrameworkBundle\Component\Domain\Domain; -use Shopsys\FrameworkBundle\Component\Router\DomainRouterFactory; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageData; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageDataFactory; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageFacade; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageRepository; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageSlugTransformer; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class SeoPageDataFixture extends AbstractReferenceFixture { @@ -32,14 +31,12 @@ class SeoPageDataFixture extends AbstractReferenceFixture * @param \Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageRepository $seoPageRepository * @param \Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageFacade $seoPageFacade * @param \Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageDataFactory $seoPageDataFactory - * @param \Shopsys\FrameworkBundle\Component\Router\DomainRouterFactory $domainRouterFactory */ public function __construct( private readonly Domain $domain, private readonly SeoPageRepository $seoPageRepository, private readonly SeoPageFacade $seoPageFacade, private readonly SeoPageDataFactory $seoPageDataFactory, - private readonly DomainRouterFactory $domainRouterFactory, ) { } @@ -60,14 +57,12 @@ private function createDemoSeoPages(): void foreach ($this->domain->getAll() as $domainConfig) { $domainId = $domainConfig->getId(); - $locale = $domainConfig->getLocale(); $seoPageData->pageSlugsIndexedByDomainId[$domainId] = $pageSlug; $this->fillSeoPageData( $seoPageData, - $domainId, - $locale, + $domainConfig, ); } @@ -92,8 +87,7 @@ private function editPredefinedSeoPages(): void foreach ($this->domainsForDataFixtureProvider->getAllowedDemoDataDomains() as $domainConfig) { $this->fillSeoPageData( $seoPageData, - $domainConfig->getId(), - $domainConfig->getLocale(), + $domainConfig, $seoPage->getId(), ); } @@ -104,29 +98,25 @@ private function editPredefinedSeoPages(): void /** * @param \Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageData $seoPageData - * @param int $domainId - * @param string $locale + * @param \Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig $domainConfig * @param int|null $seoPageId */ private function fillSeoPageData( SeoPageData $seoPageData, - int $domainId, - string $locale, + DomainConfig $domainConfig, ?int $seoPageId = null, ): void { - $seoPageDomainRouter = $this->domainRouterFactory->getRouter($domainId); - + $domainId = $domainConfig->getId(); + $locale = $domainConfig->getLocale(); $pageName = $seoPageData->pageName; $pageSlug = $seoPageData->pageSlugsIndexedByDomainId[$domainId]; $seoPageSlug = SeoPageSlugTransformer::transformFriendlyUrlToSeoPageSlug($pageSlug); if ($seoPageSlug === SeoPage::SEO_PAGE_HOMEPAGE_SLUG || $seoPageId === null) { - $canonicalUrl = $seoPageDomainRouter->generate('front_homepage', [], UrlGeneratorInterface::ABSOLUTE_URL); + $canonicalUrl = $domainConfig->getUrl(); } else { - $canonicalUrl = $seoPageDomainRouter->generate('front_page_seo', [ - 'id' => $seoPageId, - ], UrlGeneratorInterface::ABSOLUTE_URL); + $canonicalUrl = $domainConfig->getUrl() . '/' . $seoPageSlug; } $seoPageData->seoTitlesIndexedByDomainId[$domainId] = $this->formatAttributeValue($pageName, 'title', $locale); diff --git a/app/tests/App/Functional/Model/SeoPage/SeoPageTest.php b/app/tests/App/Functional/Model/SeoPage/SeoPageTest.php index 42ff249a05..b09fc0fa94 100644 --- a/app/tests/App/Functional/Model/SeoPage/SeoPageTest.php +++ b/app/tests/App/Functional/Model/SeoPage/SeoPageTest.php @@ -4,13 +4,14 @@ namespace Tests\App\Functional\Model\SeoPage; -use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageDataFactory; use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPageFacade; use Tests\App\Test\TransactionFunctionalTestCase; class SeoPageTest extends TransactionFunctionalTestCase { + private const int HOMEPAGE_SEO_PAGE_ID = 1; + /** * @inject */ @@ -25,7 +26,7 @@ public function testSeoPageMutability(): void { $domainId = $this->domain->getId(); - $seoPage = $this->seoPageFacade->getByDomainIdAndPageSlug($domainId, SeoPage::SEO_PAGE_HOMEPAGE_SLUG); + $seoPage = $this->seoPageFacade->getById(self::HOMEPAGE_SEO_PAGE_ID); $seoPageData = $this->seoPageDataFactory->createFromSeoPage($seoPage); $seoPageSlug = $seoPageData->pageSlugsIndexedByDomainId[$domainId]; diff --git a/app/tests/FrontendApiBundle/Functional/Hreflang/HreflangLinksTest.php b/app/tests/FrontendApiBundle/Functional/Hreflang/HreflangLinksTest.php index 86481d3e2e..1de831677b 100644 --- a/app/tests/FrontendApiBundle/Functional/Hreflang/HreflangLinksTest.php +++ b/app/tests/FrontendApiBundle/Functional/Hreflang/HreflangLinksTest.php @@ -12,7 +12,9 @@ use App\DataFixtures\Demo\SeoPageDataFixture; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; +use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Component\Router\FriendlyUrl\FriendlyUrlFacade; +use Shopsys\FrameworkBundle\Model\Seo\Page\SeoPage; use Shopsys\FrameworkBundle\Model\Seo\SeoSettingFacade; use Tests\FrontendApiBundle\Test\GraphQlTestCase; @@ -70,7 +72,7 @@ public static function getHreflangEntitiesDataProvider(): iterable yield 'SeoPage' => [ 'entityReference' => SeoPageDataFixture::FIRST_DEMO_SEO_PAGE, - 'routeName' => 'front_page_seo', + 'routeName' => '', 'graphQlFileName' => 'SeoPageHreflangLinksQuery.graphql', 'graphQlType' => 'seoPage', ]; @@ -114,11 +116,7 @@ public function testNoAlternateReturnsOnlyItself( $response = $this->getResponseContentForGql( __DIR__ . '/graphql/' . $graphQlFileName, [ - 'urlSlug' => $this->friendlyUrlFacade->getMainFriendlyUrlSlug( - $this->domain->getId(), - $routeName, - $entity->getId(), - ), + 'urlSlug' => $this->getFriendlyUrlSlug($routeName, $entity), ], ); $data = $this->getResponseDataForGraphQlType($response, $graphQlType); @@ -127,11 +125,7 @@ public function testNoAlternateReturnsOnlyItself( 'hreflangLinks' => [ [ 'hreflang' => $this->getFirstDomainLocale(), - 'href' => $this->friendlyUrlFacade->getAbsoluteUrlByRouteNameAndEntityId( - $this->domain->getId(), - $routeName, - $entity->getId(), - ), + 'href' => $this->getUrlByRouteNameAndEntityId($routeName, Domain::FIRST_DOMAIN_ID, $entity), ], ], ]; @@ -163,11 +157,7 @@ public function testAlternateDomainLanguages( $response = $this->getResponseContentForGql( __DIR__ . '/graphql/' . $graphQlFileName, [ - 'urlSlug' => $this->friendlyUrlFacade->getMainFriendlyUrlSlug( - $this->domain->getId(), - $routeName, - $entity->getId(), - ), + 'urlSlug' => $this->getFriendlyUrlSlug($routeName, $entity), ], ); $data = $this->getResponseDataForGraphQlType($response, $graphQlType); @@ -176,23 +166,52 @@ public function testAlternateDomainLanguages( 'hreflangLinks' => [ [ 'hreflang' => $this->getFirstDomainLocale(), - 'href' => $this->friendlyUrlFacade->getAbsoluteUrlByRouteNameAndEntityId( - $this->domain->getId(), - $routeName, - $entity->getId(), - ), + 'href' => $this->getUrlByRouteNameAndEntityId($routeName, Domain::FIRST_DOMAIN_ID, $entity), ], [ 'hreflang' => $this->domain->getDomainConfigById($secondDomainId)->getLocale(), - 'href' => $this->friendlyUrlFacade->getAbsoluteUrlByRouteNameAndEntityId( - $secondDomainId, - $routeName, - $entity->getId(), - ), + 'href' => $this->getUrlByRouteNameAndEntityId($routeName, $secondDomainId, $entity), ], ], ]; self::assertEquals($expected, $data); } + + /** + * @param string $routeName + * @param object $entity + * @return string + */ + private function getFriendlyUrlSlug(string $routeName, object $entity): string + { + if ($entity instanceof SeoPage) { + return $entity->getPageSlug($this->domain->getId()); + } + + return $this->friendlyUrlFacade->getMainFriendlyUrlSlug( + $this->domain->getId(), + $routeName, + $entity->getId(), + ); + } + + /** + * @param string $routeName + * @param int $domainId + * @param object $entity + * @return string + */ + private function getUrlByRouteNameAndEntityId(string $routeName, int $domainId, object $entity): string + { + if ($entity instanceof SeoPage) { + return $this->domain->getUrl() . '/' . $entity->getPageSlug($domainId); + } + + return $this->friendlyUrlFacade->getAbsoluteUrlByRouteNameAndEntityId( + $domainId, + $routeName, + $entity->getId(), + ); + } } From 1aba7e946531c60736e15cc6cffd8d0decc428ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Ludvik?= Date: Wed, 20 Nov 2024 13:47:05 +0100 Subject: [PATCH 2/2] no-log errors are no longer logged to console in dev environment --- storefront/urql/errorExchange.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/storefront/urql/errorExchange.ts b/storefront/urql/errorExchange.ts index 4bf3a85bac..28ee2fff3a 100644 --- a/storefront/urql/errorExchange.ts +++ b/storefront/urql/errorExchange.ts @@ -49,7 +49,7 @@ export const getErrorExchange = } if (isWithErrorDebugging) { - handleErrorMessagesForDevelopment(error); + handleErrorMessagesForDevelopment(error, t); } else { handleErrorMessagesForUsers(error, t, operation); } @@ -58,12 +58,16 @@ export const getErrorExchange = }; }; -const handleErrorMessagesForDevelopment = (error: CombinedError) => { - logException({ - message: error.message, - originalError: JSON.stringify(error), - location: 'getErrorExchange.handleErrorMessagesForDevelopment', - }); +const handleErrorMessagesForDevelopment = (error: CombinedError, t: Translate) => { + const parsedErrors = getUserFriendlyErrors(error, t); + + if (!parsedErrors.applicationError || !isNoLogError(parsedErrors.applicationError.type)) { + logException({ + message: error.message, + originalError: JSON.stringify(error), + location: 'getErrorExchange.handleErrorMessagesForDevelopment', + }); + } if (isWithToastAndConsoleErrorDebugging) { error.graphQLErrors