I am using Magento 1.8 version. I have written an observer that has to run when admin save a product review with status "Approved". And i have created a ratings attribute for every product with multiselect and it should automatically update every time when admin save the review for a product.
Note: Reviews are in Reports/Reviews/Product Reviews.
etc/Config.xml Code:
<review_save_after>
<observers>
<efkadminhtml>
<class>efkadminhtml/observer</class>
<method>ratingsUpdate</method>
</efkadminhtml>
</observers>
</review_save_after>
mode/Observer Code
public function ratingsUpdate(Varien_Event_Observer $observer)
{
$object = $observer->getEvent()->getObject();
$statusId = $object->getStatusId();
if($statusId == 1) {
$common = Mage::getSingleton('catalog/common');
$attribute = $common->getAttribute('ratings');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$productId = $object->getEntityPkValue();
$product = Mage::getModel('catalog/product')->load($productId);
$avgRating = Mage::getBlockSingleton('efkreports/product_allReviews')->getAvgReview($product->getId());
Mage::log($avgRating);
Mage::log($attribute->getOptionId(round($avgRating)));
$product->setRatings($attribute->getOptionId(round($avgRating)));
//$product->setRatings(round($avgRating));
$product->save();
}
}
When admin is attempting to save review for a product, the above observer code is executing and review is updating correctrly but product is getting previous review value rather than latest updated review.
I wrote <review_save_after>
but it getting previous value. What is the event called after "Save Review" Is that correct or not?
Please tell me where I am wrong.
Thanks in advance.