Get Top Rated Products and Order by ratingHow to add more attributes to product collectionJoin table to product/catalog collection to display new custom column in catalog grid`getLastPageNumber()` returning wrong number of pagesCan't get “products ordered” collection with configurable products included (top 10 products)Programatically get product rating and review in magento 2 product collectionMagento 2 How to get product collection of all products?Problem creating part numbersMagento more than 61 product attribute database tables in join queryHow to add .5 rating for products magento?Custom Customer attribute grid not filter by asc or dec

Am I breaking OOP practice with this architecture?

What method can I use to design a dungeon difficult enough that the PCs can't make it through without killing them?

CAST throwing error when run in stored procedure but not when run as raw query

What killed these X2 caps?

Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?

Detention in 1997

How to show a landlord what we have in savings?

Apex Framework / library for consuming REST services

Do scales need to be in alphabetical order?

How to tell a function to use the default argument values?

How do conventional missiles fly?

Can I run a new neutral wire to repair a broken circuit?

Plagiarism or not?

Why is this clock signal connected to a capacitor to gnd?

Avoiding direct proof while writing proof by induction

Is "remove commented out code" correct English?

Gatling : Performance testing tool

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures

How do I know where to place holes on an instrument?

Could the museum Saturn V's be refitted for one more flight?

How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)

How to compactly explain secondary and tertiary characters without resorting to stereotypes?



Get Top Rated Products and Order by rating


How to add more attributes to product collectionJoin table to product/catalog collection to display new custom column in catalog grid`getLastPageNumber()` returning wrong number of pagesCan't get “products ordered” collection with configurable products included (top 10 products)Programatically get product rating and review in magento 2 product collectionMagento 2 How to get product collection of all products?Problem creating part numbersMagento more than 61 product attribute database tables in join queryHow to add .5 rating for products magento?Custom Customer attribute grid not filter by asc or dec













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 [] []











share|improve this question




























    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 [] []











    share|improve this question


























      1












      1








      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 [] []











      share|improve this question
















      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 [] []








      magento2.2 product-collection






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago







      Magecode

















      asked 2 days ago









      MagecodeMagecode

      544421




      544421




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268207%2fget-top-rated-products-and-order-by-rating%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268207%2fget-top-rated-products-and-order-by-rating%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Sum ergo cogito? 1 nng

          419 nièngy_Soadمي 19bal1.5o_g

          Queiggey Chernihivv 9NnOo i Zw X QqKk LpB