src/Sylius/Bundle/ShopBundle/Twig/OrderTaxesTotalExtension.php line 24

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ShopBundle\Twig;
  12. use Sylius\Component\Core\Model\AdjustmentInterface;
  13. use Sylius\Component\Core\Model\OrderInterface;
  14. use Sylius\Component\Order\Model\AdjustmentInterface as BaseAdjustmentInterface;
  15. use Twig\Extension\AbstractExtension;
  16. use Twig\TwigFunction;
  17. @trigger_error(
  18.     'The "Sylius\Bundle\ShopBundle\Twig\OrderTaxesTotalExtension" class is deprecated since Sylius 1.12 and will be removed in 2.0. Use methods "getTaxExcludedTotal" and "getTaxIncludedTotal" from "Sylius\Component\Core\Model\Order" instead.',
  19.     \E_USER_DEPRECATED,
  20. );
  21. class OrderTaxesTotalExtension extends AbstractExtension
  22. {
  23.     public function getFunctions(): array
  24.     {
  25.         return [
  26.             new TwigFunction('sylius_order_tax_included', [$this'getIncludedTax']),
  27.             new TwigFunction('sylius_order_tax_excluded', [$this'getExcludedTax']),
  28.         ];
  29.     }
  30.     public function getIncludedTax(OrderInterface $order): int
  31.     {
  32.         return $this->getAmount($ordertrue);
  33.     }
  34.     public function getExcludedTax(OrderInterface $order): int
  35.     {
  36.         return $this->getAmount($orderfalse);
  37.     }
  38.     private function getAmount(OrderInterface $orderbool $isNeutral): int
  39.     {
  40.         return array_reduce(
  41.             $order->getAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->toArray(),
  42.             static fn (int $totalBaseAdjustmentInterface $adjustment) => $isNeutral === $adjustment->isNeutral() ? $total $adjustment->getAmount() : $total,
  43.             0,
  44.         );
  45.     }
  46. }