|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Setup\SchemaInterface; |
|
9
|
|
|
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; |
|
10
|
|
|
use Magento\Framework\Data\Collection\EntityFactoryInterface; |
|
11
|
|
|
use Magento\Framework\DB\Adapter\AdapterInterface; |
|
12
|
|
|
use Magento\Framework\Event\ManagerInterface; |
|
13
|
|
|
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; |
|
14
|
|
|
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot; |
|
15
|
|
|
use Magento\Framework\Stdlib\DateTime\TimezoneInterface; |
|
16
|
|
|
use Magento\Quote\Model\ResourceModel\Quote\Collection as ExtendCollection; |
|
17
|
|
|
use Psr\Log\LoggerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Collection |
|
21
|
|
|
* @codeCoverageIgnore |
|
22
|
|
|
*/ |
|
23
|
|
|
class Collection extends ExtendCollection |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var TimezoneInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $timezone; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param EntityFactoryInterface $entityFactory |
|
32
|
|
|
* @param LoggerInterface $logger |
|
33
|
|
|
* @param FetchStrategyInterface $fetchStrategy |
|
34
|
|
|
* @param ManagerInterface $eventManager |
|
35
|
|
|
* @param Snapshot $entitySnapshot |
|
36
|
|
|
* @param TimezoneInterface $timezone |
|
37
|
|
|
* @param AdapterInterface|null $connection |
|
38
|
|
|
* @param AbstractDb|null $resource |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct( |
|
41
|
|
|
EntityFactoryInterface $entityFactory, |
|
42
|
|
|
LoggerInterface $logger, |
|
43
|
|
|
FetchStrategyInterface $fetchStrategy, |
|
44
|
|
|
ManagerInterface $eventManager, |
|
45
|
|
|
Snapshot $entitySnapshot, |
|
46
|
|
|
TimezoneInterface $timezone, |
|
47
|
|
|
AdapterInterface $connection = null, |
|
48
|
|
|
AbstractDb $resource = null |
|
49
|
|
|
) { |
|
50
|
|
|
$this->timezone = $timezone; |
|
51
|
|
|
parent::__construct( |
|
52
|
|
|
$entityFactory, |
|
53
|
|
|
$logger, |
|
54
|
|
|
$fetchStrategy, |
|
55
|
|
|
$eventManager, |
|
56
|
|
|
$entitySnapshot, |
|
57
|
|
|
$connection, |
|
58
|
|
|
$resource |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @inheritDoc |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function _initSelect() |
|
66
|
|
|
{ |
|
67
|
|
|
parent::_initSelect(); |
|
68
|
|
|
|
|
69
|
|
|
$this->getSelect()->joinLeft( |
|
70
|
|
|
['ac_order' => $this->_resource->getTable(SchemaInterface::ORDER_TABLE)], |
|
|
|
|
|
|
71
|
|
|
'ac_order.magento_quote_id = main_table.entity_id', |
|
72
|
|
|
['ac_order.activecampaign_id'] |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return Collection |
|
80
|
|
|
* @throws \Exception |
|
81
|
|
|
*/ |
|
82
|
|
|
public function addAbandonedFilter(): self |
|
83
|
|
|
{ |
|
84
|
|
|
$this->getSelect()->where('main_table.items_count != 0'); |
|
85
|
|
|
$this->getSelect()->where('main_table.is_active = 1'); |
|
86
|
|
|
$this->getSelect()->where('main_table.customer_id IS NOT NULL'); |
|
87
|
|
|
|
|
88
|
|
|
$fromDateTime = $this->timezone->date() |
|
89
|
|
|
->sub(new \DateInterval('PT1H')) |
|
90
|
|
|
->format('Y-m-d H:i:s'); |
|
91
|
|
|
|
|
92
|
|
|
$this->getSelect()->where('main_table.updated_at <= ?', $fromDateTime); |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param int $quoteId |
|
99
|
|
|
* @return Collection |
|
100
|
|
|
*/ |
|
101
|
|
|
public function addIdFilter(int $quoteId): self |
|
102
|
|
|
{ |
|
103
|
|
|
$this->getSelect()->where('main_table.entity_id = ?', $quoteId); |
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return Collection |
|
109
|
|
|
*/ |
|
110
|
|
|
public function addOmittedFilter(): self |
|
111
|
|
|
{ |
|
112
|
|
|
$this->getSelect()->where('ac_order.activecampaign_id IS NULL'); |
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.