Skip to content

Instantly share code, notes, and snippets.

@evgv
Created May 3, 2017 18:59
Show Gist options
  • Select an option

  • Save evgv/ffee0ed3cae2507572d5fa6ceb35af5a to your computer and use it in GitHub Desktop.

Select an option

Save evgv/ffee0ed3cae2507572d5fa6ceb35af5a to your computer and use it in GitHub Desktop.
Magento. Load media images of a product

Load media images of a product

Use Backend model of media_gallery attribute & afterload of product model

    
      $attribute = $product->getResource()->getAttribute('media_gallery');
       
      $backend = $attribute->getBackend();
      $backend->afterLoad($product);
       
      $mediaGalleryImages = $product->getMediaGalleryImages();
      if($mediaGalleryImages) {
          foreach ($mediaGalleryImages as $mediaGalleryImage) {
              // do something with image
          }
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment