<?php

namespace Leadlion\Autogedal\Model\ResourceModel\Catalog;

use Magento\Framework\UrlInterface;

class Product extends \Magento\Sitemap\Model\ResourceModel\Catalog\Product
{
    /**
     * Get all product images
     *
     * @param \Magento\Framework\DataObject $product
     * @param int $storeId
     * @return array
     */
    protected function _getAllProductImages($product, $storeId)
    {
        $product->setStoreId($storeId);
        $gallery = $this->mediaGalleryResourceModel->loadProductGalleryByAttributeId(
            $product,
            $this->mediaGalleryReadHandler->getAttribute()->getId()
        );

        $imagesCollection = [];
        if ($gallery) {
            foreach ($gallery as $image) {
                $imagesCollection[] = new \Magento\Framework\DataObject(
                    [
                        'url' => $this->getMediaUrl($storeId) . 'catalog/product' . $image['file'],
                        'caption' => $image['label'] ? $image['label'] : $image['label_default'],
                    ]
                );
            }
        }

        return $imagesCollection;
    }

    /**
     * Get media url
     *
     * @return string
     */
    protected function getMediaUrl($storeId)
    {
        return $this->_storeManager->getStore($storeId)
            ->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, false);
    }
}
