|
9 | 9 |
|
10 | 10 | use Magento\Framework\Api\Filter; |
11 | 11 | use Magento\Framework\Data\Collection; |
12 | | -use Magento\Framework\Exception\LocalizedException; |
13 | 12 | use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface; |
14 | 13 |
|
15 | 14 | final class FilterModifier implements ModifierInterface |
16 | 15 | { |
17 | | - /** |
18 | | - * @inheritdoc |
19 | | - * @throws LocalizedException |
20 | | - */ |
21 | 16 | public function apply(Collection $collection, Filter $filter): void |
22 | 17 | { |
23 | 18 | if ($collection instanceof Collection\AbstractDb && $filter->getField() === 'created_at') { |
24 | 19 | $connection = $collection->getConnection(); |
25 | 20 |
|
26 | 21 | $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 | + ) |
29 | 26 | ->group(['customer_id']); |
30 | 27 |
|
31 | 28 | $collection->getSelect()->joinLeft( |
32 | 29 | ['cv' => $visitorSelect], |
33 | | - 'main_table.entity_id=cl.customer_id', |
| 30 | + 'e.entity_id=cv.customer_id', |
34 | 31 | null |
35 | 32 | ); |
36 | 33 | $collection->getSelect()->joinLeft( |
37 | 34 | ['cl' => $connection->getTableName('customer_log')], |
38 | | - 'main_table.entity_id=cl.customer_id', |
| 35 | + 'e.entity_id=cl.customer_id', |
39 | 36 | null |
40 | 37 | ); |
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( |
| 40 | + 'IFNULL(cv.last_visit_at, GREATEST(IFNULL(cl.last_login_at, e.created_at), IFNULL(cl.last_logout_at, e.updated_at)))', |
| 41 | + [$filter->getConditionType() => $filter->getValue()] |
| 42 | + ) |
48 | 43 | ); |
49 | | - $collection->addFieldToFilter('last_visit_at', [$filter->getConditionType() => $filter->getValue()]); |
50 | 44 | } |
51 | 45 | } |
52 | 46 | } |
0 commit comments