Question

Can somebody provide some insight for when reviews get put into the rating_option_vote_aggregated table? I'm trying to filter through my reviews based on four stars or higher and I was looking to use the percent_approved column for joining up with the review table, however not all of the latest approved reviews are in the rating_option_vote_aggregated table.

Do we need to install some sort of post-review-approval code that calls $review->aggregate()?

Thanks in advance!

Was it helpful?

Solution

There's no magic code that automatically aggregates the review data for a client programmer — you need to call this method manually after a review object is created. You can see this on the frontend at in the postAction method in

app/code/core/Mage/Review/controllers/ProductController.php

and in various methods on the backend

app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php

My guess would be there's one of two things happening. The first is you have some custom code that's creating reviews manually, and failing to call aggregate correctly.

The second is there's a certain percentage of people who attempt to review a product, but because of server load or some other problem, the request fails halfway through such that

$review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE))
    ->setEntityPkValue($product->getId())
    ->setStatusId(Mage_Review_Model_Review::STATUS_PENDING)
    ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
    ->setStoreId(Mage::app()->getStore()->getId())
    ->setStores(array(Mage::app()->getStore()->getId()))
    ->save();

foreach ($rating as $ratingId => $optionId) {
    Mage::getModel('rating/rating')
    ->setRatingId($ratingId)
    ->setReviewId($review->getId())
    ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
    ->addOptionVote($optionId, $product->getId());
}

is called, but

$review->aggregate();

is not. If I was going to approach fixing this, I'd add a cron job somewhere that built up a list of non-aggregated reviews, and then aggregated them.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top