From 0f37f8958c6319b86195082ab238dbd6f76d6c0f Mon Sep 17 00:00:00 2001 From: Bartosz Pietrzak Date: Fri, 19 Apr 2019 11:37:43 +0200 Subject: [PATCH] Review fixes + default channel color --- README.md | 5 +++++ spec/Provider/ChannelColorProviderSpec.php | 14 ++++++++++++-- src/Provider/ChannelColorProvider.php | 10 +++++++--- src/Provider/ChannelColorProviderInterface.php | 2 +- src/Resources/config/config.yml | 3 +++ src/Resources/config/services.xml | 1 + src/Twig/ChannelColorExtension.php | 2 +- 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b650563f..0d141080 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,11 @@ Sonata events. You can read about customizing templates via events here: +Invoicing Plugin renders invoices grid using a certain pattern, including displaying a dot next to channel in which an invoice as issued. +The dot's color is dependant on a property defined on Channel entity or, if not provided, a global parameter named `default_channel_color`. + +Like any other parameter, `default_channel_color` can also be overwritten in your `config.yml` file. + ## Fixtures You can add `ShopBillingData` fixtures into a yaml to add Channel ShopBillingData info to your installation. diff --git a/spec/Provider/ChannelColorProviderSpec.php b/spec/Provider/ChannelColorProviderSpec.php index b32d6e51..8fa70685 100644 --- a/spec/Provider/ChannelColorProviderSpec.php +++ b/spec/Provider/ChannelColorProviderSpec.php @@ -13,7 +13,7 @@ final class ChannelColorProviderSpec extends ObjectBehavior { public function let(ChannelRepositoryInterface $channelRepository): void { - $this->beConstructedWith($channelRepository); + $this->beConstructedWith($channelRepository, 'whiteGrey'); } public function it_implements_channel_color_provider_interface(): void @@ -28,6 +28,16 @@ public function it_returns_channel_color( $channel->getColor()->willReturn('black'); $channelRepository->findOneByCode('en_US')->willReturn($channel); - $this->__invoke('en_US')->shouldReturn('black'); + $this->provide('en_US')->shouldReturn('black'); + } + + public function it_returns_default_channel_color_if_channel_does_not_provide_one( + ChannelRepositoryInterface $channelRepository, + ChannelInterface $channel + ): void { + $channel->getColor()->willReturn(null); + $channelRepository->findOneByCode('en_US')->willReturn($channel); + + $this->provide('en_US')->shouldReturn('whiteGrey'); } } diff --git a/src/Provider/ChannelColorProvider.php b/src/Provider/ChannelColorProvider.php index 6f550f4b..7f03ef45 100644 --- a/src/Provider/ChannelColorProvider.php +++ b/src/Provider/ChannelColorProvider.php @@ -12,16 +12,20 @@ final class ChannelColorProvider implements ChannelColorProviderInterface /** @var ChannelRepositoryInterface */ private $channelRepository; - public function __construct(ChannelRepositoryInterface $channelRepository) + /** @var string */ + private $defaultChannelColor; + + public function __construct(ChannelRepositoryInterface $channelRepository, string $defaultChannelColor) { $this->channelRepository = $channelRepository; + $this->defaultChannelColor = $defaultChannelColor; } - public function __invoke(string $channelCode): string + public function provide(string $channelCode): string { /** @var ChannelInterface $channel */ $channel = $this->channelRepository->findOneByCode($channelCode); - return $channel->getColor(); + return null !== $channel->getColor() ? $channel->getColor() : $this->defaultChannelColor; } } diff --git a/src/Provider/ChannelColorProviderInterface.php b/src/Provider/ChannelColorProviderInterface.php index 23b3794f..f046e2b8 100644 --- a/src/Provider/ChannelColorProviderInterface.php +++ b/src/Provider/ChannelColorProviderInterface.php @@ -6,5 +6,5 @@ interface ChannelColorProviderInterface { - public function __invoke(string $channelCode): string; + public function provide(string $channelCode): string; } diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml index 1f5f0a43..c40fd713 100644 --- a/src/Resources/config/config.yml +++ b/src/Resources/config/config.yml @@ -1,3 +1,6 @@ +parameters: + default_channel_color: "lightGrey" + sylius_mailer: emails: invoice_generated: diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 73dabfda..b57f595e 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -139,6 +139,7 @@ + %default_channel_color% diff --git a/src/Twig/ChannelColorExtension.php b/src/Twig/ChannelColorExtension.php index 8f543ff3..3a291b57 100644 --- a/src/Twig/ChannelColorExtension.php +++ b/src/Twig/ChannelColorExtension.php @@ -21,7 +21,7 @@ public function __construct(ChannelColorProviderInterface $channelColorProvider) public function getFilters(): array { return [ - new TwigFilter('sylius_channel_color', [$this->channelColorProvider, '__invoke']), + new TwigFilter('sylius_channel_color', [$this->channelColorProvider, 'provide']), ]; } }