Skip to content

Commit

Permalink
style #309 Order refund admin show rebuild (Tomanhez)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

New:
<img width="1164" alt="Screenshot 2021-06-10 at 15 05 05" src="https://user-images.githubusercontent.com/39232096/121530130-64cd0a00-c9fd-11eb-9ff5-bae81823376c.png">



Commits
-------

14857c3 Add new and remove redundant templates
7c50eb6 Add new method in OrderRefundsExtension
2467d2b Update new service confirutations
  • Loading branch information
GSadee authored Jun 11, 2021
2 parents 69d43d2 + 2467d2b commit 68ecef0
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 111 deletions.
31 changes: 0 additions & 31 deletions src/Doctrine/ORM/RefundPaymentRepository.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Repository/RefundPaymentRepositoryInterface.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Resources/config/admin_routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ sylius_refund_admin_credit_memo_download:
defaults:
_controller: Sylius\RefundPlugin\Action\Admin\DownloadCreditMemoAction

sylius_refund_order_refund_payment_list:
path: /orders/{orderNumber}/refund-payments
methods: [GET]
defaults:
_controller: sylius_refund.controller.refund_payment:indexAction
_sylius:
template: "@SyliusRefundPlugin/Order/Admin/RefundPayment/list.html.twig"
repository:
method: findByOrderNumber
arguments: $orderNumber

sylius_refund_complete_refund_payment:
path: /orders/{orderNumber}/refund-payments/{id}/complete
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ sylius_resource:
sylius_refund.refund_payment:
classes:
model: Sylius\RefundPlugin\Entity\RefundPayment
repository: Sylius\RefundPlugin\Doctrine\ORM\RefundPaymentRepository

sylius_mailer:
emails:
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<argument type="service" id="Sylius\RefundPlugin\Provider\UnitRefundedTotalProviderInterface" />
<argument type="service" id="Sylius\RefundPlugin\Checker\UnitRefundingAvailabilityCheckerInterface" />
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius_refund.repository.refund_payment" />
<tag name="twig.extension"/>
</service>

Expand Down
5 changes: 0 additions & 5 deletions src/Resources/config/services/listeners.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,5 @@
<argument>@SyliusRefundPlugin/Order/Admin/creditMemos.html.twig</argument>
<tag name="kernel.event_listener" event="sonata.block.event.sylius.admin.order.show.after_summary" method="onBlockEvent" />
</service>

<service id="sylius_refund_plugin.block_event_listener.order_show.refund_payments" class="Sylius\Bundle\UiBundle\Block\BlockEventListener">
<argument>@SyliusRefundPlugin/Order/Admin/refundPayments.html.twig</argument>
<tag name="kernel.event_listener" event="sonata.block.event.sylius.admin.order.show.after_summary" method="onBlockEvent" />
</service>
</services>
</container>
33 changes: 0 additions & 33 deletions src/Resources/views/Order/Admin/RefundPayment/list.html.twig

This file was deleted.

31 changes: 31 additions & 0 deletions src/Resources/views/Order/Admin/_refundPayments.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% import '@SyliusAdmin/Common/Macro/money.html.twig' as money %}
{% set refund_payments = get_all_refund_payments_by_order(order) %}
{% if refund_payments|length > 0 %}
{% include '@SyliusAdmin/Order/Label/PaymentState/' ~ order.paymentState ~ '.html.twig' with { 'value': 'sylius.ui.' ~ order.paymentState, 'attached': true } %}
<h3 class="ui dividing header">{{ 'sylius_refund.ui.refund_payments'|trans }}</h3>
<div class="ui relaxed divided list">
{% for refund_payment in refund_payments %}
<div class="item" {{ sylius_test_html_attribute('refund') }}>
<div class="right floated content" {{ sylius_test_html_attribute('refund-status') }}>
{% include '@SyliusRefundPlugin/Common/Label/refundPaymentState.html.twig' with {'data': refund_payment.state} %}
</div>
<i class="large payment icon"></i>
<div class="content">
<div class="header">
{{ refund_payment.paymentMethod }}
</div>
<div class="description">
{{ money.format(refund_payment.amount, refund_payment.currencyCode) }}
</div>
</div>
{% if sm_can(refund_payment, 'complete', 'sylius_refund_refund_payment') %}
<div class="ui segment">
<form action="{{ path('sylius_refund_complete_refund_payment', {'orderNumber': refund_payment.orderNumber, 'id': refund_payment.id}) }}" method="POST" {{ sylius_test_html_attribute('refund-button') }}>
<button type="submit" class="ui icon labeled tiny blue fluid loadable button"><i class="check icon"></i> {{ 'sylius.ui.complete'|trans }}</button>
</form>
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}
1 change: 0 additions & 1 deletion src/Resources/views/Order/Admin/refundPayments.html.twig

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% import '@SyliusAdmin/Common/Macro/money.html.twig' as money %}

