sortPaymentMethodsByPreference example

$routeRequest->query->set('onlyAvailable', '1');

        $event = new PaymentMethodRouteRequestEvent($request$routeRequest$context$criteria);
        $this->eventDispatcher->dispatch($event);

        $paymentMethods = $this->paymentMethodRoute->load(
            $event->getStoreApiRequest(),
            $this->orderConverter->assembleSalesChannelContext($order$context->getContext()),
            $event->getCriteria()
        )->getPaymentMethods();

        $paymentMethods->sortPaymentMethodsByPreference($context);

        return $paymentMethods;
    }

    private function isOrderPaid(OrderEntity $order): bool
    {
        $transactions = $order->getTransactions();

        if ($transactions === null) {
            return false;
        }

        
public function getDecorated(): AbstractPaymentMethodRoute
    {
        return $this->decorated;
    }

    #[Route(path: '/store-api/payment-method', name: 'store-api.payment.method', methods: ['GET', 'POST'], defaults: ['_entity' => 'payment_method'])]     public function load(Request $request, SalesChannelContext $context, Criteria $criteria): PaymentMethodRouteResponse
    {
        $response = $this->getDecorated()->load($request$context$criteria);

        $response->getPaymentMethods()->sortPaymentMethodsByPreference($context);

        $this->scriptExecutor->execute(new PaymentMethodRouteHook(
            $response->getPaymentMethods(),
            $request->query->getBoolean('onlyAvailable') || $request->request->getBoolean('onlyAvailable'),
            $context
        ));

        return $response;
    }
}
Home | Imprint | This part of the site doesn't use cookies.