Magento – How to get product Review/Ratings notification via email in Magento2

adminnotificationemailmagento2

In Magento2, Whenever a new product review posted in my store, I couldn’t get any notification. I’m always navigating to the review section to check and moderate the reviews/ratings. Is there any admin configuration available to get the product reviews/ratings notification via email?

Best Answer

I haven't found such option by default in CE.

You could create a simple module that does it. Create standard module structure/files, then:

etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="review_save_after"> 
    <observer name="Foo_ReviewNotification::review_save_after" instance="Foo\ReviewNotification\Observer\ReviewObserver" />
</event>

observer/ReviewObserver.php

<?php

namespace Foo\ReviewNotification\Observer;

class ReviewObserver implements \Magento\Framework\Event\ObserverInterface
{
  protected $_registry;
  protected $_scopeConfig;

  public function __construct(     
    \Magento\Framework\Registry $registry,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  ) {
    $this->_registry = $registry;
    $this->_scopeConfig = $scopeConfig;
  }

  public function execute(\Magento\Framework\Event\Observer $observer) {        
    $event = $observer->getEvent();

    $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
    $notifyEmail = $this->_scopeConfig->getValue("trans_email/ident_general/email", $storeScope);

    $product = $this->_registry->registry("current_product");
    $name = $product->getName();
    $sku = $product->getSku();
    $emailBody = "Product name: {$name} \n SKU: {$sku} \n Review id: {$review->getId()} \n Customer id: {$review->getCustomerId()}";
    // Mail me
    $headers = "From: {$notifyEmail}\r\n" .
        "Reply-To: {$notifyEmail}\r\n";
    mail($notifyEmail,"New product review - {$name}", $emailBody, $headers);
    return;
  }
}

That's a very basic module. You can improve it if needed.