Skip to content

Admin dashboard Most Viewed Products Tab only gives default attribute set's products #9768

Closed
@ghost

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

  1. Magento ver. 2.1.5 with sample data
  2. PHP Version 7.0.8

Steps to reproduce

  1. Login to Customer Account
  2. Visited Product "Minerva LumaTech™ V-Tee"
  3. Login to magento admin panel
  4. 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.
screenshot_2

Actual result
But no product is showing in the grid as shown in the attached screenshot.
screenshot_3

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;
}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.1.xThe issue has been fixed in 2.1 release lineFixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentProgress: needs updateReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions