1

I am using the the Recently viewed products reporting on my basket page.

<?php echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>

Is it possible to exclude items that are contained in the cart from this report?

This is the full code for that report:

<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
<div class="block block-list block-viewed">
    <div class="block-title">
        <h2 style="margin-top:1.2rem;"><?php echo $this->__('Have you considered?') ?></h2>
    </div>
    <div class="block-content">
        <ul id="recently-viewed-items" class="recently-products-list">
        <?php foreach ($_products as $_item): ?>
            <li class="item">
                <div class="product">
                    <div class="product-image">
                        <a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_item->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(300) ?>" alt="<?php echo $this->escapeHtml($_item->getName()) ?>" /></a>
                    </div>
                    <div class="product-details">
                        <div class="product-info-top">
                        <h3 class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></a></h3>
                        <div class="sku"><?php echo $_item->getSku(); ?></div>
                        </div>
                        <?php echo $this->getPriceHtml($_item, true, '-related') ?>
                        <div class="actions">
                        <?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
                            <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Basket')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Basket') ?></span></span></button>
                            <?php else : ?>
                        <?php endif; ?>
                        </div>
                    </div>
                </div>
            </li>
        <?php endforeach; ?>
        </ul>
    </div>
</div>
<?php endif; ?>
0

Try the below code instead of yours:

<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
    <?php $cart = Mage::getSingleton('checkout/session')->getQuote(); ?>
    <?php $cartProductIds = array(); ?>
    <?php foreach ($cart->getAllVisibleItems() as $item): ?>
        <?php $cartProductIds[] = $item->getProduct()->getId(); ?>
    <?php endforeach; ?>
    <div class="block block-list block-viewed">
        <div class="block-title">
            <h2 style="margin-top:1.2rem;"><?php echo $this->__('Have you considered?') ?></h2>
        </div>
        <div class="block-content">
            <ul id="recently-viewed-items" class="recently-products-list">
            <?php foreach ($_products as $_item): ?>
                <?php if(!in_array($_item->getEntityId(), $cartProductIds)): ?>
                    <li class="item">
                        <div class="product">
                            <div class="product-image">
                                <a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_item->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(300) ?>" alt="<?php echo $this->escapeHtml($_item->getName()) ?>" /></a>
                            </div>
                            <div class="product-details">
                                <div class="product-info-top">
                                <h3 class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></a></h3>
                                <div class="sku"><?php echo $_item->getSku(); ?></div>
                                </div>
                                <?php echo $this->getPriceHtml($_item, true, '-related') ?>
                                <div class="actions">
                                <?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
                                    <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Basket')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Basket') ?></span></span></button>
                                    <?php else : ?>
                                <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </li>
                <?php endif; ?>
            <?php endforeach; ?>
            </ul>
        </div>
    </div>
<?php endif; ?>
  • Happy to help! When you reach 15 then upvote please. – Sukumar Gorai Jun 27 '18 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.