0

I want to show show a list of all product images of that specific product below description in a loop.

use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler; class Gallery

{ protected $galleryReadHandler; public function __construct( GalleryReadHandler $galleryReadHandler ) { $this->galleryReadHandler = $galleryReadHandler; } /** Add image gallery to $product */ public function addGallery($product) { $this->galleryReadHandler->execute($product); } } 

iam still confused that where i have to get these coding and in which particular files...like where to use these coding in which files This is what i want

enter image description here

5
  • You need to provide more detail to your question. What have you tried already? What errors have you seen? – Danny Nimmo Feb 20 '17 at 10:23
  • use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler; class Gallery { protected $galleryReadHandler; public function __construct( GalleryReadHandler $galleryReadHandler ) { $this->galleryReadHandler = $galleryReadHandler; } /** Add image gallery to $product */ public function addGallery($product) { $this->galleryReadHandler->execute($product); } } iam still confused that where i have to get these coding and in which particular files...like where to use these coding in which files – Yogesh Raghav Feb 20 '17 at 10:38
  • You need to add this to the question. – Danny Nimmo Feb 20 '17 at 10:40
  • I have edited my question. – Yogesh Raghav Feb 20 '17 at 10:51
  • any reply please? – Yogesh Raghav Feb 20 '17 at 12:18
0

I have achieved it using below code. path to file: module-catalog/view/frontend/templates/product/view

edit:attribute.html

This is default Code:

<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_call = $block->getAtCall();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

if ($_attributeLabel && $_attributeLabel == 'default') {
    $_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();
}
if ($_attributeType && $_attributeType == 'text') {
    $_attributeValue = ($_helper->productAttribute($_product, $_product->$_call(), $_code)) ? $_product->getAttributeText($_code) : '';
} else {
    $_attributeValue = $_helper->productAttribute($_product, $_product->$_call(), $_code);
}
?>

<?php if ($_attributeValue): ?>
<div class="product attribute <?php /* @escapeNotVerified */ echo $_className?>">
    <?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php /* @escapeNotVerified */ echo $_attributeLabel?></strong><?php endif; ?>
    <div class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue;
   if($_className=='description')
   {
    ?>

    <?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());        
   $images = $product->getMediaGalleryImages(); 
    foreach($images as $child){ ?>
        <img src="<?php echo $child->getUrl(); ?>" >
<?php } ?>
<?php } ?>

    </div>
</div>
<?php endif; ?>

Add after

<div class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue;


<?php /* @escapeNotVerified */ echo $_attributeValue;
   if($_className=='description')
   {
    ?>

    <?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());        
   $images = $product->getMediaGalleryImages(); 
    foreach($images as $child){ ?>
        <img src="<?php echo $child->getUrl(); ?>" >
<?php } ?>
<?php } ?>

You will get a list of product images on product listing page as shown in below image: enter image description here

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.