Skip to content

Commit bc24a37

Browse files
committed
MAGETWO-82176: Fix Filter Customer Report Review #11524
- Merge Pull Request #11524 from osrecio/magento2:PR#ReportCustomerReview - Merged commits: 1. 1e38fcf 2. b093dd1 3. bce275d 4. d02595a 5. 306b9c8 6. 4cbdf23
2 parents 9ed7081 + 4cbdf23 commit bc24a37

File tree

2 files changed

+53
-1
lines changed
  • app/code/Magento/Reports/Model/ResourceModel/Review/Customer
  • dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Review/Customer

2 files changed

+53
-1
lines changed

app/code/Magento/Reports/Model/ResourceModel/Review/Customer/Collection.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,36 @@ protected function _joinCustomers()
103103
return $this;
104104
}
105105

106+
/**
107+
* {@inheritdoc}
108+
*
109+
* Additional processing of 'customer_name' field is required, as it is a concat field, which can not be aliased.
110+
* @see _joinCustomers
111+
*/
112+
public function addFieldToFilter($field, $condition = null)
113+
{
114+
if ($field === 'customer_name') {
115+
$field = $this->getConnection()->getConcatSql(['customer.firstname', 'customer.lastname'], ' ');
116+
}
117+
118+
return parent::addFieldToFilter($field, $condition);
119+
}
120+
106121
/**
107122
* Get select count sql
108123
*
109124
* @return string
110125
*/
111126
public function getSelectCountSql()
112127
{
113-
$countSelect = clone $this->_select;
128+
$countSelect = clone $this->getSelect();
114129
$countSelect->reset(\Magento\Framework\DB\Select::ORDER);
115130
$countSelect->reset(\Magento\Framework\DB\Select::GROUP);
116131
$countSelect->reset(\Magento\Framework\DB\Select::HAVING);
117132
$countSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
118133
$countSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
119134
$countSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
135+
$countSelect->reset(\Magento\Framework\DB\Select::WHERE);
120136

121137
$countSelect->columns(new \Zend_Db_Expr('COUNT(DISTINCT detail.customer_id)'));
122138

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Reports\Model\ResourceModel\Review\Customer;
7+
8+
/**
9+
* @magentoAppArea adminhtml
10+
*/
11+
class CollectionTest extends \PHPUnit\Framework\TestCase
12+
{
13+
/**
14+
* @var \Magento\Reports\Model\ResourceModel\Review\Customer\Collection
15+
*/
16+
private $collection;
17+
18+
protected function setUp()
19+
{
20+
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
21+
\Magento\Reports\Model\ResourceModel\Review\Customer\Collection::class
22+
);
23+
}
24+
25+
/**
26+
* This tests covers issue described in:
27+
* https://github.com/magento/magento2/issues/10301
28+
*
29+
* @magentoDataFixture Magento/Review/_files/customer_review.php
30+
*/
31+
public function testSelectCountSql()
32+
{
33+
$this->collection->addFieldToFilter('customer_name', ['like' => '%John%'])->getItems();
34+
$this->assertEquals(1, $this->collection->getSize());
35+
}
36+
}

0 commit comments

Comments
 (0)