
Description
In magento admin dashboard no products are showing in most viewed product grid if all product are in different attribute sets (not in default attribute set), even with magento sample data this grid is always displaying "We couldn't find any records.".
Preconditions
- Magento ver. 2.1.5 with sample data
- PHP Version 7.0.8
Steps to reproduce
- Login to Customer Account
- Visited Product "Minerva LumaTech™ V-Tee"
- Login to magento admin panel
- Check magento dashboard "Most Viewed Product" grid
Expected result
There should be a row for product "Minerva LumaTech™ V-Tee" as shown in the attached screenshot.
Actual result
But no product is showing in the grid as shown in the attached screenshot.
Reason
This result is coming from \Magento\Reports\Model\ResourceModel\Product\CollectionFactory and in this file setProductAttributeSetId set as default attribute set id as given below-
$this->setProductAttributeSetId($product->getEntityType()->getDefaultAttributeSetId()); at line no. 121, that's why results are not showing for most viewed product if they have added in different attribute sets.
There should not use attribute set id to filter most viewed product collection at line no. 323-326.
So method "addViewsCount" of file \Magento\Reports\Model\ResourceModel\Product\Collection should be defined as given below.
`
public function addViewsCount($from = '', $to = '')
{
/**
* Getting event type id for catalog_product_view event
*/
$eventTypes = $this->_eventTypeFactory->create()->getCollection();
foreach ($eventTypes as $eventType) {
if ($eventType->getEventName() == 'catalog_product_view') {
$productViewEvent = (int)$eventType->getId();
break;
}
}
$this->getSelect()->reset()->from(
['report_table_views' => $this->getTable('report_event')],
['views' => 'COUNT(report_table_views.event_id)']
)
->join(
['e' => $this->getProductEntityTableName()],
'e.entity_id = report_table_views.object_id'
)
->where(
'report_table_views.event_type_id = ?',
$productViewEvent
)->group(
'e.entity_id'
)->order(
'views ' . self::SORT_ORDER_DESC
)->having(
'COUNT(report_table_views.event_id) > ?',
0
);
if ($from != '' && $to != '') {
$this->getSelect()->where('logged_at >= ?', $from)->where('logged_at <= ?', $to);
}
return $this;
}`