Skip to content

Commit 7e74e49

Browse files
Remove refunds button if order refunded (#226)
2 parents 046a4ec + 4c73717 commit 7e74e49

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

config/services/menu.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@
3232
<service id="sylius_mollie.menu_listener.mollie_recurring" class="Sylius\MolliePlugin\Menu\MollieRecurringMenuListener">
3333
<tag name="kernel.event_listener" method="buildMenu" event="sylius.menu.admin.main" />
3434
</service>
35+
36+
<service id="sylius_mollie.menu_listener.remove_refunds_button_order_show_menu" class="Sylius\MolliePlugin\Menu\RemoveRefundsButtonOrderShowMenuListener">
37+
<tag name="kernel.event_listener" event="sylius.menu.admin.order.show" method="removeRefundsButton" priority="-100" />
38+
</service>
3539
</services>
3640
</container>

src/Controller/Shop/QrCodeAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function removeQrCodeFromOrder(Request $request): JsonResponse
102102
/** @var OrderInterface $order */
103103
$order = $this->cartContext->getCart();
104104
$orderToken = $request->get('orderToken');
105-
if (null !== $orderToken) {
105+
if (null !== $orderToken && '' !== $orderToken) {
106106
/** @var OrderInterface|null $order */
107107
$order = $this->orderRepository->findOneByTokenValue($orderToken);
108108
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius Mollie Plugin 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\MolliePlugin\Menu;
15+
16+
use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent;
17+
use Sylius\Component\Core\Model\PaymentInterface;
18+
use Sylius\Component\Core\OrderPaymentStates;
19+
use Sylius\MolliePlugin\Entity\OrderInterface;
20+
use Webmozart\Assert\Assert;
21+
22+
final class RemoveRefundsButtonOrderShowMenuListener
23+
{
24+
public function removeRefundsButton(OrderShowMenuBuilderEvent $event): void
25+
{
26+
$menu = $event->getMenu();
27+
28+
if (null === $menu->getChild('refunds')) {
29+
return;
30+
}
31+
32+
$order = $event->getOrder();
33+
Assert::isInstanceOf($order, OrderInterface::class);
34+
35+
if (
36+
OrderPaymentStates::STATE_REFUNDED === $order->getPaymentState() &&
37+
PaymentInterface::STATE_REFUNDED === $order->getLastPayment()->getState()
38+
) {
39+
$menu->removeChild('refunds');
40+
}
41+
}
42+
}

templates/Admin/Order/Show/Payment/_refund.html.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
{% if order.paymentState != constant('Sylius\\Component\\Core\\OrderPaymentStates::STATE_PARTIALLY_REFUNDED') and sm_can(payment, 'refund', 'sylius_payment') and payment.method.gatewayConfig.factoryName == constant('Sylius\\MolliePlugin\\Payum\\Factory\\MollieGatewayFactory::FACTORY_NAME') %}
1+
{% if
2+
order.paymentState != constant('Sylius\\Component\\Core\\OrderPaymentStates::STATE_PARTIALLY_REFUNDED') and
3+
sm_can(order, 'partially_refund', 'sylius_order_payment') and
4+
sm_can(order, 'refund', 'sylius_order_payment') and
5+
sm_can(payment, 'refund', 'sylius_payment') and
6+
payment.method.gatewayConfig.factoryName == constant('Sylius\\MolliePlugin\\Payum\\Factory\\MollieGatewayFactory::FACTORY_NAME')
7+
%}
28
<div class="ui segment">
39
<form action="{{ path('sylius_admin_order_payment_refund', {'orderId': order.id, 'id': payment.id}) }}" method="post" novalidate>
410
<input type="hidden" name="_method" value="PUT">

0 commit comments

Comments
 (0)