Magento 2:保存产品评论
Magento 2: save product review
我正在开发 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';
}
}
在撰写新评论后(以及评论状态更新后),这总是会出现空白页。谁能找出我做错了什么?
确保在 php.ini
中设置了足够的 memory_limit
php.ini 值为:
post_max_size = 1024M
upload_max_filesize = 1024M
memory_limit = 3G
max_execution_time = 500
感谢您的回复!我发现这只是一个缓存错误。 De代码需要重新编译才能工作。无论如何感谢您的回答。
审核保存后我们可以使用插件来实现任何功能
di.xml file
<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;
}
}
我正在开发 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';
}
}
在撰写新评论后(以及评论状态更新后),这总是会出现空白页。谁能找出我做错了什么?
确保在 php.ini
中设置了足够的 memory_limitphp.ini 值为:
post_max_size = 1024M
upload_max_filesize = 1024M
memory_limit = 3G
max_execution_time = 500
感谢您的回复!我发现这只是一个缓存错误。 De代码需要重新编译才能工作。无论如何感谢您的回答。
审核保存后我们可以使用插件来实现任何功能
di.xml file
<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;
}
}