Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
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::
class
,
array_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 */