forked from dotmailer/dotmailer-magento2-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Order.php
executable file
·116 lines (98 loc) · 2.84 KB
/
Order.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
namespace Dotdigitalgroup\Email\Model;
class Order extends \Magento\Framework\Model\AbstractModel
{
const EMAIL_ORDER_NOT_IMPORTED = null;
/**
* constructor
*/
public function _construct()
{
parent::_construct();
$this->_init('Dotdigitalgroup\Email\Model\Resource\Order');
}
/**
* Load the email order by quote id.
* @param $orderId
* @param $quoteId
*
* @return $this|\Magento\Framework\DataObject
*/
public function loadByOrderId($orderId, $quoteId)
{
$collection = $this->getCollection()
->addFieldToFilter('order_id', $orderId)
->addFieldToFilter('quote_id', $quoteId)
->setPageSize(1);
if ($collection->count()) {
return $collection->getFirstItem();
} else {
$this->setOrderId($orderId)
->setQuoteId($quoteId);
}
return $this;
}
/**
* @param $orderId
* @param $quoteId
* @param $storeId
*
* @return $this|\Magento\Framework\DataObject
*/
public function getEmailOrderRow($orderId, $quoteId, $storeId)
{
$collection = $this->getCollection()
->addFieldToFilter('order_id', $orderId)
->addFieldToFilter('quote_id', $quoteId)
->addFieldToFilter('store_id', $storeId);
if ($collection->count()) {
return $collection->getFirstItem();
} else {
$this->setOrderId($orderId)
->setQuoteId($quoteId)
->setStoreId($storeId)
->setCreatedAt(time());
}
return $this;
}
/**
* Get all orders with particular status within certain days.
*
* @param $storeIds
* @param $limit
* @param $orderStatuses
* @param bool|false $modified
*
* @return $this
*/
public function getOrdersToImport($storeIds, $limit, $orderStatuses, $modified = false)
{
$collection = $this->getCollection()
->addFieldToFilter('store_id', array('in' => $storeIds))
->addFieldToFilter('order_status', array('in' => $orderStatuses));
if ($modified) {
$collection
->addFieldToFilter('email_imported', 1)
->addFieldToFilter('modified', 1);
} else
$collection->addFieldToFilter('email_imported', array('null' => true));
$collection->getSelect()->limit($limit);
return $collection;
}
/**
* Get all sent orders older then certain days.
*
* @param $storeIds
* @param $limit
*
* @return $this
*/
public function getAllSentOrders($storeIds, $limit)
{
$collection = $this->getCollection()
->addFieldToFilter('email_imported', 1)
->addFieldToFilter('store_id', array('in' => $storeIds));
$collection->getSelect()->limit($limit);
return $collection->load();
}
}