Magento: Displaying product image in order email - image

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.

Related

Magento Category Images are all blurry after changing size within list.phtml

http://www.rattanfurnitureuk.co.uk/sept2015/rattan-corner-sets.html
I have deleted the cache on the service but the images are still rendering blurry.
The images should be sharp and at 276 x 276px
In your Magento admin navigate to:
System > Configuration > Catalog > Product Image
Update the Small Image Width field to 276px. Then flush image cache and refresh full page cache.
Go to following location and open list.phtml file.
app\design\frontend\yourpackage\yourtheme\template\catalog\product\
and find the following line
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
In this code check
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135"
Try changing resize(135) and height and width also in above mentioned line.
Update:
You have following html in your site.
<a class="product-image" title="Maze Rattan - Winchester Square Corner Group" href="http://www.rattanfurnitureuk.co.uk/sept2015/rattan-corner-sets/maze-rattan-winchester-square-corner-group.html">
<img width="135" height="135" alt="Maze Rattan - Winchester Square Corner Group" src="http://www.rattanfurnitureuk.co.uk/sept2015/media/catalog/product/cache/1/small_image/135x/9df78eab33525d08d6e5fb8d27136e95/3/1/3198.jpg">
</a>
Check what is there in <img tag.

How to remove loading product images from cache in magento?

Due to some problems product images in cache folder turned empty (file is there but empty).Magneto loads product images from cache folder only.
For example: http://example.com/media/catalog/product/cache/54/small_image/295x295/9df78eab33525d08d6e5fb8d27136e95/b/r/br7462vi_1.png
here br7462vi_1.png turned empty.(0 bytes).
but http://example.com/media/catalog/product/b/r/br7462vi_1.png works fine.
How can I stop magento loading product images from cache?
No need to worry. Simply Login to admin panel.
Goto Admin ->System ->Cache management click on Flush Catalog Images Cache
And also flush all magento cache.
Now all image urls should work.
If you have still problem then just give 777 permission on media/catalog/product directory.
I hope it works.
Replace this from list.phtml and all your custome template where you want to load from main media folder
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(236,193); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
With This Code:
<img width="236" height="193" id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getSmallImage()); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
it only for grid mode you can change for list mode also and product details page medai.pthml file only change on this file src tag src="<?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getSmallImage()); ?>"
Reference: How to remove the cache url for product images in magento

Magento new products are not showing in homepage

In magento I want to show new products in my home page. So to do that I have searched many blogs and forums. From all of them I have got that by using
{{block type="catalog/product_new" block_id="new.products" template="catalog/product/new.phtml"}}
in CMS -> Homepage content I will get the new products. But still I am not getting any products. Also I have tried to change the date active . But it is not showing any products. So can someone kindly tell me what is the issue here? Any help and suggestions will be really appreciable. Thanks
In default Magento implementation of catalog/product_new block the rules are:
the product should be visible in catalog
the product should have both news_from_date and news_to_date attributes set to some values
attribute news_from_date works till end of today's date (23:59:59) and attribute news_to_date works from the begin of today's date (00:00:00)
When there be at least one product that meet that requirements the block will be rendered. Also flushing your cache and reindexing data could help as well.
Just in case you end up here, there is another simple fix to try:
System -> Index Management
and select them all (even if they are indicating "Green, no re-index needed" and force them to reindex.
This solved my empty getSize() problem, which in turn, allowed the Special and New database requests to find the products, fulfill the "if" conditions and properly render.
try this
write following code in cms->page->design tab->Layout Update XML
<reference name="content">
<block type="catalog/product_list" name="featured" template="catalog/product/new.phtml">
</block>
</reference>
you have to add new.phtml file in "app\design\frontend\default\default\template\catalog\product"
write following code in new.phtml file
<?php
/******************
//Recently Added Products
************************/
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4))
->setOrder('created_at', 'desc');
?>
<div style="clear: both;"></div>
<div id="block">
<div class="text">Recently Added Products
View more »
</div>
</div>
<?php foreach($_productCollection as $_product) : ?>
<div class="grid">
<div class="imgholder" >
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
</div>
<strong><?php echo $_product->getName(); ?></strong>
<p><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></p>
<div class="price">
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</div>
<?php endforeach; ?>
You can also display it using Widget. I mean by adding widget in CMS homepage.
I had this probalem and spoke to an agent who took control of it for me and worked it out as explaining it didnt help. You need to put all the nav categories into the highest root category (so all categories will look like subcategories of the first root which you cannot delete. They must not be or be stemming from any paralell root categories. Then refresh your index and the category items will be there in the nav menu.

How to add product thumbnail image to order review page in Magento?

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.

Magento display multiple product images on details page

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.

Resources