Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
createVariantImage example
/** @var Query<Detail> $query */
$query
=
$builder
->
getQuery
(
)
;
foreach
(
$query
->
getResult
(
)
as
$variant
)
{
if
(
!
$force
&&
$this
->
getCollectionElementByProperty
(
$variant
->
getImages
(
)
, 'parent',
$mapping
->
getImage
(
)
)
)
{
continue
;
}
$image
=
$this
->
getVariantResource
(
)
->
createVariantImage
(
$mapping
->
getImage
(
)
,
$variant
)
;
$variant
->
getImages
(
)
->
add
(
$image
)
;
}
}
$this
->
getManager
(
)
->
flush
(
)
;
}
/** * Helper function which creates a new product image with the passed media object. * * @return Image */
}
elseif
(
isset
(
$imageData
[
'link'
]
)
)
{
// Check if an url passed and upload the passed image url and create a new product image.
$media
=
$this
->
getMediaResource
(
)
->
internalCreateMediaByFileLink
(
$imageData
[
'link'
]
)
;
$image
=
$this
->
getArticleResource
(
)
->
createNewArticleImage
(
$article
,
$media
)
;
}
else
{
throw
new
CustomValidationException
(
"One of the passed variant images doesn't contain a mediaId or link property!"
)
;
}
$variantImage
=
$this
->
createVariantImage
(
$image
,
$variant
)
;
$this
->
createImageMappingForOptions
(
$variant
->
getConfiguratorOptions
(
)
,
$image
)
;
$images
->
add
(
$variantImage
)
;
}