Skip to content

Commit e1afb02

Browse files
committed
fix #107 invalid sql builder
1 parent 0c3c8c7 commit e1afb02

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

Model/Customer/SourceProvider/FilterModifier.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,38 @@
99

1010
use Magento\Framework\Api\Filter;
1111
use Magento\Framework\Data\Collection;
12-
use Magento\Framework\Exception\LocalizedException;
1312
use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface;
1413

1514
final class FilterModifier implements ModifierInterface
1615
{
17-
/**
18-
* @inheritdoc
19-
* @throws LocalizedException
20-
*/
2116
public function apply(Collection $collection, Filter $filter): void
2217
{
2318
if ($collection instanceof Collection\AbstractDb && $filter->getField() === 'created_at') {
2419
$connection = $collection->getConnection();
2520

2621
$visitorSelect = $connection->select()
27-
->from($connection->getTableName('customer_visitor'))
28-
->columns(['customer_id' => 'customer_id', 'last_visit_at' => 'MAX(last_visit_at)'])
22+
->from(
23+
$connection->getTableName('customer_visitor'),
24+
['customer_id' => 'customer_id', 'last_visit_at' => 'MAX(last_visit_at)']
25+
)
2926
->group(['customer_id']);
3027

3128
$collection->getSelect()->joinLeft(
3229
['cv' => $visitorSelect],
33-
'main_table.entity_id=cl.customer_id',
30+
'e.entity_id=cv.customer_id',
3431
null
3532
);
3633
$collection->getSelect()->joinLeft(
3734
['cl' => $connection->getTableName('customer_log')],
38-
'main_table.entity_id=cl.customer_id',
35+
'e.entity_id=cl.customer_id',
3936
null
4037
);
41-
$collection->getSelect()->columns(
42-
[
43-
'last_visit_at' => 'IFNULL(' .
44-
'cv.last_visit_at,'.
45-
'GREATEST(IFNULL(cl.last_login_at, e.created_at), IFNULL(cl.last_logout_at, e.updated_at))' .
46-
')',
47-
]
38+
$collection->getSelect()->where(
39+
$connection->prepareSqlCondition('IFNULL(' .
40+
'cv.last_visit_at,'.
41+
'GREATEST(IFNULL(cl.last_login_at, e.created_at), IFNULL(cl.last_logout_at, e.updated_at))' .
42+
')', [$filter->getConditionType() => $filter->getValue()])
4843
);
49-
$collection->addFieldToFilter('last_visit_at', [$filter->getConditionType() => $filter->getValue()]);
5044
}
5145
}
5246
}

0 commit comments

Comments
 (0)