I need to get recently viewed products for a customer in a product view but excluding the current product the customer is viewing. I have,
class Index extends Action
{
protected $recentlyViewed;
public function __construct(
Context $context,
\Magento\Reports\Block\Product\Viewed $recentlyViewed
)
{
parent::__construct($context);
$this->recentlyViewed = $recentlyViewed;
}
public function execute()
{
$recentProducts = $this->recentlyViewed->getItemsCollection()->getData();
}
}
This $recentProducts returns particular number of recently viewed products based on the admin configuration. For example, if the limit of recent products is 5, this returns 5 products. But I need 5 products excluding current product.
How can I exclude a particular product by providing it's ID?
Thanks in advance.