To do this programmatically, you need the collection function to get called in custom phtml file so that the product will be shown in the file.
Let’s say we have a module which is named “Magemonkeys_Recentlyview”
For that module, we have to create a block file Recentlyview.php at app/code/Magemonkeys/Recentlyview/Block/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
namespace Magemonkeys\Recentlyview\Block; class Recentlyview extends \Magento\Framework\View\Element\Template { protected $recentlyView; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Reports\Block\Product\Viewed $recentlyView, array $data = [] ) { $this->recentlyView = $recentlyView; parent::__construct($context, $data); } public function getRecentviewCollection() { return $this->recentlyView->getItemsCollection()->load(); } } |
Now we can call that block function in custom phtml file
create app/code/Magemonkeys/Recentlyview/view/recentlyview.html file
1 2 3 4 5 |
$productviewcollection = $this->getRecentviewCollection(); foreach ($productviewcollection as $recentlyview) { echo $recentlyview->getName(); } |
Now check the result by clearing the cache.
[crayon-63e09f81f1659782506027/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.