Skip to content

Commit

Permalink
Update review_entity_summary when unapprove the latest comment
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Nov 6, 2022
1 parent 8774526 commit 6038168
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 15 additions & 5 deletions app/code/core/Mage/Rating/Model/Resource/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ public function getEntitySummary($object, $onlyForCurrentStore = true)
}
}

if (empty($result[0])) {
// when you unapprove the latest comment and save
// store_id = 0 is missing and not updated in review_entity_summary
$clone = clone $object;
$clone->setCount(0);
$clone->setSum(0);
$clone->setStoreId(0);
$result[0] = $clone;
}

return array_values($result);
}

Expand All @@ -295,18 +305,18 @@ public function getEntitySummary($object, $onlyForCurrentStore = true)
*/
protected function _getEntitySummaryData($object)
{
$adapter = $this->_getReadAdapter();

$sumColumn = new Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})");
$countColumn = new Zend_Db_Expr("COUNT(*)");
$adapter = $this->_getReadAdapter();
$sumColumn = new Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})");
$countColumn = new Zend_Db_Expr("COUNT(*)");

$select = $adapter->select()
->from(
['rating_vote' => $this->getTable('rating/rating_option_vote')],
[
'entity_pk_value' => 'rating_vote.entity_pk_value',
'sum' => $sumColumn,
'count' => $countColumn]
'count' => $countColumn
]
)
->join(
['review' => $this->getTable('review/review')],
Expand Down
10 changes: 6 additions & 4 deletions app/code/core/Mage/Review/Model/Resource/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,18 @@ public function getTotalReviews($entityPkValue, $approvedOnly = false, $storeId
*/
public function aggregate($object)
{
$readAdapter = $this->_getReadAdapter();
$writeAdapter = $this->_getWriteAdapter();
$readAdapter = $this->_getReadAdapter();
$writeAdapter = $this->_getWriteAdapter();
$ratingModel = Mage::getModel('rating/rating');

if (!$object->getEntityPkValue() && $object->getId()) {
$object->load($object->getReviewId());
}

$ratingModel = Mage::getModel('rating/rating');
$ratingSummaries= $ratingModel->getEntitySummary($object->getEntityPkValue(), false);
$ratingSummaries = $ratingModel->getEntitySummary($object->getEntityPkValue(), false);

foreach ($ratingSummaries as $ratingSummaryObject) {

if ($ratingSummaryObject->getCount()) {
$ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount());
} else {
Expand Down

0 comments on commit 6038168

Please sign in to comment.