Approach One
- Login to Admin panel
- Click on Content -> Blocks
- Create new product-detail block and edit then toggle show/hide editor which will show insert widget option
- Click on insert widget select "Recently Viewed Products" from dropdown, add number of product to display (ex - 5)
- Select template from dropdown then click on insert widget
- Click on save Block
Although <p>{{widget type="Magento\Catalog\Block\Widget\RecentlyViewed" uiComponent="widget_recently_viewed" page_size="5" show_attributes="name,image,price" show_buttons="add_to_cart" template="product/widget/viewed/grid.phtml"}}</p>
works in home-page block
Approach Two
For testing purpose added below code in vendor/magento/theme-frontend-luma/Magento_Catalog/layout/catalog_product_view
<block class="Magento\Reports\Block\Product\Widget\Viewed" after="-" name="recently_viewed" cacheable="false" template="Magento_Reports::widget/viewed/content/viewed_grid.phtml">
<action method="setPageSize">
<argument name="page_size" xsi:type="number">5</argument>
</action>
Final code for catalog_product_view
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="page.main.title" destination="product.info.main" before="-"/>
<move element="product.info.stock.sku" destination="product.info.price" after="product.price.final"/>
<move element="product.info.review" destination="product.info.main" before="product.info.price"/>
<block class="Magento\Reports\Block\Product\Widget\Viewed" after="-" name="recently_viewed" cacheable="false" template="Magento_Reports::widget/viewed/content/viewed_grid.phtml">
<action method="setPageSize">
<argument name="page_size" xsi:type="number">5</argument>
</action>
</block>
</body>
</page>
Did reindexing and cleared cache too but both the above approaches are not working.
- How could I make this work and show recently viewed products block on product detail page ?
- Does Magento 2 supports
local.xml
just like earlier mage versions ?