Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

Recommended Posts

Всем здравствуйте. Суть задачи получить в массив $data['products'][] = array 

Количество оценок product.

То есть кол-во:

1 оценки,

2 оценки,

3 оценки и т.д до 5

Как понимаю нужно в модели создать

public function getTotalRatingsProductId($product_id) {

тут код запроса.

}

сделать запрос, не силен в этой части. Прошу помощи.

Link to post
Share on other sites

Может кому понадобится.

Критика приветствуется, так как додумал сам, хз может не очень верно вышло.

В model/catalog/product 

ocmod, ом добавил public function getMainProductStat($product_id), где и добавил запрос. Получив значение в массив.

SELECT product_id, rating, status, review_id FROM " . DB_PREFIX . "review WHERE product_id = '" . (int)$product_id . "' AND `rating` < '6' AND `status` = '1'

Ну и в controller/category Уже вывел.

Link to post
Share on other sites

Получить все оценки товара и рассортировать
 

public function getTotalRatingsProductId($product_id) {
    $ratings = array(1, 2, 3, 4, 5);
    
    $rating_data = array(
        1   => 0,
        2   => 0,
        3   => 0,
        4   => 0,
        5   => 0
    );
    
    $review_query = $this->db->query("SELECT review_id, rating FROM " . DB_PREFIX . "review WHERE status = '1' AND product_id = '" . (int)$product_id . "' ORDER BY review_id ASC");
    
    foreach ($review_query->rows as $row) {
        foreach ($ratings as $rating) {
            if ($row['rating'] == $rating) {
                $rating_data[$rating]++;
                
                break;
            }
        }
    }
    
    return $rating_data;
}

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.