customerNotLoggedIn example

return $this->shippingMethodRoute->load($request$contextnew Criteria())->getShippingMethods();
    }

    /** * @throws CustomerNotLoggedInException */
    private function validateCustomerAddresses(Cart $cart, SalesChannelContext $context): void
    {
        $customer = $context->getCustomer();
        if ($customer === null) {
            throw CartException::customerNotLoggedIn();
        }

        $billingAddress = $customer->getActiveBillingAddress();
        $shippingAddress = $customer->getActiveShippingAddress();

        $this->validateBillingAddress($billingAddress$cart$context);
        $this->validateShippingAddress($shippingAddress$billingAddress$cart$context);
    }

    private function validateBillingAddress(
        ?CustomerAddressEntity $billingAddress,
        
$this->itemRounding = $itemRounding;
    }

    public function getCurrencyId(): string
    {
        return $this->getCurrency()->getId();
    }

    public function ensureLoggedIn(bool $allowGuest = true): void
    {
        if ($this->customer === null) {
            throw CartException::customerNotLoggedIn();
        }

        if (!$allowGuest && $this->customer->getGuest()) {
            throw CartException::customerNotLoggedIn();
        }
    }

    public function getCustomerId(): ?string
    {
        return $this->customer ? $this->customer->getId() : null;
    }
}


    /** * @throws CategoryNotFoundException * @throws CustomerNotLoggedInException * @throws InconsistentCriteriaIdsException * @throws RoutingException */
    public function load(Request $request, SalesChannelContext $salesChannelContext): AccountPaymentMethodPage
    {
        if (!$salesChannelContext->getCustomer()) {
            throw CartException::customerNotLoggedIn();
        }

        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = AccountPaymentMethodPage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        if ($page->getSalesChannelPaymentMethods()) {
            


    /** * @throws CategoryNotFoundException * @throws CustomerNotLoggedInException * @throws InconsistentCriteriaIdsException * @throws RoutingException */
    public function load(Request $request, SalesChannelContext $salesChannelContext): AccountOrderDetailPage
    {
        if (!$salesChannelContext->getCustomer()) {
            throw CartException::customerNotLoggedIn();
        }

        $orderId = (string) $request->get('id');

        if ($orderId === '') {
            throw RoutingException::missingRequestParameter('id');
        }

        $criteria = new Criteria([$orderId]);
        $criteria
            ->addAssociation('lineItems')
            

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

        
throw new DecorationPatternException(self::class);
    }

    #[Route(path: '/store-api/order/download/{orderId}/{downloadId}', name: 'store-api.account.order.single.download', methods: ['GET'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])]     public function load(Request $request, SalesChannelContext $context): Response
    {
        $customer = $context->getCustomer();
        $downloadId = $request->get('downloadId', false);
        $orderId = $request->get('orderId', false);

        if (!$customer) {
            throw CustomerException::customerNotLoggedIn();
        }

        if ($downloadId === false || $orderId === false) {
            throw RoutingException::missingRequestParameter(!$downloadId ? 'downloadId' : 'orderId');
        }

        $criteria = new Criteria([$downloadId]);
        $criteria->addAssociation('media');
        $criteria->addFilter(new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                


    /** * @throws CategoryNotFoundException * @throws CustomerNotLoggedInException * @throws InconsistentCriteriaIdsException * @throws RoutingException */
    public function load(Request $request, SalesChannelContext $salesChannelContext): AccountProfilePage
    {
        if ($salesChannelContext->getCustomer() === null) {
            throw CartException::customerNotLoggedIn();
        }

        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = AccountProfilePage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $page->setSalutations($this->getSalutations($salesChannelContext$request));

        
'message' => 'Group request for customer "id-1" is not found',
        ];

        yield CustomerException::CUSTOMERS_NOT_FOUND => [
            'exception' => CustomerException::customersNotFound(['id-1', 'id-2']),
            'statusCode' => Response::HTTP_NOT_FOUND,
            'errorCode' => CustomerException::CUSTOMERS_NOT_FOUND,
            'message' => 'These customers "id-1, id-2" are not found',
        ];

        yield CustomerException::CUSTOMER_NOT_LOGGED_IN => [
            'exception' => CustomerException::customerNotLoggedIn(),
            'statusCode' => Response::HTTP_FORBIDDEN,
            'errorCode' => CustomerException::CUSTOMER_NOT_LOGGED_IN,
            'message' => 'Customer is not logged in.',
        ];

        yield CustomerException::LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND => [
            'exception' => CustomerException::downloadFileNotFound('id-1'),
            'statusCode' => Response::HTTP_NOT_FOUND,
            'errorCode' => CustomerException::LINE_ITEM_DOWNLOAD_FILE_NOT_FOUND,
            'message' => 'Line item download file with id "id-1" not found.',
        ];

        
return $page;
    }

    private function getById(string $addressId, SalesChannelContext $context): CustomerAddressEntity
    {
        if (!Uuid::isValid($addressId)) {
            throw new InvalidUuidException($addressId);
        }

        if ($context->getCustomer() === null) {
            throw CartException::customerNotLoggedIn();
        }
        $customer = $context->getCustomer();

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('id', $addressId));
        $criteria->addFilter(new EqualsFilter('customerId', $customer->getId()));

        $address = $this->listAddressRoute->load($criteria$context$customer)->getAddressCollection()->get($addressId);

        if (!$address) {
            throw CustomerException::addressNotFound($addressId);
        }
/** * @throws CustomerNotLoggedInException * @throws InconsistentCriteriaIdsException * @throws RoutingException * @throws OrderException */
    private function getOrder(Request $request, SalesChannelContext $salesChannelContext): OrderEntity
    {
        $customer = $salesChannelContext->getCustomer();
        if ($customer === null) {
            throw CartException::customerNotLoggedIn();
        }

        $orderId = $request->get('orderId');
        if (!$orderId) {
            throw RoutingException::missingRequestParameter('orderId', '/orderId');
        }

        $criteria = (new Criteria([$orderId]))
            ->addFilter(new EqualsFilter('order.orderCustomer.customerId', $customer->getId()))
            ->addAssociation('lineItems.cover')
            ->addAssociation('transactions.paymentMethod')
            
->add(self::STATE_ID, new Type('string'))
        ;

        $this->validator->validate($parameters$definition);

        $addressCriteria = new Criteria();
        if ($context->getCustomer()) {
            $addressCriteria->addFilter(new EqualsFilter('customer_address.customerId', $context->getCustomer()->getId()));
        } else {
            // do not allow to set address ids if the customer is not logged in             if (isset($parameters[self::SHIPPING_ADDRESS_ID])) {
                throw CartException::customerNotLoggedIn();
            }

            if (isset($parameters[self::BILLING_ADDRESS_ID])) {
                throw CartException::customerNotLoggedIn();
            }
        }

        $currencyCriteria = new Criteria();
        $currencyCriteria->addFilter(
            new EqualsFilter('currency.salesChannels.id', $context->getSalesChannel()->getId())
        );

        
/** * @throws CategoryNotFoundException * @throws CustomerNotLoggedInException * @throws InconsistentCriteriaIdsException * @throws RoutingException * @throws OrderException */
    public function load(Request $request, SalesChannelContext $salesChannelContext): AccountEditOrderPage
    {
        if (!$salesChannelContext->getCustomer() && $request->get('deepLinkCode', false) === false) {
            throw CartException::customerNotLoggedIn();
        }

        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = AccountEditOrderPage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $orderRouteResponse = $this->getOrder($request$salesChannelContext);

        
->addFilter(new EqualsFilter('sent', true));

        $criteria->addAssociation('billingAddress');
        $criteria->addAssociation('orderCustomer.customer');

        $deepLinkFilter = \current(array_filter($criteria->getFilters()static fn (Filter $filter) => \in_array('order.deepLinkCode', $filter->getFields(), true)
            || \in_array('deepLinkCode', $filter->getFields(), true))) ?: null;

        if ($context->getCustomer()) {
            $criteria->addFilter(new EqualsFilter('order.orderCustomer.customerId', $context->getCustomer()->getId()));
        } elseif ($deepLinkFilter === null) {
            throw CartException::customerNotLoggedIn();
        }

        $orderResult = $this->orderRepository->search($criteria$context->getContext());
        $orders = $orderResult->getEntities();

        // remove old orders only if there is a deeplink filter         if ($deepLinkFilter !== null) {
            $orders = $this->filterOldOrders($orders);
        }

        // Handle guest authentication if deeplink is set
$this->createMock(PaymentMethodRoute::class),
            $this->createMock(GenericPageLoader::class),
            $this->createMock(AddressValidationFactory::class),
            $this->createMock(DataValidator::class)
        );

        $context = $this->createMock(SalesChannelContext::class);
        $context
            ->method('getCustomer')
            ->willReturn(null);

        $expected = CartException::customerNotLoggedIn()::class;

        static::expectException($expected);
        static::expectExceptionMessage('Customer is not logged in');

        $checkoutConfirmPageLoader->load(new Request()$context);
    }

    public function testViolationsAreAddedAsCartErrorsWithSameAddress(): void
    {
        $violations = new ConstraintViolationList([
            new ConstraintViolation(
                
'cancel',
            new ParameterBag(),
            $context->getContext()
        );

        return new CancelOrderRouteResponse($newState);
    }

    private function verify(string $orderId, SalesChannelContext $context): void
    {
        if ($context->getCustomer() === null) {
            throw OrderException::customerNotLoggedIn();
        }

        $criteria = new Criteria([$orderId]);
        $criteria->addFilter(new EqualsFilter('orderCustomer.customerId', $context->getCustomer()->getId()));

        if ($this->orderRepository->searchIds($criteria$context->getContext())->firstId() === null) {
            throw OrderException::orderNotFound($orderId);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.