Magento 2:保存产品评论

3

我正在开发一个与 Magento 2 相关的扩展,当有新的产品评论时,它会向我发送一条消息。我尝试创建了一个观察者,但似乎从未生效。

ets/events.xml 文件中,我有以下内容:

<event name="review_save_after">
    <observer 
        name = "jeroen_update_product_review"
        instance = "Jeroen\ReviewIntegration\Observer\ProductReview" />
</event>

Jeroen\ReviewIntegration\Observer\ProductReview 中:
namespace Jeroen\ReviewIntegration\Observer;
use Magento\Framework\Event\ObserverInterface;

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

     public function __construct(
         \Magento\Store\Model\StoreManagerInterface $storeManager,
         \Magento\Framework\App\Request\Http $request
     ) {
         $this->_storeManager = $storeManager;
         $this->_request = $request;
     }

     public function execute(\Magento\Framework\Event\Observer $observer)
     {
          return 'test';
     }
}

每次写新评论后(以及评论状态更新后),页面总是显示空白。有人能找出我做错了什么吗?

你有检查过Magento日志吗? - Rohit Goel
3个回答

0

感谢您的回复!我发现这只是一个缓存错误。在代码能够正常工作之前,需要重新编译代码。无论如何,还是非常感谢您的答复。


0

我们可以使用插件,在审核保存后实现任何功能

di.xml 文件

<type name="Magento\Review\Controller\Product\Post">
    <plugin name="After_save_product_review"
                type="Module\Custom\Plugin\UpdateReviewSaveAfter" />
</type>

Plugin file

namespace Module\Custom\Plugin;

class UpdateReviewSaveAfter
{
    public function afterExecute(
        \Magento\Review\Controller\Product\Post $subject,
        $result)
    {       
        //your fuctionality

        return $result;
    }
}

-1

请确保在php.ini中设置了足够的memory_limit

php.ini值为:

post_max_size = 1024M

upload_max_filesize = 1024M

memory_limit = 3G

max_execution_time = 500


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接