customerNotFoundByHash example

$customerHashCriteria = new Criteria();
        $customerHashCriteria->addFilter(new EqualsFilter('hash', $hash));

        /** @var CustomerRecoveryEntity|null $customerRecovery */
        $customerRecovery = $this->customerRecoveryRepository->search(
            $customerHashCriteria,
            $context->getContext()
        )->first();

        if (!$customerRecovery instanceof CustomerRecoveryEntity) {
            throw CustomerException::customerNotFoundByHash($hash);
        }

        return new CustomerRecoveryIsExpiredResponse($this->isExpired($customerRecovery));
    }

    /** * @throws ConstraintViolationException */
    private function validateHash(DataBag $data, SalesChannelContext $context): void
    {
        $definition = new DataValidationDefinition('customer.recovery.get');

        
$criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('hash', $dataBag->get('hash')));
        $criteria->addAssociation('addresses');
        $criteria->addAssociation('salutation');
        $criteria->setLimit(1);

        $customer = $this->customerRepository
            ->search($criteria$context->getContext())
            ->first();

        if (!$customer instanceof CustomerEntity) {
            throw CustomerException::customerNotFoundByHash($dataBag->get('hash'));
        }

        $this->validator->validate(
            [
                'em' => $dataBag->get('em'),
                'doubleOptInRegistration' => $customer->getDoubleOptInRegistration(),
            ],
            $this->getBeforeConfirmValidation(hash('sha1', (string) $customer->getEmail()))
        );

        if ((!Feature::isActive('v6.6.0.0') && $customer->getActive())
            
'message' => 'The customer with the id "id-1" is already confirmed.',
        ];

        yield CustomerException::CUSTOMER_GROUP_REGISTRATION_NOT_FOUND => [
            'exception' => CustomerException::customerGroupRegistrationConfigurationNotFound('id-1'),
            'statusCode' => Response::HTTP_NOT_FOUND,
            'errorCode' => CustomerException::CUSTOMER_GROUP_REGISTRATION_NOT_FOUND,
            'message' => 'Customer group registration for id id-1 not found.',
        ];

        yield CustomerException::CUSTOMER_NOT_FOUND_BY_HASH => [
            'exception' => CustomerException::customerNotFoundByHash('id-1'),
            'statusCode' => Response::HTTP_NOT_FOUND,
            'errorCode' => CustomerException::CUSTOMER_NOT_FOUND_BY_HASH,
            'message' => 'No matching customer for the hash "id-1" was found.',
        ];

        yield CustomerException::CUSTOMER_NOT_FOUND_BY_ID => [
            'exception' => CustomerException::customerNotFoundByIdException('id-1'),
            'statusCode' => Response::HTTP_NOT_FOUND,
            'errorCode' => CustomerException::CUSTOMER_NOT_FOUND_BY_ID,
            'message' => 'No matching customer for the id "id-1" was found.',
        ];

        
if (!$this->checkHash($hash$context->getContext())) {
            throw CustomerException::customerRecoveryHashExpired($hash);
        }

        $customerHashCriteria = new Criteria();
        $customerHashCriteria->addFilter(new EqualsFilter('hash', $hash));
        $customerHashCriteria->addAssociation('customer');

        $customerRecovery = $this->customerRecoveryRepository->search($customerHashCriteria$context->getContext())->first();

        if (!$customerRecovery instanceof CustomerRecoveryEntity) {
            throw CustomerException::customerNotFoundByHash($hash);
        }

        $customer = $customerRecovery->getCustomer();

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

        // reset login and pw-reset limit when password was changed         if (($request = $this->requestStack->getMainRequest()) !== null) {
            $cacheKey = strtolower((string) $customer->getEmail()) . '-' . $request->getClientIp();

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