skip to Main Content

I am working on a Magento 2 extension that will send a message to me when a new product review is written. I’ve tried to create an observer, but it never seems to work.

In ets/events.xml, I have this:

<event name="review_save_after">
    <observer 
        name = "jeroen_update_product_review"
        instance = "JeroenReviewIntegrationObserverProductReview" />
</event>

In JeroenReviewIntegrationObserverProductReview:

namespace JeroenReviewIntegrationObserver;
use MagentoFrameworkEventObserverInterface;

class ProductReview implements ObserverInterface
{
     protected $_storeManager;
     protected $_request;

     public function __construct(
         MagentoStoreModelStoreManagerInterface $storeManager,
         MagentoFrameworkAppRequestHttp $request
     ) {
         $this->_storeManager = $storeManager;
         $this->_request = $request;
     }

     public function execute(MagentoFrameworkEventObserver $observer)
     {
          return 'test';
     }
}

This always gives a a blank page after a new review is written (and after the status of the review is updated). Can anyone find out what I am doing wrong?

3

Answers


  1. Chosen as BEST ANSWER

    Thanks for your replies! I found out that it was just a caching error. De code needed to be recompiled before it worked. Thanks anyway for your answers.


  2. Make sure you set enough memory_limit in php.ini

    php.ini values are:

    post_max_size = 1024M

    upload_max_filesize = 1024M

    memory_limit = 3G

    max_execution_time = 500

    Login or Signup to reply.
  3. We can use Plugin to achieve any functionality after review save

    di.xml file

    <type name="MagentoReviewControllerProductPost">
        <plugin name="After_save_product_review"
                    type="ModuleCustomPluginUpdateReviewSaveAfter" />
    </type>
    

    Plugin file

    namespace ModuleCustomPlugin;
    
    class UpdateReviewSaveAfter
    {
        public function afterExecute(
            MagentoReviewControllerProductPost $subject,
            $result)
        {       
            //your fuctionality
    
            return $result;
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search