customerGroupNotFound example

foreach ($customers as $customer) {
            $salesChannelContext = $this->restorer->restoreByCustomer($customer->getId()$context);

            /** @var CustomerEntity $customer */
            $customer = $salesChannelContext->getCustomer();

            $criteria = new Criteria([$customer->getGroupId()]);
            $criteria->setLimit(1);
            $customerRequestedGroup = $this->customerGroupRepository->search($criteria$salesChannelContext->getContext())->first();

            if ($customerRequestedGroup === null) {
                throw CustomerException::customerGroupNotFound($customer->getGroupId());
            }

            $this->eventDispatcher->dispatch(new CustomerGroupRegistrationAccepted(
                $customer,
                $customerRequestedGroup,
                $salesChannelContext->getContext()
            ));
        }

        return new JsonResponse(null, JsonResponse::HTTP_NO_CONTENT);
    }

    
static::assertEquals($statusCode$caughtException->getStatusCode());
        static::assertEquals($errorCode$caughtException->getErrorCode());
        static::assertEquals($message$caughtException->getMessage());
    }

    /** * @return array<string, array{exception: ShopwareHttpException|CustomerException, statusCode: int, errorCode: string, message: string}> */
    public static function exceptionDataProvider(): iterable
    {
        yield CustomerException::CUSTOMER_GROUP_NOT_FOUND => [
            'exception' => CustomerException::customerGroupNotFound('id-1'),
            'statusCode' => Response::HTTP_BAD_REQUEST,
            'errorCode' => CustomerException::CUSTOMER_GROUP_NOT_FOUND,
            'message' => 'Customer group with id "id-1" not found',
        ];

        yield CustomerException::CUSTOMER_GROUP_REQUEST_NOT_FOUND => [
            'exception' => CustomerException::groupRequestNotFound('id-1'),
            'statusCode' => Response::HTTP_BAD_REQUEST,
            'errorCode' => CustomerException::CUSTOMER_GROUP_REQUEST_NOT_FOUND,
            'message' => 'Group request for customer "id-1" is not found',
        ];

        
Home | Imprint | This part of the site doesn't use cookies.