Magento2: Error: Call to undefined method addViewsCount()

by Masud Shaikh   Last Updated August 13, 2019 16:09 PM

I have got the error below:

Error: Call to undefined method Magento\Catalog\Model\ResourceModel\Product\Collection\Interceptor::addViewsCount()

public function getMostViewProductCollection()
{
    $currentStoreId = $this->_storeManager->getStore()->getId();

    // get today and last 30 days time
    $today = time();
    $last = $today - (60*60*24*30);

    $from = date("Y-m-d", $last);
    $to = date("Y-m-d", $today);

    $collection = $this->_productCollectionFactory->create()
        ->addAttributeToSelect(
            '*'
        )->addViewsCount()->setStoreId(
            $currentStoreId
        )->addStoreFilter(
            $currentStoreId
        )->setPageSize(10);
    $items = $collection->getItems();
    return $items;
}

I want to get the most-view product collection. Please help me in this.



Related Questions


Updated March 07, 2018 08:09 AM

Updated July 06, 2018 10:09 AM

Updated April 28, 2015 21:04 PM

Updated June 13, 2017 18:09 PM

Updated August 06, 2015 17:04 PM