Get Top Rated Products and Order by rating The Next CEO of Stack OverflowHow 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

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Man transported from Alternate World into ours by a Neutrino Detector

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

Creating a script with console commands

Arrows in tikz Markov chain diagram overlap

Masking layers by a vector polygon layer in QGIS

Ising model simulation

Is it possible to make a 9x9 table fit within the default margins?

Salesforce opportunity stages

How to unfasten electrical subpanel attached with ramset

Is a linearly independent set whose span is dense a Schauder basis?

Incomplete cube

Avoiding the "not like other girls" trope?

Free fall ellipse or parabola?

Can a PhD from a non-TU9 German university become a professor in a TU9 university?

How dangerous is XSS

Calculate the Mean mean of two numbers

Finitely generated matrix groups whose eigenvalues are all algebraic

Another proof that dividing by 0 does not exist -- is it right?

How can a day be of 24 hours?

Are British MPs missing the point, with these 'Indicative Votes'?

Strange use of "whether ... than ..." in official text

Direct Implications Between USA and UK in Event of No-Deal Brexit

My boss doesn't want me to have a side project



Get Top Rated Products and Order by rating



The Next CEO of Stack OverflowHow 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 14 hours ago







      Magecode

















      asked 14 hours ago









      MagecodeMagecode

      539421




      539421




















          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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form