InvalidOrderException example

->addAssociation('transactions.stateMachineState')
            ->addAssociation('deliveries.shippingMethod')
            ->addAssociation('deliveries.positions.orderLineItem')
            ->addAssociation('deliveries.shippingOrderAddress.country')
            ->addAssociation('deliveries.shippingOrderAddress.countryState');

        /** @var OrderEntity|null $order */
        $order = $this->orderRepository->search($criteria$context)->get($orderId);

        if (!$order) {
            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)
        );

        
$invoiceNumber = (string) $operation->getConfig()['custom']['invoiceNumber'];
            $operation->setReferencedDocumentId($this->getReferenceId($operation->getOrderId()$invoiceNumber));
        }

        $rendered = $this->rendererRegistry->render($documentType[$operation->getOrderId() => $operation]$context$config);

        if (!\array_key_exists($operation->getOrderId()$rendered->getSuccess())) {
            if (Feature::isActive('v6.6.0.0')) {
                throw DocumentException::generationError();
            }

            throw new InvalidOrderException($operation->getOrderId());
        }

        $document = $rendered->getSuccess()[$operation->getOrderId()];

        if (!($document instanceof RenderedDocument)) {
            throw DocumentException::generationError();
        }

        $document->setContent($this->pdfRenderer->render($document));

        return $document;
    }
$criteria = OrderDocumentCriteriaFactory::create([$orderId]$deepLinkCode);

        /** @var ?OrderEntity $order */
        $order = $this->orderRepository->search($criteria$versionContext)->get($orderId);

        if ($order === null) {
            if (Feature::isActive('v6.6.0.0')) {
                throw DocumentException::orderNotFound($orderId);
            }

            throw new InvalidOrderException($orderId);
        }

        return $order;
    }

    private function handlePrices(OrderEntity $order): OrderEntity
    {
        foreach ($order->getLineItems() ?? [] as $lineItem) {
            $lineItem->setUnitPrice($lineItem->getUnitPrice() / -1);
            $lineItem->setTotalPrice($lineItem->getTotalPrice() / -1);
        }

        
$this->eventDispatcher->dispatch(new CheckoutOrderPlacedCriteriaEvent($criteria$context));

        /** @var OrderEntity|null $orderEntity */
        $orderEntity = Profiler::trace('checkout-order::order-loading', fn () => $this->orderRepository->search($criteria$context->getContext())->first());

        if (!$orderEntity) {
            if (Feature::isActive('v6.6.0.0')) {
                throw CartException::invalidPaymentOrderNotStored($orderId);
            }

            throw new InvalidOrderException($orderId);
        }

        $event = new CheckoutOrderPlacedEvent(
            $context->getContext(),
            $orderEntity,
            $context->getSalesChannel()->getId()
        );

        Profiler::trace('checkout-order::event-listeners', function D) use ($event): void {
            $this->eventDispatcher->dispatch($event);
        });

        
$criteria = OrderDocumentCriteriaFactory::create([$orderId]$deepLinkCode);

        /** @var ?OrderEntity $order */
        $order = $this->orderRepository->search($criteria$versionContext)->get($orderId);

        if ($order === null) {
            if (Feature::isActive('v6.6.0.0')) {
                throw DocumentException::orderNotFound($orderId);
            }

            throw new InvalidOrderException($orderId);
        }

        return $order;
    }

    private function getNumber(Context $context, OrderEntity $order, DocumentGenerateOperation $operation): string
    {
        return $this->numberRangeValueGenerator->getValue(
            'document_' . self::TYPE,
            $context,
            $order->getSalesChannelId(),
            

                'additionalInformation' => $additionalInformation,
                'orderTransactionId' => $orderTransactionId,
            ],
            $e
        );
    }

    public static function invalidOrder(string $orderId, ?\Throwable $e = null): self
    {
        if (!Feature::isActive('v6.6.0.0')) {
            return new InvalidOrderException($orderId$e);
        }

        return new self(
            Response::HTTP_NOT_FOUND,
            self::PAYMENT_INVALID_ORDER_ID,
            'The order with id {{ orderId }} is invalid or could not be found.',
            [
                'orderId' => $orderId,
            ],
            $e
        );
    }
Home | Imprint | This part of the site doesn't use cookies.