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:
So, it echos "not found" because $secondaryimage is not an object in the list - how do I get that working please?
Thanks
Dave
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
Hey Nour, thanks, so I've updated my code to:
But now I get the error:
Length of either side cannot be 0 or negative, current size is x
<?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"; } }
Viewing 15 lines of 16 lines. View entire code block.
But now I get the error:
Length of either side cannot be 0 or negative, current size is x
that's because your $defaultimageheight and defaultimageheight have no value.
Somewhere before that code add
Of course give them any values you want
Somewhere before that code add
$defaultimagewidth = 720; $defaultimageheight = 720;
Of course give them any values you want
Ah yes, of course, spot on thank you sir!
my pleasure Gov'nor!
You are actually getting all the images. So then you need a loop that does