Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getMaxWidth example
if
(
!
$media
instanceof Media
)
{
return
[
]
;
}
$thumbnails
=
[
]
;
foreach
(
$media
->
getThumbnails
(
)
as
$thumbnail
)
{
$thumbnails
[
]
=
[
'source' =>
$thumbnail
->
getSource
(
)
,
'retinaSource' =>
$thumbnail
->
getRetinaSource
(
)
,
'sourceSet' =>
$this
->
getSourceSet
(
$thumbnail
)
,
'maxWidth' =>
$thumbnail
->
getMaxWidth
(
)
,
'maxHeight' =>
$thumbnail
->
getMaxHeight
(
)
,
'attributes' =>
$thumbnail
->
getAttributes
(
)
,
]
;
}
$data
=
[
'id' =>
$media
->
getId
(
)
,
'position' => null,
'source' =>
$media
->
getFile
(
)
,
'description' =>
$media
->
getName
(
)
,
'extension' =>
$media
->
getExtension
(
)
,
ShopContextInterface
$context
)
{
$search
->
addPostFilter
(
$this
->
getQuery
(
$criteriaPart
)
)
;
}
private
function
getQuery
(
WidthCondition
$criteriaPart
)
: RangeQuery
{
$range
=
[
]
;
if
(
$criteriaPart
->
getMinWidth
(
)
)
{
$range
[
'gte'
]
=
$criteriaPart
->
getMinWidth
(
)
;
}
if
(
$criteriaPart
->
getMaxWidth
(
)
)
{
$range
[
'lte'
]
=
$criteriaPart
->
getMaxWidth
(
)
;
}
return
new
RangeQuery
(
'width',
$range
)
;
}
}
$this
->variantHelper->
joinVariants
(
$query
)
;
$min
= ':minWidth' .
md5
(
json_encode
(
$condition
, JSON_THROW_ON_ERROR
)
)
;
$max
= ':maxWidth' .
md5
(
json_encode
(
$condition
, JSON_THROW_ON_ERROR
)
)
;
if
(
$condition
->
getMinWidth
(
)
> 0
)
{
$query
->
andWhere
(
'allVariants.width >= ' .
$min
)
;
$query
->
setParameter
(
$min
,
$condition
->
getMinWidth
(
)
)
;
}
if
(
$condition
->
getMaxWidth
(
)
> 0
)
{
$query
->
andWhere
(
'allVariants.width <= ' .
$max
)
;
$query
->
setParameter
(
$max
,
$condition
->
getMaxWidth
(
)
)
;
}
}
}