vendor/shopware/core/Checkout/Payment/SalesChannel/PaymentMethodRoute.php line 43

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Payment\SalesChannel;
  3. use Shopware\Core\Checkout\Payment\PaymentMethodCollection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  7. use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
  8. use Shopware\Core\Framework\Routing\Annotation\Entity;
  9. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  10. use Shopware\Core\Framework\Routing\Annotation\Since;
  11. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  12. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. /**
  16.  * @Route(defaults={"_routeScope"={"store-api"}})
  17.  */
  18. class PaymentMethodRoute extends AbstractPaymentMethodRoute
  19. {
  20.     private SalesChannelRepositoryInterface $paymentMethodsRepository;
  21.     /**
  22.      * @internal
  23.      */
  24.     public function __construct(SalesChannelRepositoryInterface $paymentMethodsRepository)
  25.     {
  26.         $this->paymentMethodsRepository $paymentMethodsRepository;
  27.     }
  28.     public function getDecorated(): AbstractPaymentMethodRoute
  29.     {
  30.         throw new DecorationPatternException(self::class);
  31.     }
  32.     /**
  33.      * @Since("6.2.0.0")
  34.      * @Entity("payment_method")
  35.      * @Route("/store-api/payment-method", name="store-api.payment.method", methods={"GET", "POST"})
  36.      */
  37.     public function load(Request $requestSalesChannelContext $contextCriteria $criteria): PaymentMethodRouteResponse
  38.     {
  39.         $criteria
  40.             ->addFilter(new EqualsFilter('active'true))
  41.             ->addSorting(new FieldSorting('position'))
  42.             ->addAssociation('media');
  43.         $result $this->paymentMethodsRepository->search($criteria$context);
  44.         /** @var PaymentMethodCollection $paymentMethods */
  45.         $paymentMethods $result->getEntities();
  46.         if ($request->query->getBoolean('onlyAvailable') || $request->request->getBoolean('onlyAvailable')) {
  47.             $paymentMethods $paymentMethods->filterByActiveRules($context);
  48.         }
  49.         $result->assign(['entities' => $paymentMethods'elements' => $paymentMethods'total' => $paymentMethods->count()]);
  50.         return new PaymentMethodRouteResponse($result);
  51.     }
  52. }