Magento get images that are only in stock - magento

I need to list thumbnail images that are only in stock but i cant find the way to insert the filter to say addAttributeToFilter('is_saleable', TRUE) to the next code.
The structure of product:
2 Options
Color and Size
All sku's are associated to the configurable product, and Gallery image have the Color Label that Match with the Color form Option.
When you open the Configurable product in product view page, this show a dropdown or checkbox form, that allow you to select the Color first then Show all Sizes in stock. But in the dropdown show only Colors that are in stock.
Example:
Red => S,M,L
Blue => L,XL
Yellow => S
Gray => Not in stock, not in the dropdown.
Is there any way to insert a filter to skip images colors that are not saleable or in stock?
<?php $_gallery = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php $imgcount = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages()->count();?>
<?php if($imgcount >1): ?>
<div class="more-views">
<a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo html_entity_decode($_helper->productAttribute($_product, $_product->getName(), 'name')); ?> <?php // echo $this->htmlEscape($_image->getLabel()) ?>">
<img style="padding-top:2px;" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(33, 31); ?>" width="33" height="31" alt="<?php echo html_entity_decode($_helper->productAttribute($_product, $_product->getName(), 'name')); ?> <?php echo $this->htmlEscape($_image->getLabel()); ?>" title="<?php echo html_entity_decode($_helper->productAttribute($_product, $_product->getName(), 'name')); ?> <?php echo $this->htmlEscape($_image->getLabel()); ?>" />
</div>
<?php endif; ?>

Related

Product images are serving from different paths on Product detail page and in sitemap

Product images are serving from different paths in view page & in sitemap.
1) product view page : media/catalog/product/W/i/image-name.jpg : link1
2) http://sitename.com/media/sitemap.xml : media/product/ee7/image-name.jpg : link2
but i want product images should serve from same path in both links:
media.phtml
<?php
$_product = $this->getProduct();
$_helper = $this->helper('catalog/output');
$dexxtz = Mage::helper('productzoom');
$dexxtz->getCss();
$dexxtz->getJs();
?>
<ul id="etalage">
<li>
<img class="etalage_thumb_image"
src="<?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl($_product->getImage()); ?>" />
<img class="etalage_source_image" title="<?php echo $_product->getImageLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image'), true); ?>" />
</li>
<?php
foreach ($this->getGalleryImages() as $_image) {
if(Mage::registry('current_product')->getImage() != $_image->getFile()) { ?>
<li>
<img class="etalage_thumb_image" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())); ?>" />
<img class="etalage_source_image" title="<?php echo $_image->getLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()), true); ?>" />
</li>
<?php
}
}
?>
</ul>
For delivering images in the frontend you should always use this call <?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getSmallImage()); ?> as it utilizes the Magento cache, if enabled.
Definately not default Magento is this path media/product/ee7/image-name.jpg - all product media related stuff is in media/catalog/product. It might be that you have an extension that uses media/product to store and server images - but this is not default Magento.
Please check your extensions, especially how the links in the sitemap are created.

Check If Magento Product Has Thumbnail

I want to display a thumbnail image on a product page only if it exists. Currently it shows the placeholder image if a thumbnail image is not selected. I suppose I need to just wrap that around an if statement but do not know the method (if there is one) to check if the thumbnail image exists. Here is the code used to display the thumbnail:
<img id="slide-img-1" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(163, 100); ?>" /></a>
Use the following:
<?php if(!($_item->getThumbnail() == "no_selection")): ?>
<div class="image-holder">
<img class="thumbnail-image"
src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->constrainOnly(true)->resize(800); ?>"
alt=""
title="" />
</div>
<?php endif; ?>
If a thumbnail exists for the product then it should be set on the $_product instance. So you can use that in your condition, see below.
<?php if($_product->getThumbnail()): ?>
<img id="slide-img-1" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(163, 100); ?>" /></a>
<?php endif; ?>

How to limit amount of product thumbnail images in Magento product page

In Magento, does anyone know how to limit the amount of thumbnails to be shown under the main product image?
Is this something that is easily controlled via the admin or should I go into media.phtml and edit the php?
<div class="more-views">
<ul>
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" title="<?php echo $_product->getName();?>" onclick="$('image').src = this.href; return false;">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(103, 103); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"/>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
The quickest way would be
<div class="more-views">
<ul>
<?php $limit = 5; ?>
<?php $ct = 0; ?>
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" title="<?php echo $_product->getName();?>" onclick="$('image').src = this.href; return false;">
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(103, 103); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"/>
</a>
</li>
<?php
if(++$ct >= $limit)
break;
?>
<?php endforeach; ?>
</ul>
</div>
Yes, you can easily control via the admin, which images you want to show under the main product image, but you need to set for all the products individually.
Simply go to images tabs of add/edit product. click on the exclude checkbox which you don't want to show on image gallery and then hit the save button.

How to call product information?

I am trying to get a static block to pull information. Using Magento 1.7 CE.
In the static box I am using the following code:
<div>{{block type="catalog/product_list" category_id="6" template="catalog/product/listmenu.phtml"}}</div>
I want this to display the product name, price, and image... What do I list in the listmenu.phtml so it pulls the correct information?
Given that the block type is "catalog/product_list", you can access the functionality of the block Mage_Catalog_Block_Product_List, i.e. a product collection loaded by the category id. So the approximate code outputting a list of products and their names, images, and prices would be:
<?php
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product): ?>
<div>
<h4><?php echo $this->stripTags($_product->getName());?></h4>
<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) ?>" />
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
<?php endforeach; ?>

Magento: Display all images on the product page (view.phtml)

I can see how media.phtml (with Cloud Zoom extension) is listing all the images on the product page by help of $this->getGalleryImages():
<?php foreach ($this->getGalleryImages() as $_image): ?>
<?php ... ?>
<?php endforeach; ?>
But when I use $this->getGalleryImages() in view.phtml which is the catalog product page template, it doesn't return or output anything. However, this would only print the first image on the product page:
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->setWatermarkImageOpacity(0)->resize(300, null);?>" alt="<?php echo $this->htmlEscape($this->getImageLabel());?>" title="<?php echo $this->htmlEscape($this->getImageLabel());?>" />
My question is how can I iterate through and display all the product images on the product page (view.phtml, not media.phtml)? Basically, I want them all on display on the page without thumbnailing or zooming or anything, just plain big images, one after another.
Thanks!
Here is the code for showing product image gallery..
Thanks,
Jeet
<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>
<?php $i=0; foreach($_images as $_image){ $i++; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(108,90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php } ?>
<?php } ?>

Resources