Question

I want to show recently searched products on homepage without using Recently Viewed Products Widget I want to get this in my custom block and also want to show this in my custom .phtml file how it would be possible?

Was it helpful?

Solution

Please create a static block with the following code

{{widget type="Magento\Catalog\Block\Widget\RecentlyViewed" uiComponent="widget_recently_viewed" page_size="5" show_attributes="name,image,price,learn_more" show_buttons="add_to_cart,add_to_compare,add_to_wishlist" template="product/widget/viewed/grid.phtml" type_name="Recently Viewed Products"}}

Now, Call that static block in your phtml

<?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('recently_viewed')->toHtml(); ?>

You can manage it via XML using following way.

<!-- Configured recently viewed products block -->
<block class="Magento\Catalog\Block\Widget\RecentlyViewed" name="recently_viewed" template="Magento_Catalog::product/widget/viewed/grid.phtml" after="-">
    <arguments>
        <argument name="uiComponent" xsi:type="string">widget_recently_viewed</argument>
        <argument name="page_size" xsi:type="number">5</argument>
        <!-- 'Product attributes to show' configuration -->
        <argument name="show_attributes" xsi:type="string">name,image,price,learn_more</argument>
        <!-- 'Buttons to show' configuration -->
        <argument name="show_buttons" xsi:type="string">add_to_cart,add_to_compare,add_to_wishlist</argument>
    </arguments>
</block>

Please clear cache and view some product pages, so the viewed product will where you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top