Skip to content

Commit abaa3da

Browse files
authored
refactor #146 [Admin] Unify order link in Credit Memos (Tomanhez)
This PR was merged into the 1.0-dev branch. Discussion ---------- **Before:** ![Screenshot 2019-07-11 at 11 43 17](https://user-images.githubusercontent.com/39232096/61049785-a4d87c00-a3e5-11e9-8031-47e1cf579f43.png) **After:** ![Screenshot 2019-07-12 at 07 45 08](https://user-images.githubusercontent.com/39232096/61105112-3218e080-a479-11e9-9ccc-7e66bd0e9e38.png) **After click in link:** ![Screenshot 2019-07-11 at 13 56 14](https://user-images.githubusercontent.com/39232096/61049786-a4d87c00-a3e5-11e9-9f4a-765e3bf33aa6.png) ![Screenshot 2019-07-11 at 13 56 23](https://user-images.githubusercontent.com/39232096/61049787-a4d87c00-a3e5-11e9-906c-82a097c751d0.png) Commits ------- 9f57d20 Add routing and grid config 64a90b6 Add RedirectToOrderShowAction service and twig
2 parents 486684b + 64a90b6 commit abaa3da

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

src/Resources/config/admin_routing.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ sylius_refund_admin_credit_memo_send:
7474
methods: [GET]
7575
defaults:
7676
_controller: Sylius\RefundPlugin\Action\Admin\SendCreditMemoAction
77+
78+
sylius_refund_admin_order_show_by_number:
79+
path: /orders/by-number/{number}
80+
methods: [GET]
81+
defaults:
82+
_controller: Sylius\RefundPlugin\Ui\RedirectToOrderShowAction
83+
_sylius:
84+
section: admin
85+
permission: true
86+
alias: refund_plugin

src/Resources/config/app/config.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ sylius_grid:
6363
label: sylius.ui.number
6464
sortable: ~
6565
orderNumber:
66-
type: string
67-
label: sylius_refund.ui.order_number
66+
type: twig
67+
label: sylius.ui.order
68+
sortable: ~
69+
options:
70+
template: "@SyliusRefundPlugin/Order/Grid/Field/number.html.twig"
6871
channel:
6972
type: twig
7073
label: sylius.ui.channel

src/Resources/config/services.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
<argument type="service" id="sylius.manager.order" />
7676
</service>
7777

78+
<service id="Sylius\RefundPlugin\Ui\RedirectToOrderShowAction">
79+
<argument type="service" id="router" />
80+
<argument type="service" id="sylius.repository.order" />
81+
</service>
82+
7883
<service id="Sylius\RefundPlugin\Checker\OrderFullyRefundedTotalChecker">
7984
<argument type="service" id="Sylius\RefundPlugin\Provider\OrderRefundedTotalProvider" />
8085
</service>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href="{{ path('sylius_refund_admin_order_show_by_number', {'number': data}) }}">#{{ data }}</a>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
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\RefundPlugin\Ui;
15+
16+
use Sylius\Component\Core\Model\OrderInterface;
17+
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
18+
use Symfony\Component\HttpFoundation\RedirectResponse;
19+
use Symfony\Component\HttpFoundation\Request;
20+
use Symfony\Component\HttpFoundation\Response;
21+
use Symfony\Component\Routing\RouterInterface;
22+
use Webmozart\Assert\Assert;
23+
24+
final class RedirectToOrderShowAction
25+
{
26+
/** @var RouterInterface */
27+
private $router;
28+
29+
/** @var OrderRepositoryInterface */
30+
private $orderRepository;
31+
32+
public function __construct(RouterInterface $router, OrderRepositoryInterface $orderRepository)
33+
{
34+
$this->router = $router;
35+
$this->orderRepository = $orderRepository;
36+
}
37+
38+
public function __invoke(Request $request): Response
39+
{
40+
$number = $request->attributes->get('number');
41+
42+
$order = $this->orderRepository->findOneByNumber($number);
43+
Assert::notNull($order);
44+
45+
/** @var OrderInterface $order */
46+
return RedirectResponse::create($this->router->generate(
47+
'sylius_admin_order_show',
48+
['id' => $order->getId()]
49+
));
50+
}
51+
}

0 commit comments

Comments
 (0)