php - How to commission in twig?
793
I have function to payments
public function calculateClientCost(Transaction $transaction)
{
if ($transaction->getPaymentType() == Order::PAYMENT_TYPE_ALTERNATIVE) {
return $this->container->getParameter('commission_alternative_price');
}
if ($transaction->getPaymentType() == Order::PAYMENT_TYPE_PRICE) {
return $transaction->getPrice();
}
}
public function calculateCommission(Transaction $transaction)
{
if ($transaction->getPaymentType() == Order::PAYMENT_TYPE_ALTERNATIVE) {
return $this->container->getParameter('commission_alternative_price');
}
if ($transaction->getPaymentType() == Order::PAYMENT_TYPE_PRICE) {
return round($this->container->getParameter('commission_publisher') * $transaction->getPrice() / 100, 2);
}
}
and there is a problem i want to use the function in my twig. My twig looks like
<span class="rab_mobile">{{ 'table.head.net_price'|trans }}:</span>
{% if t.isNormalPrice() %}
{{ t.price|localizedcurrency(currency) }}
{% else %}
<em>{{ t.alternativePayment|slice(0,15) }}</em>
{% endif %}
I want to add commission in twig. Can anyone suggest me how I can do this? Thanks in Advance.
Answer
Solution:
If you want to use a php function in Twig, you might need to create a new extension.
And then, in Twig
I used this in Symfony 4 and my class was automatically registered as service and could be used as is.
Assuming you're using Twig with Symfony, you can read the documentation for more informations.