Community Store Product List - Get Additional Images?

Permalink
Hi folks,

I have a site using Community Store.

I want to get the first two additional images loaded on each product and render them in the product list. I took this function from the product blocks view and added the else statement:
<?php 
        $images = $product->getImagesObjects();
         if (is_object($secondaryimage)) {
                if($loop < 4) {
                     $thumb = Core::make('helper/image')->getThumbnail($secondaryimage, $defaultimagewidth, $defaultimageheight, true);
                    ?>
                    <a href="<?= $secondaryimage->getRelativePath() ?>" title="<?= h($product->getName()); ?>"><img src="<?= $thumb->src ?>" /></a>
                 <?php }
                          $loop++;
                }
           else {
                 echo "not found";
            }   
           ?>


So, it echos "not found" because $secondaryimage is not an object in the list - how do I get that working please?

Thanks

Dave

madesimplemedia
 
mnakalay replied on at Permalink Reply
mnakalay
Hey Dave, you're missing a loop. When you do
$images = $product->getImagesObjects();

You are actually getting all the images. So then you need a loop that does
foreach ($images as $secondaryimage) {
    // and your code here
}
madesimplemedia replied on at Permalink Reply
madesimplemedia
Hey Nour, thanks, so I've updated my code to:

<?php 
                                $images = $product->getImagesObjects();
                                foreach ($images as $secondaryimage) {
                                   if (is_object($secondaryimage)) {
                                        if($loop < 4) {
                                        $thumb = Core::make('helper/image')->getThumbnail($secondaryimage, $defaultimagewidth, $defaultimageheight, true);
                                        ?>
                                        <a href="<?= $secondaryimage->getRelativePath() ?>" title="<?= h($product->getName()); ?>"><img src="<?= $thumb->src ?>" /></a>
                                        <?php }
                                        $loop++;
                                    }
                                    else {
                                        echo "not found";
                                    }   
                                }


But now I get the error:

Length of either side cannot be 0 or negative, current size is x
mnakalay replied on at Permalink Best Answer Reply
mnakalay
that's because your $defaultimageheight and defaultimageheight have no value.

Somewhere before that code add
$defaultimagewidth = 720;
$defaultimageheight = 720;

Of course give them any values you want
madesimplemedia replied on at Permalink Reply
madesimplemedia
Ah yes, of course, spot on thank you sir!
mnakalay replied on at Permalink Reply
mnakalay
my pleasure Gov'nor!