1

Does anyone know how to order by views (ascending/descending) a product collection when working with most viewed products?

I am using this following code:

$_productCollection = Mage::getResourceModel('reports/product_collection')
        ->addViewsCount($from, $to)
        ->addAttributeToFilter('entity_id', $productIds)
    ;

I am getting the most viewed product in a time range but always the collection is ordered descending mainly because method addViewsCount() orders collection views descending.

In file /app/code/core/Mage/Reports/Model/Product/Collection.php (line 375)

    ->order('views ' . self::SORT_ORDER_DESC)

I would like to order my collection by views, ascending and descending, but views is not an attribute to use in setOrder() method.

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.