/** * Cleanup product reviews after product delete * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function processProductAfterDeleteEvent(\Magento\Framework\Event\Observer $observer) { $eventProduct = $observer->getEvent()->getProduct(); if ($eventProduct && $eventProduct->getId()) { $this->_resourceReview->deleteReviewsByProductId($eventProduct->getId()); $this->_resourceRating->deleteAggregatedRatingsByProductId($eventProduct->getId()); } return $this; }
/** * @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php */ public function testAggregate() { $rating = $this->reviewCollection->getFirstItem(); $this->reviewResource->aggregate($rating); $select = $this->adapter->select()->from($this->resource->getTableName('review_entity_summary')); $result = $this->adapter->fetchRow($select); $this->assertEquals(1, $result['reviews_count']); $this->assertEquals(40, $result['rating_summary']); }
public function testGetEntityIdByCode() { $entityCode = 'test'; $result = 22; $this->resource->expects($this->once())->method('getEntityIdByCode')->with($this->equalTo($entityCode))->will($this->returnValue($result)); $this->assertSame($result, $this->review->getEntityIdByCode($entityCode)); }