Skip to content

Commit

Permalink
Adjusted locale switcher for internal shop pages without translations
Browse files Browse the repository at this point in the history
  • Loading branch information
triongroup committed Apr 26, 2023
1 parent c14622c commit 738d977
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- '@Pimcore\Model\Document\Service'
- '@CoreShop\Component\Core\Context\ShopperContextInterface'
- '@Symfony\Component\HttpFoundation\RequestStack'
- '@service_container'
tags:
- { name: twig.extension }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Pimcore\Model\Document;
use Pimcore\Model\Site;
use Pimcore\Tool;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Extension\AbstractExtension;
Expand All @@ -35,6 +36,7 @@ public function __construct(
private Document\Service $documentService,
private ShopperContextInterface $shopperContext,
private RequestStack $requestStack,
protected ContainerInterface $container,
) {
}

Expand Down Expand Up @@ -84,16 +86,27 @@ public function getLocalizedLinks(Document $document): array
continue;
}

if (isset($translations[$language])) {
$localizedDocument = Document::getById($translations[$language]);
$link = '';
if ($this->getMainRequest()->attributes->get('pimcore_request_source') === 'staticroute') {
$route = $this->getMainRequest()->attributes->get('_route');
$link = $this->container->get('router')->generate($route, ['_locale' => $language]);

} else {
$localizedDocument = Document::getByPath($target);
if ( isset($translations[$language]) ) {
$localizedDocument = Document::getById($translations[$language]);
} else {
$localizedDocument = Document::getByPath($target);
}

if ( $localizedDocument instanceof Document && $localizedDocument->getPublished() ) {
$link = $localizedDocument->getFullPath();
}
}

if ($localizedDocument instanceof Document && $localizedDocument->getPublished()) {
if (!empty($link)) {
$links[] = [
'language' => $language,
'target' => $localizedDocument->getFullPath(),
'target' => $link,
'displayLanguage' => \Locale::getDisplayLanguage($language, $language),
];
}
Expand Down

0 comments on commit 738d977

Please sign in to comment.