Skip to content

Commit 48be817

Browse files
authored
Add invoices column to orders grid (#387)
New clickable download buttons on orders grid <img width="1399" height="519" alt="image" src="https://github.com/user-attachments/assets/4af34220-f904-4fd3-b026-1de8681a6929" />
2 parents 10305e8 + 0259a6a commit 48be817

File tree

12 files changed

+231
-0
lines changed

12 files changed

+231
-0
lines changed

config/config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ sylius_grid:
102102
parameters:
103103
id: resource.id
104104

105+
sylius_shop_account_order:
106+
fields:
107+
invoices:
108+
type: twig
109+
label: sylius_invoicing.ui.invoices
110+
path: .
111+
options:
112+
template: "@SyliusInvoicingPlugin/shop/account/order/grid/field/invoices.html.twig"
113+
105114
framework:
106115
messenger:
107116
buses:

config/services/twig.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
1313
<services>
14+
<service id="sylius_invoicing.twig.extension.invoices" class="Sylius\InvoicingPlugin\Twig\InvoicesExtension">
15+
<argument type="service" id="sylius_invoicing.repository.invoice" />
16+
<argument>%sylius_invoicing.pdf_generator.enabled%</argument>
17+
<tag name="twig.extension" />
18+
</service>
19+
1420
<service
1521
id="sylius_invoicing.twig.component.invoice.list"
1622
class="Sylius\InvoicingPlugin\Twig\Component\Invoice\ListComponent"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@customer_browsing_invoices
2+
Feature: Showing plain invoice numbers on orders list when PDF is disabled
3+
In order not to expose download links when PDF generation is disabled
4+
As a Customer
5+
I should see invoice numbers without links on the orders list
6+
7+
Background:
8+
Given the store operates on a single channel in "United States"
9+
And the store has a product "Angel T-Shirt"
10+
And the store ships everywhere for free
11+
And the store allows paying with "Cash on Delivery"
12+
And I am a logged in customer
13+
And I placed an order "#00000666"
14+
And I bought a single "Angel T-Shirt"
15+
And I addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
16+
And for the billing address of "Mazikeen Lilim" in the "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
17+
And I chose "Free" shipping method with "Cash on Delivery" payment
18+
19+
@ui @pdf_disabled
20+
Scenario: Invoice numbers are not links on orders list
21+
When I browse my orders
22+
Then I should not be able to download an invoice from my orders list
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@customer_browsing_invoices
2+
Feature: Showing invoice links on orders list when PDF is enabled
3+
In order to download invoices directly from my orders list
4+
As a Customer
5+
I should see clickable invoice numbers when PDF generation is enabled
6+
7+
Background:
8+
Given the store operates on a single channel in "United States"
9+
And the store has a product "Angel T-Shirt"
10+
And the store ships everywhere for free
11+
And the store allows paying with "Cash on Delivery"
12+
And I am a logged in customer
13+
And I placed an order "#00000666"
14+
And I bought a single "Angel T-Shirt"
15+
And I addressed it to "Lucifer Morningstar", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
16+
And for the billing address of "Mazikeen Lilim" in the "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
17+
And I chose "Free" shipping method with "Cash on Delivery" payment
18+
19+
@ui @pdf_enabled
20+
Scenario: Invoice numbers are links on orders list
21+
When I browse my orders
22+
Then I should be able to download an invoice from my orders list

src/Twig/InvoicesExtension.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\InvoicingPlugin\Twig;
15+
16+
use Sylius\Component\Core\Model\OrderInterface;
17+
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
18+
use Twig\Extension\AbstractExtension;
19+
use Twig\TwigFunction;
20+
21+
final class InvoicesExtension extends AbstractExtension
22+
{
23+
public function __construct(
24+
private readonly InvoiceRepositoryInterface $invoiceRepository,
25+
private readonly bool $pdfEnabled = true,
26+
) {
27+
}
28+
29+
public function getFunctions(): array
30+
{
31+
return [
32+
new TwigFunction('invoices_for_order', $this->invoicesForOrder(...)),
33+
new TwigFunction('invoices_pdf_enabled', $this->isPdfEnabled(...)),
34+
];
35+
}
36+
37+
public function invoicesForOrder(OrderInterface $order): array
38+
{
39+
return $this->invoiceRepository->findByOrderNumber($order->getNumber());
40+
}
41+
42+
public function isPdfEnabled(): bool
43+
{
44+
return $this->pdfEnabled;
45+
}
46+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% set invoices = invoices_for_order(data) %}
2+
{% if invoices is empty %}
3+
<span class="text-muted">—</span>
4+
{% else %}
5+
{% set pdf_enabled = invoices_pdf_enabled() %}
6+
{% for invoice in invoices %}
7+
{% if pdf_enabled %}
8+
<div>
9+
<a href="{{ path('sylius_invoicing_shop_invoice_download', {'id': invoice.id}) }}" {{ sylius_test_html_attribute('invoice-link') }}>{{ invoice.number }}</a>
10+
</div>
11+
{% else %}
12+
<div>
13+
<span {{ sylius_test_html_attribute('invoice-number') }}>{{ invoice.number }}</span>
14+
</div>
15+
{% endif %}
16+
{% endfor %}
17+
{% endif %}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Tests\Sylius\InvoicingPlugin\Behat\Context\Ui\Shop;
15+
16+
use Behat\Behat\Context\Context;
17+
use Behat\Step\Then;
18+
use Tests\Sylius\InvoicingPlugin\Behat\Page\Shop\Account\Order\IndexPageInterface;
19+
use Webmozart\Assert\Assert;
20+
21+
final class AccountContext implements Context
22+
{
23+
public function __construct(private IndexPageInterface $orderIndexPage)
24+
{
25+
}
26+
27+
#[Then('I should be able to download an invoice from my orders list')]
28+
public function iShouldBeAbleToDownloadAnInvoiceFromMyOrdersList(): void
29+
{
30+
Assert::true($this->orderIndexPage->hasInvoiceLinks());
31+
}
32+
33+
#[Then('I should not be able to download an invoice from my orders list')]
34+
public function iShouldNotBeAbleToDownloadAnInvoiceFromMyOrdersList(): void
35+
{
36+
Assert::true($this->orderIndexPage->hasPlainInvoiceNumbers());
37+
}
38+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Tests\Sylius\InvoicingPlugin\Behat\Page\Shop\Account\Order;
15+
16+
use Sylius\Behat\Page\Shop\Account\Order\IndexPage as BaseIndexPage;
17+
18+
final class IndexPage extends BaseIndexPage implements IndexPageInterface
19+
{
20+
public function hasInvoiceLinks(): bool
21+
{
22+
return $this->getDocument()->has('css', '[data-test-grid-table-body] [data-test-invoice-link]');
23+
}
24+
25+
public function hasPlainInvoiceNumbers(): bool
26+
{
27+
return $this->getDocument()->has('css', '[data-test-grid-table-body] [data-test-invoice-number]');
28+
}
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Tests\Sylius\InvoicingPlugin\Behat\Page\Shop\Account\Order;
15+
16+
use Sylius\Behat\Page\Shop\Account\Order\IndexPageInterface as BaseIndexPageInterface;
17+
18+
interface IndexPageInterface extends BaseIndexPageInterface
19+
{
20+
public function hasInvoiceLinks(): bool;
21+
22+
public function hasPlainInvoiceNumbers(): bool;
23+
}

tests/Behat/Page/Shop/Order/ShowPageInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace Tests\Sylius\InvoicingPlugin\Behat\Page\Shop\Order;

0 commit comments

Comments
 (0)