Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProcessProductAfterDeleteEventObserver.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
17  protected $_resourceReview;
18 
22  protected $_resourceRating;
23 
28  public function __construct(
29  \Magento\Review\Model\ResourceModel\Review $resourceReview,
30  \Magento\Review\Model\ResourceModel\Rating $resourceRating
31  ) {
32  $this->_resourceReview = $resourceReview;
33  $this->_resourceRating = $resourceRating;
34  }
35 
42  public function execute(\Magento\Framework\Event\Observer $observer)
43  {
44  $eventProduct = $observer->getEvent()->getProduct();
45  if ($eventProduct && $eventProduct->getId()) {
46  $this->_resourceReview->deleteReviewsByProductId($eventProduct->getId());
47  $this->_resourceRating->deleteAggregatedRatingsByProductId($eventProduct->getId());
48  }
49 
50  return $this;
51  }
52 }
__construct(\Magento\Review\Model\ResourceModel\Review $resourceReview, \Magento\Review\Model\ResourceModel\Rating $resourceRating)