0

I have a model, this is the code of getting product collection

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
    $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
    $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');     
    /** Apply filters here */
    $collection = $productCollection->addAttributeToSelect('*')->setPageSize($limit) 
        ->setCurPage($page)
        ->load();

    $products = array();
    foreach ($collection as $product){
        $products[$product->getId()]['image_list'] = $product->getMediaGalleryImages();
    }

getMediaGalleryImages() return null, i tried to use $product->getData('image') but only return the url of the main images, anyone know what is the problem.

0

try this code.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');     

$collection = $productCollection->addAttributeToSelect('*')->setPageSize($limit) 
        ->setCurPage($page)
        ->load();

$products = array();
foreach ($collection as $product)
{
   $product = $objectManager->create('Magento\Catalog\Model\Product')->load($product->getId());
   $products[$product->getId()]['image_list'] = $product->getMediaGalleryImages();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.