magento2: Recently viewed products block not working in product page with enabled cache

Steps to reproduce

  1. add: <block class="Magento\Reports\Block\Product\Widget\Viewed" page_size="4" name="recently_viewed" template="widget/viewed/content/viewed_grid.phtml" cacheable="false" /> to catalog_product_view.xml in any container

Expected result: With enabled cache you should see recently viewed products block in product page.

Actual result: Block is visible only with disabled cache, when cache is enabled, it does not have output.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 36 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @slavvka,

Please keep the 2.1.x issues open until the fix is backported to 2.1-develop If there isn’t a backport scheduled via an internal MAGETWO task, please mark the issue with an up for grabs label so that anyone from the community was able to notice it and make a backport PR voluntarily.

@dhduc Doesn’t that stop the whole page from being cached though? I’m sure I’ve heard that a few times, and if so that is a terrible workaround as the side effect is potentially worse than the initial issue.

Edit: It does stop the whole page from being cached:

To create an uncacheable page, mark any block on that page as uncacheable in the layout using cacheable=“false”.

Source - http://devdocs.magento.com/guides/v2.1/config-guide/cache/cache-priv-over.html

issue is still exists in magento 2.3.1 when cache is enable then recently products is not showing Anyone know how to solve this ?

@dan-advantec and @crantron - Have you tried adding a product to bag?

For some weird reason recently viewed products will only load once a product has been added to bag, I can replicate this on two completely separate production websites.

Any update on this @magento-engcom-team? Should we create a new issue?

what is wrong with using:

`<?php /**

  • Copyright © 2013-2017 Magento, Inc. All rights reserved.
  • See COPYING.txt for license details. */

namespace Magento\Reports\Block\Product;

use \Magento\Framework\DataObject\IdentityInterface;

/**

  • Reports Recently Viewed Products Block

  • @author Magento Core Team core@magentocommerce.com */ class Viewed extends AbstractProduct implements IdentityInterface { protected function _construct() { $this->addData(array(‘cache_lifetime’ => false)); }

    /**

    • Config path to recently viewed product count */ const XML_PATH_RECENTLY_VIEWED_COUNT = ‘catalog/recently_products/viewed_count’;

`

Internal ticket to track issue progress: MAGETWO-66615