91 \
Magento\Customer\Model\Session $customerSession,
93 \
Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress,
96 $this->_customerSession = $customerSession;
97 $this->_ratingOptionVoteF = $ratingOptionVoteF;
98 $this->_remoteAddress = $remoteAddress;
109 $this->
_init(
'rating_option',
'option_id');
111 $this->_reviewTable = $this->
getTable(
'review');
112 $this->_ratingOptionTable = $this->
getTable(
'rating_option');
113 $this->_ratingVoteTable = $this->
getTable(
'rating_option_vote');
114 $this->_aggregateTable = $this->
getTable(
'rating_option_vote_aggregated');
115 $this->_reviewStoreTable = $this->
getTable(
'review_store');
116 $this->_ratingStoreTable = $this->
getTable(
'rating_store');
130 'option_id' =>
$option->getId(),
131 'review_id' =>
$option->getReviewId(),
137 $data[
'remote_ip'] = $this->_remoteAddress->getRemoteAddress();
138 $data[
'remote_ip_long'] = $this->_remoteAddress->getRemoteAddress(
true);
139 $data[
'customer_id'] = $this->_customerSession->getCustomerId();
147 $condition = [
'vote_id = ?' =>
$option->getVoteId(),
'review_id = ?' =>
$option->getReviewId()];
158 throw new \Exception($e->getMessage());
171 $vote = $this->_ratingOptionVoteF->create()->load(
$option->getVoteId());
187 $this->_aggregateTable,
188 [
'store_id',
'primary_id']
190 'rating_id = :rating_id' 192 'entity_pk_value = :pk_value' 194 $bind = [
':rating_id' => $ratingId,
':pk_value' => $entityPkValue];
197 $appVoteCountCond =
$connection->getCheckSql(
'review.status_id=1',
'vote.vote_id',
'NULL');
198 $appVoteValueSumCond =
$connection->getCheckSql(
'review.status_id=1',
'vote.value',
'0');
201 [
'vote' => $this->_ratingVoteTable],
203 'vote_count' =>
new \
Zend_Db_Expr(
'COUNT(vote.vote_id)'),
204 'vote_value_sum' =>
new \
Zend_Db_Expr(
'SUM(vote.value)'),
205 'app_vote_count' =>
new \
Zend_Db_Expr(
"COUNT({$appVoteCountCond})"),
206 'app_vote_value_sum' =>
new \
Zend_Db_Expr(
"SUM({$appVoteValueSumCond})")
209 [
'review' => $this->_reviewTable],
210 'vote.review_id=review.review_id',
213 [
'store' => $this->_reviewStoreTable],
214 'vote.review_id=store.review_id',
217 [
'rstore' => $this->_ratingStoreTable],
218 'vote.rating_id=rstore.rating_id AND rstore.store_id=store.store_id',
221 'vote.rating_id = :rating_id' 223 'vote.entity_pk_value = :pk_value' 225 [
'vote.rating_id',
'vote.entity_pk_value',
'store.store_id']
231 foreach ($perStoreInfo as
$row) {
233 'rating_id' => $ratingId,
234 'entity_pk_value' => $entityPkValue,
235 'vote_count' =>
$row[
'vote_count'],
236 'vote_value_sum' =>
$row[
'vote_value_sum'],
237 'percent' =>
$row[
'vote_value_sum'] /
$row[
'vote_count'] / 5 * 100,
238 'percent_approved' =>
$row[
'app_vote_count'] ?
$row[
'app_vote_value_sum'] /
239 $row[
'app_vote_count'] /
242 'store_id' =>
$row[
'store_id'],
245 if (isset($oldData[
$row[
'store_id']])) {
246 $condition = [
'primary_id = ?' => $oldData[
$row[
'store_id']]];
247 $connection->update($this->_aggregateTable, $saveData, $condition);
249 $connection->insert($this->_aggregateTable, $saveData);
252 $usedStores[] =
$row[
'store_id'];
255 $toDelete = array_diff(array_keys($oldData), $usedStores);
258 $condition = [
'primary_id = ?' => $oldData[
$storeId]];
259 $connection->delete($this->_aggregateTable, $condition);
272 if (!$this->_optionData || $this->_optionId !=
$optionId) {
275 $select->from($this->_ratingOptionTable)->where(
'option_id = :option_id');
279 $this->_optionData =
$data;
_init($mainTable, $idFieldName)
aggregateEntityByRatingId($ratingId, $entityPkValue)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Review\Model\Rating\Option\VoteFactory $ratingOptionVoteF, \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress, $connectionName=null)