Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make invoices and credit memo grid consistent #124

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

GSadee marked this conversation as resolved.
Show resolved Hide resolved
## Fixtures

You can add `ShopBillingData` fixtures into a yaml to add Channel ShopBillingData info to your installation.
Expand Down
43 changes: 43 additions & 0 deletions spec/Provider/ChannelColorProviderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace spec\Sylius\InvoicingPlugin\Provider;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\InvoicingPlugin\Provider\ChannelColorProviderInterface;

final class ChannelColorProviderSpec extends ObjectBehavior
{
public function let(ChannelRepositoryInterface $channelRepository): void
{
$this->beConstructedWith($channelRepository, 'whiteGrey');
}

public function it_implements_channel_color_provider_interface(): void
{
$this->shouldImplement(ChannelColorProviderInterface::class);
}

public function it_returns_channel_color(
ChannelRepositoryInterface $channelRepository,
ChannelInterface $channel
): void {
$channel->getColor()->willReturn('black');
$channelRepository->findOneByCode('en_US')->willReturn($channel);

$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');
}
}
31 changes: 31 additions & 0 deletions src/Provider/ChannelColorProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Sylius\InvoicingPlugin\Provider;

use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;

final class ChannelColorProvider implements ChannelColorProviderInterface
{
/** @var ChannelRepositoryInterface */
private $channelRepository;

/** @var string */
private $defaultChannelColor;

public function __construct(ChannelRepositoryInterface $channelRepository, string $defaultChannelColor)
{
$this->channelRepository = $channelRepository;
$this->defaultChannelColor = $defaultChannelColor;
}

public function provide(string $channelCode): string
{
/** @var ChannelInterface $channel */
$channel = $this->channelRepository->findOneByCode($channelCode);

return $channel->getColor() ?? $this->defaultChannelColor;
}
}
10 changes: 10 additions & 0 deletions src/Provider/ChannelColorProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Sylius\InvoicingPlugin\Provider;

interface ChannelColorProviderInterface
{
public function provide(string $channelCode): string;
}
30 changes: 26 additions & 4 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 Expand Up @@ -47,14 +50,24 @@ sylius_grid:
options:
template: '@SyliusInvoicingPlugin/Invoice/Grid/Field/orderNumber.html.twig'
sortable: true
channel:
type: twig
label: sylius.ui.channel
options:
template: "@SyliusInvoicingPlugin/Invoice/Grid/Field/channel.html.twig"
total:
type: twig
label: sylius.ui.total
path: .
sortable: total
options:
template: "@SyliusAdmin/Order/Grid/Field/total.html.twig"
issuedAt:
type: datetime
label: sylius_invoicing_plugin.ui.issued_at
options:
format: 'Y-m-d H:i:s'
sortable: true
channel:
type: string
label: sylius.ui.channel
path: channel.name
filters:
orderNumber:
type: string
Expand All @@ -81,3 +94,12 @@ sylius_grid:
route: sylius_invoicing_plugin_admin_invoice_download
parameters:
id: resource.id
resend:
type: default
label: sylius_invoicing_plugin.ui.resend_invoice
icon: send
options:
link:
route: sylius_invoicing_plugin_admin_invoice_resend
parameters:
id: resource.id
10 changes: 10 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,15 @@
<argument type="service" id="sylius.repository.order" />
<tag name="console.command" command="sylius-invoicing:generate-invoices" />
</service>

<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">
<argument type="service" id="Sylius\InvoicingPlugin\Provider\ChannelColorProvider" />
<tag name="twig.extension" />
</service>
</services>
</container>
1 change: 1 addition & 0 deletions src/Resources/views/Invoice/Grid/Field/channel.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="ui small horizontal circular label" style="background-color: {{ data.code|sylius_channel_color }}"></span> {{ data.name }}
27 changes: 27 additions & 0 deletions src/Twig/ChannelColorExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Sylius\InvoicingPlugin\Twig;

use Sylius\InvoicingPlugin\Provider\ChannelColorProviderInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

final class ChannelColorExtension extends AbstractExtension
{
/** @var ChannelColorProviderInterface */
private $channelColorProvider;

public function __construct(ChannelColorProviderInterface $channelColorProvider)
{
$this->channelColorProvider = $channelColorProvider;
}

public function getFilters(): array
{
return [
new TwigFilter('sylius_channel_color', [$this->channelColorProvider, 'provide']),
];
}
}