Question

We use a custommenu.phtml to show recently view items via a popup block.

<div id="pt_menu_pt_item_menu_4" class="pt_menu">
    <div class="parentMenu">
        <span class="block-title">Recently Viewed</span>
    </div>

    <div id="popup_pt_item_menu_4" class="popup cmsblock" style="display: none;">
        <div class="block3" id="block2_pt_item_menu_4">
            <div>
                <?php echo $this->getLayout()->createBlock('reports/product_widget_viewed')->setTemplate('reports/widget/viewed/content/viewed_grid.phtml')->toHtml(); ?>
            </div>
        </div>
    </div>
</div>

Everything works great except we do not need the whole <div>to show when these is no recently viewed product.

I tried wrapping the whole div with the following:

<?php if ($_products = $this->getRecentlyViewedProducts()): ?>

<?php endif>

but the whole div disappears whether we have viewed products or not.

How do I achieve this?

Was it helpful?

Solution

Try with the condition

<?php if($products = Mage::getSingleton('Mage_Reports_Block_Product_Viewed')->getItemsCollection()): ?>
<?php endif; ?>

Refernce: https://stackoverflow.com/questions/11413918/get-recently-viewed-products-array-in-magento

OTHER TIPS

the following code does the trick, just for the records.

<?php $products = Mage::getSingleton('Mage_Reports_Block_Product_Viewed')->getItemsCollection(); ?>
<?php if(count($products)>0): ?>


<?php endif?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top