/** * Aggregate review summary * * @param \Magento\Framework\Model\AbstractModel $object * @param \Magento\Review\Model\Rating $ratingSummaryObject * @return void */ protected function aggregateReviewSummary($object, $ratingSummaryObject) { $readAdapter = $this->_getReadAdapter(); if ($ratingSummaryObject->getCount()) { $ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount()); } else { $ratingSummary = $ratingSummaryObject->getSum(); } $reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId()); $select = $readAdapter->select()->from($this->_aggregateTable)->where('entity_pk_value = :pk_value')->where('entity_type = :entity_type')->where('store_id = :store_id'); $bind = [':pk_value' => $object->getEntityPkValue(), ':entity_type' => $object->getEntityId(), ':store_id' => $ratingSummaryObject->getStoreId()]; $oldData = $readAdapter->fetchRow($select, $bind); $data = new \Magento\Framework\Object(); $data->setReviewsCount($reviewsCount)->setEntityPkValue($object->getEntityPkValue())->setEntityType($object->getEntityId())->setRatingSummary($ratingSummary > 0 ? $ratingSummary : 0)->setStoreId($ratingSummaryObject->getStoreId()); $this->writeReviewSummary($oldData, $data); }