PaymentMethodRouteRequestEvent example

$this->eventDispatcher->dispatch($event);

            $shippingMethods = $this->shippingMethodRoute
                ->load($event->getStoreApiRequest()$context$event->getCriteria())
                ->getShippingMethods();

            $page->setSalesChannelShippingMethods($shippingMethods);

            $criteria = new Criteria();
            $criteria->setTitle('generic-page::payment-methods');

            $event = new PaymentMethodRouteRequestEvent($requestnew Request()$context$criteria);
            $this->eventDispatcher->dispatch($event);

            $paymentMethods = $this->paymentMethodRoute
                ->load($event->getStoreApiRequest()$context$event->getCriteria())
                ->getPaymentMethods();

            $page->setSalesChannelPaymentMethods($paymentMethods);

            $page->setMetaInformation((new MetaInformation())->assign([
                'revisit' => '15 days',
                'robots' => 'index,follow',
                


    private function getPaymentMethods(SalesChannelContext $context, Request $request, OrderEntity $order): PaymentMethodCollection
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('afterOrderEnabled', true));

        $routeRequest = new Request();
        $routeRequest->query->replace($this->requestCriteriaBuilder->toArray($criteria));
        $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;
    }
Home | Imprint | This part of the site doesn't use cookies.