I’m looking to create a Magento 2 module that displays recently viewed products on the storefront. I want to achieve something similar to the standard Magento widget (Last Viewed Products), but instead of using listing.html, I’d like to render the products directly in a custom phtml file.
Here are my questions:
-
Which classes/models in Magento 2 should I use to fetch the list of recently viewed products?
-
How can I retrieve this data and pass it to a block for use in the phtml template?
-
Are there any best practices I should follow when implementing such a module?
-
How can I handle caching to ensure the data updates dynamically as users browse?
I’d like a more custom solution rather than relying on built-in widgets to have complete control over the code in the phtml file.
Thanks in advance for any tips or guidance!