Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

moving image thumbnails from media.phtml to view.phtml
 
raffi vitis
Jr. Member
 
Total Posts:  11
Joined:  2008-08-26
 

i would like to move the thumnail images from the media.phtml file into the view .phtml file.
the reason i want to do it is that I want to show the various colors available for the product below the product header.
they are no longer there as links but just to show the various options in thumbnail view.

the code for showing the thumbnails is the following and it resides in template/catalog/product/view/media.phtml

<?php if (count($this->getGalleryImages()) > 0): ?>
<div class="more-views">
    <
h4><?php echo $this->__('More Views'?></h4>
    <
ul>
    
<?php foreach ($this->getGalleryImages() as $_image): ?>
        
<li>
            <
a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
        </
li>
    
<?php endforeach; ?>
    
</ul>
</
div>
<?php endif; ?>

when i mote this section of code into template/catalog/product/view.phtml the page no longer works and shows errors.
any ideas what the problem is?

(i have attached two files showing how it looks now and how i would like the design to be)

Image Attachments
ScreenHunter_01 Dec. 13 19.36.gifScreenHunter_01-Dec.-13-19.36-after.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

You can’t just move code from one block to another. getGalleryImages is a function of the media block, not the product view block.

However, you can just move <?php echo $this->getChildHtml('media') ?> in view.phtml.

 
Magento Community Magento Community
Magento Community
Magento Community
 
raffi vitis
Jr. Member
 
Total Posts:  11
Joined:  2008-08-26
 

yes Anders, I thought that would be the problem.
I could maybe alter the core files to get this to work, which is something i am not keen on doing.
since my knowledge of php is small i thought maybe there is a way to call the function getGalleryImages from the view file.

any ideas?

ok, i thought about 5 minutes more and got to a solution
i moved <div class="product-img-box"> from the view.phtml file into the media.phtml file.

but i would still love to know how to call the function (getGalleryImages in this case) outside of the media.phtml.

raffi.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

In the product view block, I guess you could call $_product->getMediaGalleryImages()

 
Magento Community Magento Community
Magento Community
Magento Community
 
Skeuds
Member
 
Avatar
Total Posts:  53
Joined:  2008-04-15
 

Hi,

I reopen this post because i’m searching for a similar things.

I explain :

I’m working on a file outside Magento and i try to retrieve all the images of a product. I can retrieve the base image but not the others.

This is my code :

require_once 'app/Mage.php';
umask(0);
Mage::app();

$storeId 1;

$className Mage::getConfig()->getBlockClassName('catalog/product');
$block = new $className();

$product    Mage::getModel('catalog/product');

$todayDate  $product->getResource()->formatDate(time());
$products   $product->setStoreId($storeId)->getCollection()
    ->
addAttributeToSelect(array('name''price''small_image'), 'inner')
    ->
addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left')
    ->
addAttributeToSelect('status')
    ->
addAttributeToSelect('image')
;
$products->getSelect()->order('rand()');

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

$block->setProductCollection($products);

then i display my product :

foreach ($_products->getItems() as $_product)
    
{
        
echo 'Product name : '.$_product->getName();
        echo 
'Product base image : '.$block->helper('catalog/image')->init($_product'image');
    
}

And i can’t retrieve all the product’s image. I have try with :

echo count$_product->getMediaGalleryImages() );

But it always return 0 (and my product has for example 4 images not excluded)

If you have an idea.

Thanx smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jacek Sompel
Jr. Member
 
Total Posts:  8
Joined:  2009-05-17
Melbourne, Australia
 

Hi,

Moving the More views block to another block was really doing my head in and eventually I had to give up on it as anything I was doing seemed to work.
What I did in the end, I simply used jQuery to move it for me to whereever I wanted that block to display.
Here is the code I added to media.phtml:

<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function(){
        jQuery
(".product-shop").append(jQuery(".more-views"));
});
//]]>
</script>

Yes I know it’s not as elegant as it could be using the normal block arrangement in Magento xml files, but I simply had not time to spend on getting it working that way. At the same time because the site I was building for a client required jQuery it didn’t matter in the end.

Please note that you still need to load your jQuery js file in the head.phtml or add it through the xml files. Also you will need to use jQuery var noConflict() function to avoid Prototype and jQuery $ conflict.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
     
var $j jQuery.noConflict();
//]]>
</script>
I am still interested to see how anyone successfully moved the “More views” to other blocks eg. product-shop

Hope this helps.

Jacek
http://itelligence.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top