Skip to content

Rewrote Mage_Reports_Model_Resource_Review_Product_Collection/Mage_Reports_Model_Resource_Order_Collection queries for a correct use of Zend_Db_Expr #2864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function joinReview()
'e.entity_id = r.entity_pk_value',
[
'review_cnt' => new Zend_Db_Expr(sprintf('(%s)', $subSelect)),
'last_created' => 'MAX(r.created_at)',
'last_created' => new Zend_Db_Expr('MAX(r.created_at)'),
]
)
->group('e.entity_id');
Expand All @@ -66,22 +66,18 @@ public function joinReview()
$this->getConnection()->quoteInto('table_rating.store_id > ?', 0)
];

/**
* @var array $groupByCondition of group by fields
*/
$groupByCondition = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
$percentField = $this->getConnection()->quoteIdentifier('table_rating.percent');
$sumPercentField = $helper->prepareColumn("SUM({$percentField})", $groupByCondition);
$sumPercentApproved = $helper->prepareColumn('SUM(table_rating.percent_approved)', $groupByCondition);
$countRatingId = $helper->prepareColumn('COUNT(table_rating.rating_id)', $groupByCondition);
$sumPercentField = "SUM({$percentField})";
$sumPercentApproved = 'SUM(table_rating.percent_approved)';
$countRatingId = 'COUNT(table_rating.rating_id)';

$this->getSelect()
->joinLeft(
['table_rating' => $this->getTable('rating/rating_vote_aggregated')],
implode(' AND ', $joinCondition),
[
'avg_rating' => sprintf('%s/%s', $sumPercentField, $countRatingId),
'avg_rating_approved' => sprintf('%s/%s', $sumPercentApproved, $countRatingId),
'avg_rating' => new Zend_Db_Expr("$sumPercentField / $countRatingId"),
'avg_rating_approved' => new Zend_Db_Expr("$sumPercentApproved / $countRatingId"),
]
);

Expand Down