EmptyCartException example


    public function persist(Cart $cart, SalesChannelContext $context): string
    {
        if ($cart->getErrors()->blockOrder()) {
            throw CartException::invalidCart($cart->getErrors());
        }

        if (!$context->getCustomer()) {
            throw CartException::customerNotLoggedIn();
        }
        if ($cart->getLineItems()->count() <= 0) {
            throw new EmptyCartException();
        }

        $order = $this->converter->convertToOrder($cart$contextnew OrderConversionContext());

        $context->getContext()->scope(Context::SYSTEM_SCOPE, function DContext $context) use ($order): void {
            $this->orderRepository->create([$order]$context);
        });

        return $order['id'];
    }
}
Home | Imprint | This part of the site doesn't use cookies.