From 3fe977b81b921dbc846944770b35262edff670a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pysiak?= Date: Thu, 5 Dec 2024 12:57:07 +0100 Subject: [PATCH] Remove partials, add components --- config/admin_routing.yml | 11 ----- config/app/twig_hooks/admin/order/show.yaml | 5 ++- .../twig_hooks/shop/account/order/show.yaml | 7 +++- config/services/twig_components.xml | 32 +++++++++++++++ config/shop_routing.yml | 11 ----- src/Doctrine/ORM/CreditMemoRepository.php | 2 +- .../CreditMemoRepositoryInterface.php | 2 +- .../Component/OrderCreditMemosComponent.php | 41 +++++++++++++++++++ templates/shop/order/_creditMemos.html.twig | 25 ----------- templates/shop/order/credit_memos.html.twig | 28 +++++++++++-- 10 files changed, 109 insertions(+), 55 deletions(-) create mode 100644 config/services/twig_components.xml create mode 100644 src/Twig/Component/OrderCreditMemosComponent.php delete mode 100644 templates/shop/order/_creditMemos.html.twig diff --git a/config/admin_routing.yml b/config/admin_routing.yml index 810f1a203..e97bdc26a 100644 --- a/config/admin_routing.yml +++ b/config/admin_routing.yml @@ -24,17 +24,6 @@ sylius_refund_credit_memo: icon: inbox type: sylius.resource -sylius_refund_order_credit_memos_list: - path: /orders/{orderId}/credit-memos - methods: [GET] - defaults: - _controller: sylius_refund.controller.credit_memo::indexAction - _sylius: - template: "@SyliusRefundPlugin/admin/order/credit_memo/list.html.twig" - repository: - method: findByOrderId - arguments: $orderId - sylius_refund_credit_memo_details: path: /orders/{orderNumber}/credit-memos/{id} methods: [GET] diff --git a/config/app/twig_hooks/admin/order/show.yaml b/config/app/twig_hooks/admin/order/show.yaml index e468764f9..92a778efe 100644 --- a/config/app/twig_hooks/admin/order/show.yaml +++ b/config/app/twig_hooks/admin/order/show.yaml @@ -51,7 +51,10 @@ sylius_twig_hooks: template: '@SyliusRefundPlugin/admin/order/content/sections/credit_memos/header.html.twig' priority: 100 items: - template: '@SyliusRefundPlugin/admin/order/content/sections/credit_memos/items.html.twig' + component: 'sylius_refund:admin:credit_memos' + props: + order: '@=_context.order' + template: '@SyliusRefundPlugin/admin/order/credit_memo/list.html.twig' priority: 0 'sylius_admin.order.show.content.sections.credit_memos.header': diff --git a/config/app/twig_hooks/shop/account/order/show.yaml b/config/app/twig_hooks/shop/account/order/show.yaml index 6d5e33725..329c181a9 100644 --- a/config/app/twig_hooks/shop/account/order/show.yaml +++ b/config/app/twig_hooks/shop/account/order/show.yaml @@ -1,8 +1,11 @@ sylius_twig_hooks: hooks: 'sylius_shop.account.order.show.content.main': - credit_memos: #TODO: Change this to twig component - template: '@SyliusRefundPlugin/shop/order/credit_memos.html.twig' + credit_memos: + component: 'sylius_refund:account:credit_memos' + props: + order: '@=_context.order' + template: '@SyliusRefundPlugin/shop/order/credit_memos.html.twig' priority: -100 'sylius_shop.account.order.show.content.main.credit_memos': diff --git a/config/services/twig_components.xml b/config/services/twig_components.xml new file mode 100644 index 000000000..0e776f18b --- /dev/null +++ b/config/services/twig_components.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/config/shop_routing.yml b/config/shop_routing.yml index 18d796fb6..6dbfd3795 100644 --- a/config/shop_routing.yml +++ b/config/shop_routing.yml @@ -1,14 +1,3 @@ -sylius_refund_plugin_shop_order_credit_memos_partial: - path: /_partial/orders/{orderId}/credit-memos/ - methods: [GET] - defaults: - _controller: sylius_refund.controller.credit_memo::indexAction - _sylius: - template: "@SyliusRefundPlugin/shop/order/_creditMemos.html.twig" - repository: - method: findByOrder - arguments: $orderId - sylius_refund_shop_credit_memo_download: path: /credit-memos/{id}/download methods: [GET] diff --git a/src/Doctrine/ORM/CreditMemoRepository.php b/src/Doctrine/ORM/CreditMemoRepository.php index 2e776ad33..3371a5db1 100644 --- a/src/Doctrine/ORM/CreditMemoRepository.php +++ b/src/Doctrine/ORM/CreditMemoRepository.php @@ -18,7 +18,7 @@ class CreditMemoRepository extends EntityRepository implements CreditMemoRepositoryInterface { - public function findByOrderId(string $orderId): array + public function findByOrderId(int $orderId): array { return $this->createQueryBuilder('o') ->andWhere('o.order = :orderId') diff --git a/src/Repository/CreditMemoRepositoryInterface.php b/src/Repository/CreditMemoRepositoryInterface.php index d16d2570e..c5951ecd2 100644 --- a/src/Repository/CreditMemoRepositoryInterface.php +++ b/src/Repository/CreditMemoRepositoryInterface.php @@ -19,5 +19,5 @@ interface CreditMemoRepositoryInterface extends RepositoryInterface { /** @return CreditMemoInterface[] */ - public function findByOrderId(string $orderId): array; + public function findByOrderId(int $orderId): array; } diff --git a/src/Twig/Component/OrderCreditMemosComponent.php b/src/Twig/Component/OrderCreditMemosComponent.php new file mode 100644 index 000000000..f880cd542 --- /dev/null +++ b/src/Twig/Component/OrderCreditMemosComponent.php @@ -0,0 +1,41 @@ + */ + #[ExposeInTemplate(name: 'credit_memos')] + public function getCreditMemosForOrder(): array + { + if ($this->order === null || $this->order->getId() === null) { + return []; + } + + return $this->creditMemoRepository->findByOrderId($this->order->getId()); + } +} diff --git a/templates/shop/order/_creditMemos.html.twig b/templates/shop/order/_creditMemos.html.twig deleted file mode 100644 index 3bb4c5398..000000000 --- a/templates/shop/order/_creditMemos.html.twig +++ /dev/null @@ -1,25 +0,0 @@ -{% if credit_memos|length > 0 %} -
-
{{ 'sylius_refund.ui.credit_memos'|trans }}
-
- - - {% for credit_memo in credit_memos %} - - - - - - {% endfor %} - -
-
- {{ credit_memo.issuedAt|date('d-m-Y') }} - {{ credit_memo.number }} -
-
{{ credit_memo.total|sylius_format_money(credit_memo.currencyCode, credit_memo.localeCode) }} - {% hook 'sylius_shop.account.order.show.content.main.credit_memos' %} -
-
-
-{% endif %} diff --git a/templates/shop/order/credit_memos.html.twig b/templates/shop/order/credit_memos.html.twig index 1ba29eb27..3bb4c5398 100644 --- a/templates/shop/order/credit_memos.html.twig +++ b/templates/shop/order/credit_memos.html.twig @@ -1,3 +1,25 @@ -{% set order = hookable_metadata.context.order %} - -{{ render(url('sylius_refund_plugin_shop_order_credit_memos_partial', {'orderId': order.id})) }} +{% if credit_memos|length > 0 %} +
+
{{ 'sylius_refund.ui.credit_memos'|trans }}
+
+ + + {% for credit_memo in credit_memos %} + + + + + + {% endfor %} + +
+
+ {{ credit_memo.issuedAt|date('d-m-Y') }} + {{ credit_memo.number }} +
+
{{ credit_memo.total|sylius_format_money(credit_memo.currencyCode, credit_memo.localeCode) }} + {% hook 'sylius_shop.account.order.show.content.main.credit_memos' %} +
+
+
+{% endif %}