Skip to content

Commit

Permalink
Keep current locale set on results to have correct translation
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Apr 9, 2024
1 parent d83286d commit f64e329
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Provider/ProductUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace MonsieurBiz\SyliusMenuPlugin\Provider;

use Sylius\Component\Core\Model\Product;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Symfony\Component\Routing\RouterInterface;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -56,7 +56,9 @@ protected function getResults(string $locale, string $search = ''): iterable

protected function addItemFromResult(object $result, string $locale): void
{
Assert::isInstanceOf($result, Product::class);
Assert::isInstanceOf($result, ProductInterface::class);
/** @var ProductInterface $result */
$result->setCurrentLocale($locale);
$this->addItem(
(string) $result->getName(),
$this->router->generate('sylius_shop_product_show', ['slug' => $result->getSlug(), '_locale' => $locale])
Expand Down
2 changes: 2 additions & 0 deletions src/Provider/TaxonUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ protected function getResults(string $locale, string $search = ''): iterable
protected function addItemFromResult(object $result, string $locale): void
{
Assert::isInstanceOf($result, TaxonInterface::class);
/** @var TaxonInterface $result */
$result->setCurrentLocale($locale);
$this->addItem(
(string) $result->getFullname(' > '),
$this->router->generate('sylius_shop_product_index', ['slug' => $result->getSlug(), '_locale' => $locale])
Expand Down

0 comments on commit f64e329

Please sign in to comment.