NonUniqueIdentifierUsedException example

$builder = Shopware()->Models()->createQueryBuilder();
        $builder->select(['customer.id'])
                ->from(CustomerModel::class, 'customer')
                ->where('customer.number = ?1')
                ->setParameter(1, $number);

        try {
            $id = $builder->getQuery()->getOneOrNullResult();
        } catch (NonUniqueResultException $nonUniqueResultException) {
            $ids = $builder->getQuery()->getArrayResult();
            throw new NonUniqueIdentifierUsedException('number', (string) $number, CustomerModel::classarray_column($ids, 'id'));
        }

        if (!$id) {
            throw new NotFoundException(sprintf('Customer by number %s not found', $number));
        }

        return $id['id'];
    }

    /** * @param string $number * * @throws NotFoundException * @throws ParameterMissingException * * @return array<string, mixed>|CustomerModel */
Home | Imprint | This part of the site doesn't use cookies.