I'm looking for a solution to move the video to the first position in left gallery in product page WITHOUT changing from admin.
I've set the video in 3rd position, but I want the video should in the 1st position.
The result will look like this:
I've custom some in function setData() from fotorama.js, i've create datanew, then i load data, and check if its a video or not, then move video to top by using "unshift", then assign data = datanew:
// other code
function setData() {
data = that.data = data || clone(opts.data) || getDataFromHtml($fotorama);
size = that.size = data.length;
ready.ok && opts.shuffle && shuffle(data);
var datanew = [];
for (var i = 0; i < data.length; i++) {
if (data[i].type == 'video') {
datanew.unshift(data[i]);
} else {
datanew.push(data[i]);
}
}
data = datanew;
checkForVideo();
activeIndex = limitIndex(activeIndex);
size && appendElements(true);
}
// other code
But most of the time, its doesn't show the play video button and video thumb icon.
Other time, it shows both thumb icon in the image as well (which I don't want to).
I'm following @Dhiren Vasoya solution, and its almost work, but the content in the right is not video, its image.
Here are the code that i've custom in Gallery.php
public function getGalleryImagesJson()
{
$imagesItems = [];
$n = 1;
/** @var DataObject $image */
foreach ($this->getGalleryImages() as $image) {
$position = $image->getData('position') + 1;
if ($image->getMediaType() == 'external-video') {
$isMain = true;
$position = $n;
$n++;
} else {
$isMain = false;
}
$imageItem = new DataObject([
'thumb' => $image->getData('small_image_url'),
'img' => $image->getData('medium_image_url'),
'full' => $image->getData('large_image_url'),
'caption' => ($image->getLabel() ?: $this->getProduct()->getName()),
'position' => $position,
'isMain' => $isMain,
'type' => str_replace('external-', '', $image->getMediaType()),
'videoUrl' => $image->getVideoUrl(),
]);
foreach ($this->getGalleryImagesConfig()->getItems() as $imageConfig) {
$imageItem->setData(
$imageConfig->getData('json_object_key'),
$image->getData($imageConfig->getData('data_object_key'))
);
}
if ($image->getMediaType() == 'external-video') {
array_unshift($imagesItems, $imageItem->toArray());
} else {
$imagesItems[] = $imageItem->toArray();
}
// $imagesItems[] = $imageItem->toArray();
}
if (empty($imagesItems)) {
$imagesItems[] = [
'thumb' => $this->_imageHelper->getDefaultPlaceholderUrl('thumbnail'),
'img' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
'full' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
'caption' => '',
'position' => '0',
'isMain' => true,
'type' => 'image',
'videoUrl' => null,
];
}
return json_encode($imagesItems);
}