assembleSalesChannelContext example

/** * @phpstan-ignore-next-line setter name is misleading, but kept for BC */
    #[Route(path: '/store-api/order/payment', name: 'store-api.order.set-payment', methods: ['POST'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])]     public function setPayment(Request $request, SalesChannelContext $context): SetPaymentOrderRouteResponse
    {
        $paymentMethodId = (string) $request->request->get('paymentMethodId');

        $orderId = (string) $request->request->get('orderId');
        $order = $this->loadOrder($orderId$context);

        $context = $this->orderConverter->assembleSalesChannelContext(
            $order,
            $context->getContext(),
            [SalesChannelContextService::PAYMENT_METHOD_ID => $paymentMethodId]
        );

        $this->validateRequest($context$paymentMethodId);

        $this->validatePaymentState($order);

        $this->setPaymentMethod($paymentMethodId$order$context);

        
$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;
    }

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

        


    #[Route(path: '/payment/finalize-transaction', name: 'payment.finalize.transaction', methods: ['GET', 'POST'])]     public function finalizeTransaction(Request $request): Response
    {
        $paymentToken = $request->get('_sw_payment_token');

        if ($paymentToken === null) {
            throw RoutingException::missingRequestParameter('_sw_payment_token');
        }

        $salesChannelContext = $this->assembleSalesChannelContext($paymentToken);

        $result = $this->paymentService->finalizeTransaction(
            $paymentToken,
            $request,
            $salesChannelContext
        );

        $response = $this->handleException($result);
        if ($response !== null) {
            return $response;
        }

        
if (!Feature::isActive('v6.6.0.0')) {
                throw new InvalidOrderException($orderId);
            }

            throw CartException::orderNotFound($orderId);
        }

        $convertedCart = $this->orderConverter->convertToCart($order$context);

        $this->cartPersister->save(
            $convertedCart,
            $this->orderConverter->assembleSalesChannelContext($order$context)
        );

        return new JsonResponse(['token' => $convertedCart->getToken()]);
    }
}
public function reset(): void
    {
        $this->scopes = [];
    }

    public function build(OrderEntity $order, Context $context): FlowRuleScope
    {
        if (\array_key_exists($order->getId()$this->scopes)) {
            return $this->scopes[$order->getId()];
        }

        $context = $this->orderConverter->assembleSalesChannelContext($order$context);
        $cart = $this->orderConverter->convertToCart($order$context->getContext());
        $behavior = new CartBehavior($context->getPermissions());

        foreach ($this->collectors as $collector) {
            $collector->collect($cart->getData()$cart$context$behavior);
        }

        $cart->setDeliveries(
            $this->deliveryBuilder->build($cart$cart->getData()$context$behavior)
        );

        
static::assertSame($this->cashRoundingConfig, $input);
                });
                $salesChannelContext->method('setRuleIds')->willReturnCallback(function D$input): void {
                    static::assertSame(['order-rule-id-1', 'order-rule-id-2']$input);
                });

                return $salesChannelContext;
            }
        );

        $orderEntity = $this->getOrder($manipulateOrder);
        $orderConverter->assembleSalesChannelContext($orderEntity, Context::createDefaultContext());
    }

    /** * @return array<mixed> */
    public static function assembleSalesChannelContextData(): array
    {
        return [
            [
                OrderException::class,
                'order-no-transactions',
            ],

    public function recalculateOrder(string $orderId, Context $context): void
    {
        $order = $this->fetchOrder($orderId$context);

        $this->validateOrder($order$orderId);
        \assert($order instanceof OrderEntity);

        $salesChannelContext = $this->orderConverter->assembleSalesChannelContext($order$context);
        $cart = $this->orderConverter->convertToCart($order$context);
        $recalculatedCart = $this->recalculateCart($cart$salesChannelContext);

        $conversionContext = (new OrderConversionContext())
            ->setIncludeCustomer(false)
            ->setIncludeBillingAddress(false)
            ->setIncludeDeliveries(true)
            ->setIncludeTransactions(false)
            ->setIncludeOrderDate(false);

        $orderData = $this->orderConverter->convertToOrder($recalculatedCart$salesChannelContext$conversionContext);
        
Home | Imprint | This part of the site doesn't use cookies.