Skip to content

Commit

Permalink
fix: removed the index record on last comment removal for a product
Browse files Browse the repository at this point in the history
  • Loading branch information
samberrry committed Jul 12, 2022
1 parent 002bfca commit c247127
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Hook/ProductComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ public function actionObjectProductCommentDeleteAfter(array $params){
$count = $productCommentLogRowCount[0]['count'];
$count--;

$newGradeValue = (int)$gradeCommentRow[0]['score'] - (int)$comment->grade;
$avg_score = $newGradeValue/(((int)$count));
if ($count === 0 ){
$this->database->execute('DELETE FROM `'._DB_PREFIX_.'layered_comment_index` WHERE id_product = ' . $comment->id_product );
} else{
$newGradeValue = (int)$gradeCommentRow[0]['score'] - (int)$comment->grade;
$avg_score = $newGradeValue/(((int)$count));

$this->database->execute('update ' . _DB_PREFIX_ . 'layered_comment_index set score='.$newGradeValue.', avg_score= '.$avg_score .' where id_product=' . $comment->id_product);
$this->database->execute('update ' . _DB_PREFIX_ . 'layered_comment_index set score='.$newGradeValue.', avg_score= '.$avg_score .' where id_product=' . $comment->id_product);
}

$this->deleteCommentIndexLog($comment->id, $comment->id_product);
}
Expand Down

0 comments on commit c247127

Please sign in to comment.