2016-04-24 8 views
1

In Magento 1 habe ich immerErhalten Sie alle Produktbilder in Magento 2 auf Produktliste Seite

$_product->getMediaGallery('images') 

Aber in der Quelle verwendet haben von Magento 2 I

$productImage = $block->getImage($_product, $image); 
echo $productImage->toHtml(); 

sehen nur Es wird die erste Produktbild. Wie bekomme ich das zweite oder dritte Bild (nicht nur das Basisbild)?

GetMediaGallery Funktion existiert nicht?

Antwort

0

Schritt 1: offen list.phtml von Ihrem Thema \ Magento_Catalog \ Templates \ product

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

$ _imagehelper = $ this-> Helfer ('Magento \ Catalog \ Helper \ Bild');

hinzufügen oben in Ihrer phtml Datei

dann unter Code in Produkt-Schleife hinzufügen, wo Sie Galerie Bilder wollen

<div class="left-carousel"> 

        <div class="product-small-thumbs"> 
        <?php $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId()); 


          $images = $product->getMediaGalleryImages(); 
          if($images->count()>0){?> 
          <div class="carousel carousel-<?php $_product->getId()?>"> 


         <?php 
          $i = 0; 
          foreach($images as $child){ 
          $i++; 
          $productImage = $_imagehelper->init($product, 'product_page_image_large') 
           ->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(81,53) 
           ->getUrl(); 

          $productImagedata = $_imagehelper->init($product, 'product_page_image_large') 
          ->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(285,240) 
          ->getUrl(); 
          if($i==1) continue; 

          ?> 
          <div class="slide"> 
          <img data-id="smallthumbs-<?php echo $_product->getId();?>" data-img="<?php echo $productImagedata; ?>" src="<?php echo $productImage; ?>"/> 
          </div> 

          <?php 

          } 
          ?> 
          </div> 

          <?php 
          } 
        ?> 
        </div> 
       </div>