Skip to content

Commit

Permalink
Update review_entity_summary when unapprove the latest comment (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Apr 18, 2023
1 parent 177461b commit 25ea459
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 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 @@ -277,6 +277,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 @@ -288,18 +298,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
7 changes: 4 additions & 3 deletions app/code/core/Mage/Review/Model/Resource/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,14 @@ 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);

foreach ($ratingSummaries as $ratingSummaryObject) {
Expand Down

0 comments on commit 25ea459

Please sign in to comment.