Skip to content

Commit a8712fc

Browse files
committed
Show sandbox only when enabled, the same with production
1 parent edf0bc9 commit a8712fc

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
</service>
319319

320320
<service id="sylius_paypal.twig.extension.paypal" class="Sylius\PayPalPlugin\Twig\PayPalExtension">
321+
<argument>%sylius_paypal.sandbox%</argument>
321322
<tag name="twig.extension" />
322323
</service>
323324

src/Twig/PayPalExtension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,23 @@
2121

2222
final class PayPalExtension extends AbstractExtension
2323
{
24+
public function __construct(private readonly bool $sandbox)
25+
{
26+
}
27+
2428
public function getFunctions(): array
2529
{
2630
return [
2731
new TwigFunction('sylius_is_paypal_enabled', [$this, 'isPayPalEnabled']),
32+
new TwigFunction('sylius_is_paypal_sandbox', [$this, 'isSandbox']),
2833
];
2934
}
3035

36+
public function isSandbox(): bool
37+
{
38+
return $this->sandbox;
39+
}
40+
3141
public function isPayPalEnabled(iterable $paymentMethods): bool
3242
{
3343
/** @var PaymentMethodInterface $paymentMethod */

templates/admin/payment_method/grid/action/enable_paypal.html.twig

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
{{ 'sylius_paypal.enable_paypal'|trans }}
66
</button>
77
<ul class="dropdown-menu">
8-
<li>
9-
<a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#confirmation-modal-create-pay-pal">
10-
{{ ux_icon('tabler:brand-paypal-filled') }}
11-
{{ 'sylius_paypal.enable_paypal_production'|trans }}
12-
</a>
13-
</li>
14-
<li>
15-
<a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#confirmation-modal-create-paypal-sandbox">
16-
{{ ux_icon('tabler:flask') }}
17-
{{ 'sylius_paypal.enable_paypal_sandbox'|trans }}
18-
</a>
19-
</li>
8+
{% if sylius_is_paypal_sandbox() %}
9+
<li>
10+
<a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#confirmation-modal-create-paypal-sandbox">
11+
{{ ux_icon('tabler:flask') }}
12+
{{ 'sylius_paypal.enable_paypal_sandbox'|trans }}
13+
</a>
14+
</li>
15+
{% else %}
16+
<li>
17+
<a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#confirmation-modal-create-pay-pal">
18+
{{ ux_icon('tabler:brand-paypal-filled') }}
19+
{{ 'sylius_paypal.enable_paypal_production'|trans }}
20+
</a>
21+
</li>
22+
{% endif %}
2023
</ul>
2124
</div>
2225
{% endif %}

0 commit comments

Comments
 (0)