{% if order.hasPayments %}
<div class="ui segment" id="payment-state">
{% include '@SyliusAdmin/Order/Label/PaymentState/' ~ order.paymentState ~ '.html.twig' with { 'value': 'sylius.ui.' ~ order.paymentState, 'attached': true } %}
<h3 class="ui dividing header">{{ 'sylius.ui.payments'|trans }}</h3>
<div class="ui relaxed divided list" id="sylius-payments">
{% for payment in order.payments %}
{% include '@SyliusAdmin/Order/Show/_payment.html.twig' %}
{% endfor %}
</div>
{% include '@SyliusRefundPlugin/Order/Admin/_refundPayments.html.twig' %}
</div>
{% else %}
<div class="ui segment center aligned" id="no-payments">
<span class="ui grey large label">
<i class="ban icon"></i> {{ 'sylius.ui.no_payments'|trans }}
</span>
</div>
{% endif %}
26 changes: 21 additions & 5 deletions src/Twig/OrderRefundsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Checker\UnitRefundingAvailabilityCheckerInterface;
use Sylius\RefundPlugin\Model\RefundType;
use Sylius\RefundPlugin\Provider\OrderRefundedTotalProviderInterface;
use Sylius\RefundPlugin\Provider\UnitRefundedTotalProviderInterface;
use Twig\TwigFunction;

final class OrderRefundsExtension extends \Twig_Extension
{
Expand All @@ -34,37 +36,46 @@ final class OrderRefundsExtension extends \Twig_Extension
/** @var OrderRepositoryInterface */
private $orderRepository;

/** @var RepositoryInterface */
private $refundPaymentRepository;

public function __construct(
OrderRefundedTotalProviderInterface $orderRefundedTotalProvider,
UnitRefundedTotalProviderInterface $unitRefundedTotalProvider,
UnitRefundingAvailabilityCheckerInterface $unitRefundingAvailabilityChecker,
OrderRepositoryInterface $orderRepository
OrderRepositoryInterface $orderRepository,
RepositoryInterface $refundPaymentRepository
) {
$this->orderRefundedTotalProvider = $orderRefundedTotalProvider;
$this->unitRefundedTotalProvider = $unitRefundedTotalProvider;
$this->unitRefundingAvailabilityChecker = $unitRefundingAvailabilityChecker;
$this->orderRepository = $orderRepository;
$this->refundPaymentRepository = $refundPaymentRepository;
}

public function getFunctions(): array
{
return [
new \Twig_Function(
new TwigFunction(
'order_refunded_total',
[$this, 'getRefundedTotal']
),
new \Twig_Function(
new TwigFunction(
'unit_refunded_total',
[$this, 'getUnitRefundedTotal']
),
new \Twig_Function(
new TwigFunction(
'can_unit_be_refunded',
[$this, 'canUnitBeRefunded']
),
new \Twig_Function(
new TwigFunction(
'unit_refund_left',
[$this, 'getUnitRefundLeft']
),
new TwigFunction(
'get_all_refund_payments_by_order',
[$this, 'getAllRefundPaymentsByOrder']
)
];
}

Expand All @@ -90,4 +101,9 @@ public function getRefundedTotal(string $orderNumber): int

return ($this->orderRefundedTotalProvider)($order);
}

public function getAllRefundPaymentsByOrder(OrderInterface $order): array
{
return $this->refundPaymentRepository->findBy(['order' => $order]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% if order.hasPayments %}
<div class="ui segment" id="payment-state">
{% include '@SyliusAdmin/Order/Label/PaymentState/' ~ order.paymentState ~ '.html.twig' with { 'value': 'sylius.ui.' ~ order.paymentState, 'attached': true } %}
<h3 class="ui dividing header">{{ 'sylius.ui.payments'|trans }}</h3>
<div class="ui relaxed divided list" id="sylius-payments">
{% for payment in order.payments %}
{% include '@SyliusAdmin/Order/Show/_payment.html.twig' %}
{% endfor %}
</div>
{% include '@SyliusRefundPlugin/Order/Admin/_refundPayments.html.twig' %}
</div>
{% else %}
<div class="ui segment center aligned" id="no-payments">
<span class="ui grey large label">
<i class="ban icon"></i> {{ 'sylius.ui.no_payments'|trans }}
</span>
</div>
{% endif %}
8 changes: 4 additions & 4 deletions tests/Behat/Page/Admin/Order/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public function hasRefundsButton(): bool

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

$refundPaymentsWithStatus = 0;
/** @var NodeElement $refundPayment */
foreach ($refundPayments as $refundPayment) {
if (strpos($refundPayment->getText(), $status)) {
if ($refundPayment->getText() === $status) {
$refundPaymentsWithStatus++;
}
}
Expand All @@ -49,7 +49,7 @@ public function hasRefundPaymentsWithStatus(int $count, string $status): bool

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

/** @var NodeElement $refundPayment */
$refundPayment = $refundPayments[$number];
Expand All @@ -59,7 +59,7 @@ public function completeRefundPayment(int $number): void

public function canCompleteRefundPayment(int $number): bool
{
$refundPayments = $this->getDocument()->findAll('css', '#refund-payments tbody tr');
$refundPayments = $this->getDocument()->findAll('css', '[data-test-refund]');

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

0 comments on commit 68ecef0

Please sign in to comment.