/** @var ProductMediaCollection $sliderItems */
$sliderItems =
new ProductMediaCollection(array_merge( [$productEntity->
getCoverId() =>
$productEntity->
getCover()],
$sliderItems->
getElements() ));
} } foreach ($sliderItems->
getMedia() as $media) { $imageSliderItem =
new ImageSliderItemStruct();
$imageSliderItem->
setMedia($media);
$imageSlider->
addSliderItem($imageSliderItem);
} } } protected function sortItemsByPosition(ProductMediaCollection
$sliderItems): void
{ if (!
$sliderItems->
first() || !
$sliderItems->
first()->
has('position'
)) { return;
} $sliderItems->
sort(static fn (ProductMediaEntity
$a, ProductMediaEntity
$b) =>
$a->
get('position'
) -
$b->
get('position'
));
}