1

I want to get Top Rated Products collection and sort it by ratings. I'm using the code but not working.

$collection->getSelect()->joinLeft(
                        'rating_option_vote_aggregated',
                        'e.entity_id = rating_option_vote_aggregated.entity_pk_value',
                        array('vote_count' => 'SUM(rating_option_vote_aggregated.vote_count)'))
                ->group('e.entity_id')
                ->order('vote_count ' . $this->getCurrentDirectionReverse());

[2019-04-01 12:51:58] main.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'vote_count ' in 'order clause', query was: SELECT e.*, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS status, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS visibility, SUM(rating_option_vote_aggregated.vote_count) AS vote_count, stock_status_index.stock_status AS is_salable FROM catalog_product_entity AS e INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 INNER JOIN catalog_product_entity_int AS at_status_default ON (at_status_default.entity_id = e.entity_id) AND (at_status_default.attribute_id = '97') AND at_status_default.store_id = 0 LEFT JOIN catalog_product_entity_int AS at_status ON (at_status.entity_id = e.entity_id) AND (at_status.attribute_id = '97') AND (at_status.store_id = 1) INNER JOIN catalog_product_entity_int AS at_visibility_default ON (at_visibility_default.entity_id = e.entity_id) AND (at_visibility_default.attribute_id = '99') AND at_visibility_default.store_id = 0 LEFT JOIN catalog_product_entity_int AS at_visibility ON (at_visibility.entity_id = e.entity_id) AND (at_visibility.attribute_id = '99') AND (at_visibility.store_id = 1) LEFT JOIN rating_option_vote_aggregated ON e.entity_id = rating_option_vote_aggregated.entity_pk_value INNER JOIN cataloginventory_stock_status AS stock_status_index ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 WHERE (IF(at_status.value_id > 0, at_status.value, at_status_default.value) = '1') AND (IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) = '4') AND (stock_status_index.stock_status = 1) GROUP BY e.entity_id ORDER BY vote_count ASC LIMIT 8 [] []

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.