Skip to content

Commit

Permalink
Merge pull request #57 from BitBagCommerce/feature/api-locale-support
Browse files Browse the repository at this point in the history
Add support for passing locale in +api_graphql_entrypoint route
senghe authored Dec 15, 2022
2 parents b343f51 + f3b4912 commit ff77c46
Showing 4 changed files with 101 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/Fixture/ChannelLocalesFixture.php
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
{

}
}
7 changes: 7 additions & 0 deletions src/Resources/config/config.yml
Original file line number Diff line number Diff line change
@@ -13,3 +13,10 @@ liip_imagine:
sylius_shop_product_large_thumbnail:
filters:
thumbnail: { size: [550, 412], mode: outbound }

sylius_fixtures:
suites:
default:
fixtures:
channel_locales:
priority: 0
7 changes: 7 additions & 0 deletions src/Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
api_graphql_entrypoint:
path: /api/v2/graphql/{_locale}
defaults:
_controller: api_platform.graphql.action.entrypoint
_locale: '%locale%'
_graphql: true

sylius_shop_password_reset:
path: /reset-password
methods: [GET, POST]
14 changes: 14 additions & 0 deletions src/Resources/services/fixtures.xml
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>

0 comments on commit ff77c46

Please sign in to comment.