-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from BitBagCommerce/feature/api-locale-support
Add support for passing locale in +api_graphql_entrypoint route
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusVueStorefront2Plugin\Fixture; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Locale\Model\LocaleInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
final class ChannelLocalesFixture extends AbstractFixture | ||
{ | ||
private const ADDITIONAL_LOCALE_CODE = 'de_DE'; | ||
|
||
private ChannelRepositoryInterface $channelRepository; | ||
|
||
private RepositoryInterface $localeRepository; | ||
|
||
private EntityManagerInterface $entityManager; | ||
|
||
public function __construct( | ||
ChannelRepositoryInterface $channelRepository, | ||
RepositoryInterface $localeRepository, | ||
EntityManagerInterface $entityManager | ||
) { | ||
$this->channelRepository = $channelRepository; | ||
$this->localeRepository = $localeRepository; | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'channel_locales'; | ||
} | ||
|
||
public function load(array $options): void | ||
{ | ||
$channels = $this->channelRepository->findAll(); | ||
if (count($channels) === 0) { | ||
return; | ||
} | ||
|
||
/** @var LocaleInterface|null $additionalLocale */ | ||
$additionalLocale = $this->localeRepository->findOneBy(['code' => self::ADDITIONAL_LOCALE_CODE]); | ||
if ($additionalLocale === null) { | ||
return; | ||
} | ||
|
||
/** @var ChannelInterface $channel */ | ||
foreach ($channels as $channel) { | ||
$channel->addLocale($additionalLocale); | ||
} | ||
|
||
$this->entityManager->flush(); | ||
} | ||
|
||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<defaults public="true" /> | ||
<service id="bitbag.sylius_vue_storefront2_plugin.fixture.channel_locales" class="BitBag\SyliusVueStorefront2Plugin\Fixture\ChannelLocalesFixture"> | ||
<argument type="service" id="sylius.repository.channel" /> | ||
<argument type="service" id="sylius.repository.locale" /> | ||
<argument type="service" id="doctrine.orm.default_entity_manager" /> | ||
<tag name="sylius_fixtures.fixture" /> | ||
</service> | ||
</services> | ||
</container> |