Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
createNamedParameter example
protected
function
configureQuery
(
QueryBuilder
$builder
, ?int
$shopId
, string
$pluginName
)
: QueryBuilder
{
return
$builder
->
innerJoin
(
'coreConfigValues',
's_core_shops',
'coreShops',
'coreConfigValues.shop_id = coreShops.main_id'
)
->
andWhere
(
$builder
->
expr
(
)
->
eq
(
'corePlugins.name',
$builder
->
createNamedParameter
(
$pluginName
)
)
)
->
andWhere
(
$builder
->
expr
(
)
->
eq
(
'coreShops.id',
$builder
->
createNamedParameter
(
$shopId
)
)
)
;
}
protected
function
isLayerResponsible
(
?int
$shopId
)
: bool
{
$queryBuilder
=
$this
->connection->
createQueryBuilder
(
)
;
return
$queryBuilder
->
select
(
'1'
)
->
from
(
's_core_shops'
)
->
andWhere
(
$queryBuilder
->
expr
(
)
->
eq
(
'id', ':id'
)
)
if
(
$shopId
=== null
)
{
return
$this
->
getParent
(
)
->
readValues
(
$pluginName
,
$shopId
)
;
}
return
parent::
readValues
(
$pluginName
,
$shopId
)
;
}
protected
function
configureQuery
(
QueryBuilder
$builder
, ?int
$shopId
, string
$pluginName
)
: QueryBuilder
{
return
$builder
->
andWhere
(
$builder
->
expr
(
)
->
eq
(
'corePlugins.name',
$builder
->
createNamedParameter
(
$pluginName
)
)
)
->
andWhere
(
$builder
->
expr
(
)
->
eq
(
'coreConfigValues.shop_id',
$builder
->
createNamedParameter
(
$shopId
)
)
)
;
}
protected
function
isLayerResponsible
(
?int
$shopId
)
: bool
{
$queryBuilder
=
$this
->connection->
createQueryBuilder
(
)
;
return
$queryBuilder
->
from
(
's_core_shops'
)
->
select
(
'1'
)
->
andWhere
(
$queryBuilder
->
expr
(
)
->
eq
(
'id', ':id'
)
)
if
(
$where
=== null
)
{
$expression
= 'IS NULL';
}
$cond
= '`' .
$item
[
'property'
]
. '` ' .
$expression
;
if
(
$where
)
{
if
(
$expression
=== 'IN'
)
{
$cond
=
$query
->
expr
(
)
->
in
(
'`' .
$item
[
'property'
]
. '`',
$where
)
;
}
else
{
$cond
.= ' ' .
$query
->
createNamedParameter
(
$where
)
;
}
}
if
(
isset
(
$item
[
'operator'
]
)
)
{
$query
->
orWhere
(
$cond
)
;
}
else
{
$query
->
andWhere
(
$cond
)
;
}
}
}
}
'`category`.updated_at',
]
)
;
$wheres
=
[
]
;
$categoryIds
=
array_filter
(
[
$context
->
getSalesChannel
(
)
->
getNavigationCategoryId
(
)
,
$context
->
getSalesChannel
(
)
->
getFooterCategoryId
(
)
,
$context
->
getSalesChannel
(
)
->
getServiceCategoryId
(
)
,
]
)
;
foreach
(
$categoryIds
as
$id
)
{
$wheres
[
]
= '`category`.path LIKE ' .
$query
->
createNamedParameter
(
'%|' .
$id
. '|%'
)
;
}
$query
->
andWhere
(
'(' .
implode
(
' OR ',
$wheres
)
. ')'
)
;
$query
->
andWhere
(
'`category`.version_id = :versionId'
)
;
$query
->
andWhere
(
'`category`.active = 1'
)
;
$query
->
andWhere
(
'`category`.type != :linkType'
)
;
$excludedCategoryIds
=
$this
->
getExcludedCategoryIds
(
$context
)
;
if
(
!
empty
(
$excludedCategoryIds
)
)
{
$query
->
andWhere
(
'`category`.id NOT IN (:categoryIds)'
)
;
$query
->
setParameter
(
'categoryIds', Uuid::
fromHexToBytesList
(
$excludedCategoryIds
)
, ArrayParameterType::STRING
)
;
}