I am uploading 2 images for each product. Only 2 no more, no less.
1st image is product base image and will be displayed on product details page.
I am using following line to display this image:
$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(180, 300).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');
I am able to display the above image correctly.
Second image will be displayed in a pop up when a particular link is clicked. I do not want to display a gallery. Just want to display each image separately.
I think I found a way to retrieve array of images uploaded:
$productData = $_product->getData();
$secondImage = $productData['media_gallery']['images'][1];
Now, I am not sure how to display this image. I mean how to use helper, like I used for first image to make is display second image.
I've option to hardcode the complete path of image and use:
$secondImage['file'];
to display the image etc, but, I want to know if there is way, I can do it magento way ?
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'scrollbars=yes,width=200,height=200,resizable=yes');return false;">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(68,68); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"/>
</a>
</li>
<?php endforeach; ?>
Code lifted from:
http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_lightbox_to_magento_v2
Note exactly the answer but obviously you can remove the foreach and simply supply the array's index if you know your only going to have one file.
Related
I have a Magento store at http://www.harmonics.co.uk and I have PinIt buttons on products.
The problem is when you click it, it does not pick up the image from the media attribute in the query string, even though the URL is correct.
I'm using the following code to generate my image and the PinIt button on product pages:
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
$image = $this->helper('catalog/image')->init($_product, $_product->getImageUrl(), 'image')->resize(150, 150);
?>
// PinIt Anchor
<a class="pinterest" href="http://pinterest.com/pin/create/button/?url=<?php echo $_product->getProductUrl(); ?>&media=<?php echo $image; ?>&description=<?php echo $_product->getName(); ?>" title="Share on Pinterest"> </a>
It used to work but I think Pinterest have changed the way their buttons work but I can't see how. The generated code looks almost the same, except that generated URL's replace : with %3A and / with %2F.
I've tried doing a string replace but this doesn't work either. Any ideas folks. Cheers.
try replacing
<a class="pinterest" href="http://pinterest.com/pin/create/button/?url=<?php echo $_product->getProductUrl(); ?>&media=<?php echo $image; ?>&description=<?php echo $_product->getName(); ?>" title="Share on Pinterest"> </a>
with
<a class="pinterest" href="http://pinterest.com/pin/create/button/?url=<?php echo urlencode($_product->getProductUrl()); ?>&media=<?php echo urlencode($image); ?>&description=<?php echo urlencode($_product->getName()); ?>" title="Share on Pinterest"> </a>
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;?>
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;?>
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.
To show product image in order email, I have written the following code in template/email/order/items/order/default.phtml
<?php
$_product = Mage::getModel('catalog/product')
->setStoreId($_item->getOrder()->getStoreId())
->load($_item->getProductId());
?>
<img src="<?php echo Mage::helper('catalog/image')
->init($_product, 'image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepFrame(FALSE)
->resize(50,50); ?>"
alt="<?php echo $_item->getName() ?>" />
It works fine. It displays resized product image in order email.
However, I have one problem.
The product image is fetched from media/catalog/product/cache
directory. And, if we Flush Images Cache from Magento Admin (System >
Cache Management) then the product image which was displayed before is
not displayed in order email. It’s because flushing image cache will
clear all cache images from media/catalog/product/cache directory.
What would be an appropriate solution to this problem? Is it a good idea to show product image in order email at all?
Try this:
<img src="<?php echo Mage::getModel('catalog/product_media_config')
->getMediaUrl($_product->getThumbnail()); ?>"
alt="<?php echo $_item->getName() ?>" />
You can use getSmallImage(), getThumbnail() for different images of the product.
I am trying to show image thumbnail of products in order view page.
For this I am using this line
<img src="<?php echo Mage::helper('catalog/image')
->init($_item,'small_image')
->resize(50); ?>" width="50" height="50" alt="" />
in this file
template/sales/order/items/renderer/default.phtml
what I get is the blank image of magento, this one -->
On firebug I get the image url as below
src="http://my_Website.com/media/catalog/product/cache/1/small_image/50x/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/small_image.jpg">
this is where that blank image is coming from.
Can anyone explain what's happening here and what's the possible solution.
Thank You very much in advance.
Try the codes given below:
First load the product
$_product = Mage::getModel('catalog/product')->load($_item->getProductId());
Then show the thumbnail where you want using the code given below
<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75, 75); ?>" alt="<?php echo $this->htmlEscape($_item->getName()); ?>" border="0" width="75" />
This code is working fine try :
if($_item->getProductType() == 'configurable') {
$_product = $_item->getProduct();
}else{
$_product = Mage::getModel('catalog/product')->load($_item->getId());
}
?>
<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="" />
Make sure you have checked the appropriate radio button on the products media tab. There are three columns (Base Image, Small Image, Thumbnail) that need to be set to use that image as a thumbnail.
I want to call the image that loads into the larger view area of the magento product page.
In the product view page, I have more view images when clicked, it shows the image in the larger view, not in default pop up window. I want to call the full size image of whatever the image is loaded in the larger view area. Can someone tell me how do I do it?
I did some search and found
echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(163, 100);
But this gets only the image which was there by default. I want to be able to call any image that comes in the larger view area.
try this code
$this->helper('catalog/image')->init($_product, 'image')
this will get you the image on product view page.
ok I think this might save ur trouble. ITs Damn easy
Lets say ur main image area is <img id="main-image" src="main-image.jpg" />
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a class="grouped_elements" href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(260,null) ?>"
title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" rel="group1">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(70,null) ?>"
width="70" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
</a>
</li>
<script type="text/javascript">
//<![CDATA[
jQuery("a.grouped_elements").click(function(){
$('#main-image').attr('src', this.attr('href'));
});
//]]>
</script>
Hope this should help ...
I think u must check the file
app\design\frontend\base\default\template\catalog\product\view
& its declared as in the
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
this file gives u the Main Image & also the Gallery Images. of course u'll get only enabled images.
so What I understand from the subsequent comments. u need these images in a fancybox. there has to be a slideshow thing previou next etc. right??
ok Here it is what u can do. Create a new file under
app\design\frontend\base\default\template\catalog\product\view\fancy.media.phtml
(or u can use ur theme folder instead of base/default)
in ur catalog.xml add this block under
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
<block type="catalog/product_view_media" name="fancy.media" template="catalog/product/view/fancy.media.phtml"/>
now in media.phtml u'll get all the images & there URLs. code the fancybox & pass the image url to it. &
& yeah don't forget to call this block in ur product page i.e.
app\design\frontend\base\default\template\catalog\product\view.phtml
by echo $this->getChilHtml('fancy.media')
I hope this must solve problem
UPDATE:
try this in fancy.media.phtml:
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a class="grouped_elements" href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(260,null) ?>"
title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" rel="group1">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(70,null) ?>"
width="70" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
</a>
</li>
<?php endforeach; ?>
<script type="text/javascript">
//<![CDATA[
$("a.grouped_elements").fancybox();
//]]>
</script>
Please refer to the Docs of fancybox, fancybox how to
I think ur requirement is if somebody clicks on the More-views on product page it must get open in fancybox. Right?? so u can place this code in media.phtml also. no need to create a new file & no need to edit the catalog.xml.
If u make this working then feel free to accept my answer.
I got the desired result by adding a button on media.phtml
<a class="fullscreen" href="#image" onclick="document.getElementById('image').style.width='100%'; return false; " > <img src="<?php echo $this->getSkinUrl('images/zoom_full.jpg') ?>" alt="<?php echo $this->__('Full Screen') ?>" title="<?php echo $this->__('Full Screen') ?>" /></a>
<script type="text/javascript"> j(document).ready(function() {
j(".fullscreen").fancybox({ 'transitionIn': 'fade', 'transitionOut':
'none', 'overlayColor': '#fff', 'overlayOpacity':1,
'hideOnOverlayClick':false }); </script>