Skip to content

Commit

Permalink
Review fixes + default channel color
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszpietrzak1994 committed Apr 19, 2019
1 parent d09733d commit 0f37f89
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ Sonata events. You can read about customizing templates via events here:
<http://docs.sylius.com/en/latest/customization/template.html>
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.
Expand Down
14 changes: 12 additions & 2 deletions spec/Provider/ChannelColorProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
10 changes: 7 additions & 3 deletions src/Provider/ChannelColorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Provider/ChannelColorProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

interface ChannelColorProviderInterface
{
public function __invoke(string $channelCode): string;
public function provide(string $channelCode): string;
}
3 changes: 3 additions & 0 deletions src/Resources/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
parameters:
default_channel_color: "lightGrey"

sylius_mailer:
emails:
invoice_generated:
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@

<service id="Sylius\InvoicingPlugin\Provider\ChannelColorProvider">
<argument type="service" id="sylius.repository.channel" />
<argument>%default_channel_color%</argument>
</service>

<service id="Sylius\InvoicingPlugin\Twig\ChannelColorExtension">
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/ChannelColorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
];
}
}

0 comments on commit 0f37f89

Please sign in to comment.