Showing results for 
Search instead for 
Did you mean: 

Recently viewed products


Recently viewed products

I have made my own theme from the RWD theme and I am displaying recently viewed products on the homepage via:


	$collection = $this->getRecentlyViewedProducts();

<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
   <h2>Your recently viewed</h2>
     <div class="jcarousel-wrapper">
                <div class="jcarousel">
                           <?php foreach ($collection as $_product) {  ?>
                        <li><a href="<?php echo $_product->getProductUrl() ?>">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" alt="" /></a> 
                        <div class="productName">
                        <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a>
                         <?php if($_product->isSaleable()): ?>
                        <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                         <?php }?>

                <a href="#" class="jcarousel-control-prev">&lsaquo;</a>
                <a href="#" class="jcarousel-control-next">&rsaquo;</a>

            <?php else:?>
	             <img src=""/>
<?php endif; ?>

 It all works fine, but obviously when a user hasn't viewed any products, it leaves empty space. So, I would like to have some content appear if no recent viewed products. i have tried as you can see to run a conditional statement, but it does not work. So, how could I if there is no recently viewed products, show an image ? 

Tags (1)

Re: Recently viewed products

I would suggest that as you don't use $_products (you switch back to $collection in your inner loop) that you change the IF statement to


- however, I'm guessing the issue is that this is actually returning something every time. Could you


 and see what it returns?

Re: Recently viewed products

Solved via:

if ($collection->getSize() > 0)

Re: Recently viewed products

In which case, I'm guessing that it was returning an empty array Smiley Happy



Should be enough Smiley Happy