-
-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
Sylius version affected: 1.7.4
Description
Following these steps here: https://docs.sylius.com/en/latest/customization/fixtures.html, adding countries to channels using fixtures does not work
Steps to reproduce
# config/services.yaml
sylius.fixture.example_factory.channel:
class: App\Fixture\Factory\ChannelExampleFactory
arguments:
- "@sylius.factory.channel"
- "@sylius.repository.locale"
- "@sylius.repository.currency"
- "@sylius.repository.zone"
- "@sylius.repository.country"
public: true
sylius.fixture.channel:
class: App\Fixture\ChannelFixture
arguments:
- "@sylius.manager.channel"
- "@sylius.fixture.example_factory.channel"
tags:
- { name: sylius_fixtures.fixture }
# config/packages/sylius_fixtures.yaml
sylius_fixtures:
suites:
myt:
listeners:
orm_purger: ~
logger: ~
fixtures:
locale:
options:
locales:
- 'de_DE'
currency:
options:
currencies:
- 'EUR'
geographical:
options:
countries:
- 'DE'
channel:
options:
custom:
de_store:
name: "DE Store"
code: "DE"
locales:
- "de_DE"
currencies:
- "EUR"
enabled: true
hostname: "localhost"
countries:
- "DE"
//src/Fixture/Factory/ChannelExampleFactory.php
<?php
namespace App\Fixture\Factory;
use Sylius\Bundle\CoreBundle\Fixture\Factory\ChannelExampleFactory as BaseChannelExampleFactory;
use Sylius\Bundle\CoreBundle\Fixture\OptionsResolver\LazyOption;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ChannelExampleFactory extends BaseChannelExampleFactory
{
/** @var RepositoryInterface */
public $countryRepository;
public function __construct(
ChannelFactoryInterface $channelFactory,
RepositoryInterface $localeRepository,
RepositoryInterface $currencyRepository,
RepositoryInterface $zoneRepository,
RepositoryInterface $countryRepository
)
{
$this->countryRepository = $countryRepository;
parent::__construct($channelFactory, $localeRepository, $currencyRepository, $zoneRepository);
}
public function create(array $options = []): ChannelInterface
{
$channel = parent::create($options);
foreach ($options['countries'] as $country) {
$channel->addCountry($country);
}
return $channel;
}
protected function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver
->setDefault('countries', LazyOption::randomOne($this->countryRepository))
->setAllowedTypes('countries', 'array')
->setNormalizer('countries', LazyOption::findOneBy($this->countryRepository, 'code'));
}
}
//src/Fixture/ChannelFixture.php
<?php
namespace App\Fixture;
use Sylius\Bundle\CoreBundle\Fixture\ChannelFixture as BaseChannelFixture;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
final class ChannelFixture extends BaseChannelFixture
{
protected function configureResourceNode(ArrayNodeDefinition $resourceNode): void
{
parent::configureResourceNode($resourceNode);
$resourceNode
->children()
->arrayNode('countries')->scalarPrototype()->end()->end();
}
}
running then
php bin/console sylius:install -s myt
throws this error:
Argument 1 passed to Sylius\Component\Core\Model\Channel::addCountry() must implement interface Sylius\Component\Addressing\Model\CountryInterface, string given, called in /home/lucian/www/sylius/myt
/src/Fixture/Factory/ChannelExampleFactory.php on line 36
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels