1
<?php
namespace Logicrays\ProductSlider\Block;

use Magento\Catalog\Block\Product\Context;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Reports\Block\Product\Viewed as ReportProductViewed;
use Logicrays\ProductSlider\Helper\Data;

class RecentProducts extends AbstractSlider
{
    protected $reportProductViewed;
    protected $recentlyViewed;
    protected $_layout;

    public function __construct(
        Context $context,
        CollectionFactory $productCollectionFactory,
        Visibility $catalogProductVisibility,
        DateTime $dateTime,
        Data $helperData,
        \Magento\Reports\Block\Product\Viewed $recentlyViewed,
        \Magento\Framework\View\LayoutInterface $layout,
        HttpContext $httpContext,
        ReportProductViewed $reportProductViewed,
        array $data = []
    ) {
        $this->reportProductViewed = $reportProductViewed;
        $this->recentlyViewed = $recentlyViewed;
        $this->_layout = $layout;

        parent::__construct($context, $productCollectionFactory, $catalogProductVisibility, $dateTime, $helperData, $httpContext, $data);
    }

    public function getProductCollection()
    {
        $collection = $this->reportProductViewed->getItemsCollection()->setPageSize($this->getProductsCount());
        //print_r($collection->getData());
        //exit;
        return $collection;
    }
}
  • Try this and check how many products you are getting $this->reportProductViewed->getCount(); Code seems right if $this->getProductsCount() this portion is ok. – Kingshuk Deb Dec 4 '19 at 12:05
  • yes i was try this cart page count:5 and any other page count:0 – Milan Magento2 Developer Dec 4 '19 at 12:08
  • I would suggest you to go to Magento\Reports\Block\Product\AbstractProduct this file. Find this function getItemsCollection and check whats the count for other pages after line no.109 $this->_collection->getCount(). – Kingshuk Deb Dec 4 '19 at 12:17
  • int(2046) found yes – Milan Magento2 Developer Dec 4 '19 at 12:47
  • recent product show customer login needed – Milan Magento2 Developer Dec 4 '19 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.