0

I've created a module to show YouTube videos on a CMS page in Magento by pasting the videoId into a text field for each product, the video then shows on each custom CMS product page. The problem I have now is I need to pull a single image for the 'Play' button which is the logo for each product but I am not sure how to this.

I've tried creating another attribute called videothumbnail and selecting media image bot I can't see the field in the manage products section so I am a bit stuck.

This is the code that shows the YouTube video for each page. You will se that the image I currently have will show on all CMS page even if they are different products I need to assign an image to each page if possible.

  <?php $_product = Mage::getModel('catalog/product')->load($this->getProductId()); ?>
<?php if ($_product->getId() && $_product->getVideoid()): ?>
<ul class="list">
    <h3 class="product-name">Video</h3>
   <li> <a class="fancybox-video" href="http://www.youtube.com/embed/<?php echo $_product->getVideoid(); ?>">
    <img src="<?php echo $this->getSkinUrl('images/x5-play.png');?>" /></a> </li>
</ul>
<?php endif;?>
user1704524
  • 427
  • 3
  • 15
  • 40

2 Answers2

0

Assuming that you create a new media image called videothumbnail

By going to Admin -> Catalog -> Attribute -> Manage Attribute

Then create a new attribute of 'Media Image' for 'Catalog Input Type for Store Owner'

Then add it to a 'Manage Attribute Sets' in Admin -> Catalog -> Attribute

(you may need to do a reindex to catalog flat table)

<?php $_product = Mage::getModel('catalog/product')->load($this->getProductId()); ?>
<?php if ($_product->getId() && $_product->getVideoid()): ?>
<ul class="list">
    <h3 class="product-name">X5 Mop Video</h3>
   <li> 
       <a class="fancybox-video" href="http://www.youtube.com/embed/<?php echo $_product->getVideoid(); ?>">
       $_helper = Mage::helper('catalog/output');
       $_img = '<img id="image" src="' . Mage::helper('catalog/image')->init($_product, 'videothumbnail')->resize(410,420) . '" width="410" height="420" />';
       echo $_helper->productAttribute($_product, $_img, 'image');
   </li>
</ul>
<?php endif;?>
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
0

For less faff, but less control, you can pull a live thumbnail from YouTube very easily if you have the video ID:

How do I get a YouTube video thumbnail from the YouTube API?

You should consider using this as a fallback for if the product has no Magento video thumbnail specified.

Community
  • 1
  • 1
Paul Gregory
  • 1,733
  • 19
  • 25
  • This is also a good solution although the thumbnails that get generated a not as nice a custom image but thank you for your time – user1704524 Nov 26 '12 at 10:44