Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Sort Order Of Rating Block On Homepage? Rate Topic   - - - - -

 
  • thecigarhut
  • Advanced Member
  • Members
  • Join Date: 07-Dec 21
  • 73 posts

Posted 18 June 2022 - 11:20 PM #1

I have a block on the homepage and the filling is set to "Rating"

Works but problem is that it lists products by rating then alphabetically and completely ignores those products with hundreds of reviews, but instead lists all the 5 star reviews 1st regardless of 1 or 2 reviews only.

I want to change it to sort by # of reviews instead of alphabetical

 

I found this bit of code that does it but not the code that is used for the block filling "Rating"

 

/app/addons/product_reviews?func.php

    $params['sort_by'] = 'rating';
    $params['sort_order'] = 'desc';
    $sortings['rating'] = ['average_rating', 'product_reviews_count'];

In a nutshell, I want a product with 4.6 stars and 100+ ratings to appear in the block before a 5 star with just 1 review

Does anyone know where the function is located that produces the block filling type "Rating"?


osCommerce user since 2005 now upgrading to CS-Cart Ultimate.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22892 posts

Posted 20 June 2022 - 05:49 AM #2

Do you use old or new module for product reviews?


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 1210     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 4025     CS-Cart + YOUPI      USD 1459      Multi-Vendor Ultimate       USD 7500 (6000)


 
  • thecigarhut
  • Advanced Member
  • Members
  • Join Date: 07-Dec 21
  • 73 posts

Posted 21 June 2022 - 02:40 AM #3

Do you use old or new module for product reviews?

 

was using the new version but have since installed CP Power Reviews so the ratings are being added into the cscart_discussion_ group of tables as opposed to the cscart_product_reviews tables


osCommerce user since 2005 now upgrading to CS-Cart Ultimate.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22892 posts

Posted 21 June 2022 - 07:27 AM #4

So you should alter the fn_discussion_get_products function

 

Add extra field to calculate posts amount and add it to sorting


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 1210     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 4025     CS-Cart + YOUPI      USD 1459      Multi-Vendor Ultimate       USD 7500 (6000)


 
  • thecigarhut
  • Advanced Member
  • Members
  • Join Date: 07-Dec 21
  • 73 posts

Posted 22 June 2022 - 05:01 PM #5

So you should alter the fn_discussion_get_products function

 

Add extra field to calculate posts amount and add it to sorting

 

 

thanks for the info, the function in question is:

function fn_discussion_get_products(&$params, &$fields, &$sortings, &$condition, &$join, &$sorting, &$group_by, &$lang_code, &$having)
{
    if (
        !empty($params['rating'])
        && Registry::get('addons.product_reviews.status') !== ObjectStatuses::ACTIVE
    ) {
        $fields[] = 'AVG(?:discussion_rating.rating_value) AS average_rating';
        $fields[] = '?:discussion.type AS discussion_type';
        $fields[] = '?:discussion.thread_id AS discussion_thread_id';
        $join .= db_quote(" LEFT JOIN ?:discussion ON ?:discussion.object_id = products.product_id AND ?:discussion.object_type = 'P'");

        if (fn_allowed_for('ULTIMATE') && Registry::ifGet('addons.discussion.product_share_discussion', 'N') == 'N' && Registry::get('runtime.company_id')) {
            $join .= " AND ?:discussion.company_id = " . Registry::get('runtime.company_id');
        }

        $join .= db_quote(" LEFT JOIN ?:discussion_posts ON ?:discussion_posts.thread_id = ?:discussion.thread_id AND ?:discussion_posts.status = 'A'");
        if (!empty($params['start_rating_period'])) {
            $join .= db_quote(' AND ?:discussion_posts.timestamp > ?i', $params['start_rating_period']);
        }

        $join .= db_quote(" LEFT JOIN ?:discussion_rating ON ?:discussion.thread_id = ?:discussion_rating.thread_id AND ?:discussion_rating.post_id = ?:discussion_posts.post_id AND ?:discussion_rating.rating_value != 0");

        $having[] = db_quote("average_rating > 0");
        $params['sort_by'] = 'rating';
        $params['sort_order'] = 'desc';
        $sortings['rating'] = 'average_rating';
    }

    return true;
}

what I would like to do is add a limit to the selected ratings to only those with 50 or more posts.

 

but honestly am not sure how to add that limit correctly and only apply it to the block in question

 

any additional help is appreciated


osCommerce user since 2005 now upgrading to CS-Cart Ultimate.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22892 posts

Posted 23 June 2022 - 01:46 PM #6

Try to add something like

$fields[] = 'COUNT(?:discussion_posts.post_id) as posts_count';
$having[] = db_quote("posts_count > 50");

(!) Not tested


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 1210     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 4025     CS-Cart + YOUPI      USD 1459      Multi-Vendor Ultimate       USD 7500 (6000)