Skip to content

Commit

Permalink
Add hooks for refund payments on order
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed Nov 25, 2024
1 parent 36d9fcf commit fd5d520
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 3 deletions.
33 changes: 33 additions & 0 deletions src/Resources/config/app/twig_hooks/admin/order/show.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,36 @@ sylius_twig_hooks:
refunds:
template: '@SyliusRefundPlugin/order/admin/content/header/title_block/actions/refunds.html.twig'
priority: -100

'sylius_admin.order.show.content.sections.payments':
refund_header:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/refund_header.html.twig'
priority: -100
refund_items:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/refund_items.html.twig'
priority: -200

'sylius_admin.order.show.content.sections.payments.refund_header':
title:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/header/title.html.twig'
priority: 100


'sylius_admin.order.show.content.sections.payments.refund_item':
state:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/item/state.html.twig'
priority: 300
name:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/item/name.html.twig'
priority: 200
amount:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/item/amount.html.twig'
priority: 100
actions:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/item/actions.html.twig'
priority: 0

'sylius_admin.order.show.content.sections.payments.refund_item.actions':
complete:
template: '@SyliusRefundPlugin/order/admin/content/sections/payments/item/actions/complete.html.twig'
priority: 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="card-title">
{{ 'sylius_refund.ui.refund_payments'|trans }}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<td class="w-1">
<div class="d-flex gap-1 justify-content-end">
{% hook 'actions' %}
</div>
</td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% set refund_payment = hookable_metadata.context.refund_payment %}

{% if sylius_sm_can(refund_payment, constant('Sylius\\RefundPlugin\\StateResolver\\RefundPaymentTransitions::GRAPH'), constant('Sylius\\RefundPlugin\\StateResolver\\RefundPaymentTransitions::TRANSITION_COMPLETE')) %}
<form action="{{ path('sylius_refund_complete_refund_payment', {'orderNumber': refund_payment.order.number, 'id': refund_payment.id}) }}" method="POST" {{ sylius_test_html_attribute('refund-complete-button') }}>
<button type="submit" class="btn">
{{ ux_icon('tabler:check') }} {{ 'sylius.ui.complete'|trans }}
</button>
</form>
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% import '@SyliusAdmin/shared/helper/money.html.twig' as money %}

{% set refund_payment = hookable_metadata.context.refund_payment %}

<td class="py-2 text-end" {{ sylius_test_html_attribute('refund-payment-amount') }}>
<strong>{{ money.format(refund_payment.amount, refund_payment.currencyCode) }}</strong>
</td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% set refund_payment = hookable_metadata.context.refund_payment %}

<td class="py-2">
<strong {{ sylius_test_html_attribute('refundd-payment-method') }}>{{ refund_payment.paymentMethod }}</strong>
</td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% from '@SyliusAdmin/order/macro/order_payment_state_label.html.twig' import label %}

{% set refund_payment = hookable_metadata.context.refund_payment %}

<td class="w-1" {{ sylius_test_html_attribute('refund-state') }}>
{{ label(refund_payment.state) }}
</td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="card-header">
{% hook 'refund_header' %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% set order = hookable_metadata.context.resource %}
{% set refund_payments = get_all_refund_payments_by_order(order) %}

<div class="py-3">
{% if order.hasPayments %}
<div class="table-responsive">
<table class="table table-vcenter table-borderless table-sm card-table">
<tbody>
{% for refund_payment in refund_payments %}
<tr {{ sylius_test_html_attribute('refund') }}>
{% hook 'refund_item' with { resource: order, refund_payment } %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<span class="px-3 text-secondary italic" {{ sylius_test_html_attribute('no-payments') }}>{{ 'sylius.ui.no_payments'|trans }}</span>
{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{% set unit = hookable_metadata.context.unit %}

<td class="aligned collapsing">
<button data-refund="{{ unit_refund_left(unit.id, constant('Sylius\\RefundPlugin\\Model\\RefundType::ORDER_ITEM_UNIT'), unit.total) }}" type="button" class="ui button primary" {% if not can_unit_be_refunded(unit.id, constant('Sylius\\RefundPlugin\\Model\\RefundType::ORDER_ITEM_UNIT')) %}disabled{% endif %}>
<button
data-refund="{{ unit_refund_left(unit.id, constant('Sylius\\RefundPlugin\\Model\\RefundType::ORDER_ITEM_UNIT'), unit.total) }}"
type="button"
class="btn"
{% if not can_unit_be_refunded(unit.id, constant('Sylius\\RefundPlugin\\Model\\RefundType::ORDER_ITEM_UNIT')) %}disabled{% endif %}
{{ sylius_test_html_attribute('refund-item-button') }}
>
{{ ux_icon('tabler:truck') }}
{{ 'sylius_refund.ui.refund'|trans }}
</button>
</td>
4 changes: 2 additions & 2 deletions tests/Behat/Page/Admin/Order/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function hasRefundsButton(): bool

public function hasRefundPaymentsWithStatus(int $count, string $status): bool
{
$refundPayments = $this->getDocument()->findAll('css', '[data-test-refund-status]');
$refundPayments = $this->getDocument()->findAll('css', '[data-test-refund-state]');

$refundPaymentsWithStatus = 0;
/** @var NodeElement $refundPayment */
Expand All @@ -57,7 +57,7 @@ public function hasRefundPaymentsWithStatus(int $count, string $status): bool

public function completeRefundPayment(int $number): void
{
$refundPayments = $this->getDocument()->findAll('css', '[data-test-refund-button]');
$refundPayments = $this->getDocument()->findAll('css', '[data-test-refund-complete-button]');

/** @var NodeElement $refundPayment */
$refundPayment = $refundPayments[$number];
Expand Down

0 comments on commit fd5d520

Please sign in to comment.