Demac Media Demac Media Brand Demac Media Brand

Blog

Subscribe

Mini Tutorial: How to Auto Approve Reviews for Registered Users in Magento

Timer Icon 2 Mins

Development, Magento Commerce, Magento Tutorials

Magento product reviews are either marked as Approved or Pending. New reviews are always marked Pending and the administrator has to set them to Approved to publish them on the product page.

Related: Mini Tutorial – Using Customer Segmentation Based on Cookie Data

If one wants to auto approve reviews for registered users in Magento, the controller that has to be overridden is the Mage/Review/controllers/ProductController.php specifically, the postAction().

Just change this block:

$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();

To:

$customer = Mage::getSingleton('customer/session')->getCustomer();
$review->setEntityId($review
  ->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE)
  );

if($customer->getEntityId()) {
  $review->setStatusId(Mage_Review_Model_Review::STATUS_APPROVED);
  $session->addSuccess($this->__('Your review has been accepted.'));
}
$review->setStatusId(Mage_Review_Model_Review::STATUS_PENDING);
   $session->addSuccess(
         $this->__('Your review has been accepted for moderation.')
       );
}
$review->setEntityPkValue($product->getId())
  ->setCustomerId(Mage::getSingleton('customer/session')
  ->getCustomerId())
  ->setStoreId(Mage::app()->getStore()->getId())
  ->setStores(array(Mage::app()->getStore()->getId()));
$review->save();
Subscribe to the Blog

Stay updated with 20,000+ eCommerce leaders in our community

Sign Up

Let’s talk about your 10X return

Icon/Social/Phone Contact us for pricing information