I've embedded some extra pictures and videos on my product pages, but when I create a new without setting a picture, Magento creates an error because it cannot find the picture, that is not set. I've created an attribute in Magento named embed3, an image attribute. Then I made this snippet, which works great - except if no pictures are chosen Magento fails:
<?php
$video3 = $_product->getEmbed3();
if (isset($video3)){
echo '<img src="';
echo $this->helper('catalog/image')->init($_product, 'embed3');
echo '"/>';
}
else
{
}
?>
It's crude and ugly - I know, any suggestions/help will be much appreciated
Sadly that didn't work @F. Haymar d'Ettory :( it only created errors on all my products. But I found out that, while it works well on products I've created in the past, and products with pictures isset was also working, when creating new products and not setting a picture, Magento set it as "no_selection" - and the isset then think's that theres actually an image set, but here is not. So by creating this:
if (isset($video3)&&($video3 != 'no_selection')){
it works again, still not pretty but it works.
Are you using this snippet in product view?
Use the following instead of $video3 = $_product->getEmbed3()
. getAttribute() always exists for a product resource, while magic methods don't.
$video3 = $_product->getResource()->getAttribute('embed3');