For one product I am getting gallery images 0.
in gallery.phtml
<?php $galleryImages = $block->getGalleryImages(); ?>
gives me count 0.
I checked it database table catalog_product_entity_media_gallery_value_to_entity
for row_id which gives me 7 value_id(which means 7 images) which is linked to catalog_product_entity_media_gallery
.
Whats the reason. How can i get all media gallery images.
Gallery.php
public function getGalleryImages()
{
$product = $this->getProduct();
$images = $product->getMediaGalleryImages();
\Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class)->info("in images " .$images );
if (!$images instanceof \Magento\Framework\Data\Collection) {
return $images;
}
foreach ($images as $image) {
$galleryImagesConfig = $this->getGalleryImagesConfig()->getItems();
foreach ($galleryImagesConfig as $imageConfig) {
$image->setData(
$imageConfig->getData('data_object_key'),
$this->imageUrlBuilder->getUrl($image->getFile(), $imageConfig['image_id'])
);
}
}
return $images;
}
getMediaGalleryImages
in file Product.php
public function getMediaGalleryImages()
{
$directory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
if (!$this->hasData('media_gallery_images')) {
$this->setData('media_gallery_images', $this->_collectionFactory->create());
}
if (!$this->getData('media_gallery_images')->count() && is_array($this->getMediaGallery('images'))) {
$images = $this->getData('media_gallery_images');
foreach ($this->getMediaGallery('images') as $image) {
if (!empty($image['disabled'])
|| !empty($image['removed'])
|| empty($image['value_id'])
|| $images->getItemById($image['value_id']) != null
) {
continue;
}
$image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
$image['id'] = $image['value_id'];
$image['path'] = $directory->getAbsolutePath($this->getMediaConfig()->getMediaPath($image['file']));
$images->addItem(new \Magento\Framework\DataObject($image));
}
$this->setData('media_gallery_images', $images);
}
return $this->getData('media_gallery_images');
}