Skip to content

Commit 981f33a

Browse files
itegration-itSanyi
andauthored
EMA-167 - Orders filtering & Refund polling based on timestamps (#70)
Co-authored-by: Sanyi <[email protected]>
1 parent 77c1155 commit 981f33a

File tree

11 files changed

+338
-80
lines changed

11 files changed

+338
-80
lines changed

Api/OrdersApiInterface.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@ interface OrdersApiInterface
1313
* @param int $pageSize
1414
* @param int $sinceId
1515
* @param string|null $storeId
16+
* @param string|null $lastUpdatedFrom
17+
* @param string|null $lastUpdatedTo
1618
*
1719
* @return \Emartech\Emarsys\Api\Data\OrdersApiResponseInterface
1820
*/
19-
public function get(int $page, int $pageSize, int $sinceId = 0, string $storeId = null): OrdersApiResponseInterface;
21+
public function get(
22+
int $page,
23+
int $pageSize,
24+
int $sinceId = 0,
25+
string $storeId = null,
26+
string $lastUpdatedFrom = null,
27+
string $lastUpdatedTo = null
28+
): OrdersApiResponseInterface;
2029
}

Api/RefundsApiInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ interface RefundsApiInterface
1313
* @param int $pageSize
1414
* @param int $sinceId
1515
* @param string|null $storeId
16+
* @param string|null $lastUpdatedFrom
17+
* @param string|null $lastUpdatedTo
1618
*
1719
* @return \Emartech\Emarsys\Api\Data\RefundsApiResponseInterface
1820
*/
1921
public function get(
2022
int $page,
2123
int $pageSize,
2224
int $sinceId = 0,
23-
string $storeId = null
25+
string $storeId = null,
26+
string $lastUpdatedFrom = null,
27+
string $lastUpdatedTo = null
2428
): RefundsApiResponseInterface;
2529
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Release notes:
22
==============
33

4+
2.0.15
5+
-------
6+
* New
7+
* Orders filtering & Refund polling based on timestamps
8+
49
2.0.14
510
-------
611
* Fix

Model/Api/OrdersApi.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ public function __construct(
4848
* @param int $pageSize
4949
* @param int $sinceId
5050
* @param string|null $storeId
51+
* @param string|null $lastUpdatedFrom
52+
* @param string|null $lastUpdatedTo
5153
*
5254
* @return OrdersApiResponseInterface
5355
* @throws WebApiException
5456
*/
55-
public function get(int $page, int $pageSize, int $sinceId = 0, string $storeId = null): OrdersApiResponseInterface
56-
{
57+
public function get(
58+
int $page,
59+
int $pageSize,
60+
int $sinceId = 0,
61+
string $storeId = null,
62+
string $lastUpdatedFrom = null,
63+
string $lastUpdatedTo = null
64+
): OrdersApiResponseInterface {
65+
5766
if (empty($storeId)) {
5867
throw new WebApiException(__('Store ID is required'));
5968
}
@@ -62,6 +71,7 @@ public function get(int $page, int $pageSize, int $sinceId = 0, string $storeId
6271
->initCollection()
6372
->filterStore($storeId)
6473
->filterSinceId($sinceId)
74+
->filterLastUpdated($lastUpdatedFrom, $lastUpdatedTo)
6575
->setPage($page, $pageSize);
6676

6777
return $this->responseFactory
@@ -121,6 +131,27 @@ private function filterSinceId(int $sinceId = 0): OrdersApi
121131
return $this;
122132
}
123133

134+
/**
135+
* Filter last updated at
136+
*
137+
* @param string|null $lastUpdatedFrom
138+
* @param string|null $lastUpdatedTo
139+
*
140+
* @return OrdersApi
141+
*/
142+
private function filterLastUpdated(?string $lastUpdatedFrom = null, ?string $lastUpdatedTo = null): OrdersApi
143+
{
144+
if ($lastUpdatedFrom) {
145+
$this->orderCollection->addFieldToFilter('updated_at', ['gteq' => $lastUpdatedFrom]);
146+
}
147+
148+
if ($lastUpdatedTo) {
149+
$this->orderCollection->addFieldToFilter('updated_at', ['lteq' => $lastUpdatedTo]);
150+
}
151+
152+
return $this;
153+
}
154+
124155
/**
125156
* SetPage
126157
*

Model/Api/RefundsApi.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,21 @@ public function __construct(
4747
* @param int $pageSize
4848
* @param int $sinceId
4949
* @param string|null $storeId
50+
* @param string|null $lastUpdatedFrom
51+
* @param string|null $lastUpdatedTo
5052
*
5153
* @return RefundsApiResponseInterface
5254
* @throws WebApiException
5355
*/
54-
public function get(int $page, int $pageSize, int $sinceId = 0, string $storeId = null): RefundsApiResponseInterface
55-
{
56+
public function get(
57+
int $page,
58+
int $pageSize,
59+
int $sinceId = 0,
60+
string $storeId = null,
61+
string $lastUpdatedFrom = null,
62+
string $lastUpdatedTo = null
63+
): RefundsApiResponseInterface {
64+
5665
if (empty($storeId)) {
5766
throw new WebApiException(__('Store ID is required'));
5867
}
@@ -61,6 +70,7 @@ public function get(int $page, int $pageSize, int $sinceId = 0, string $storeId
6170
->initCollection()
6271
->filterStore($storeId)
6372
->filterSinceId($sinceId)
73+
->filterLastUpdated($lastUpdatedFrom, $lastUpdatedTo)
6474
->setPage($page, $pageSize);
6575

6676
return $this->responseFactory
@@ -119,6 +129,27 @@ private function filterSinceId(int $sinceId = 0): RefundsApi
119129
return $this;
120130
}
121131

132+
/**
133+
* Filter last updated at
134+
*
135+
* @param string|null $lastUpdatedFrom
136+
* @param string|null $lastUpdatedTo
137+
*
138+
* @return RefundsApi
139+
*/
140+
private function filterLastUpdated(?string $lastUpdatedFrom = null, ?string $lastUpdatedTo = null): RefundsApi
141+
{
142+
if ($lastUpdatedFrom) {
143+
$this->creditmemoCollection->addFieldToFilter('updated_at', ['gteq' => $lastUpdatedFrom]);
144+
}
145+
146+
if ($lastUpdatedTo) {
147+
$this->creditmemoCollection->addFieldToFilter('updated_at', ['lteq' => $lastUpdatedTo]);
148+
}
149+
150+
return $this;
151+
}
152+
122153
/**
123154
* SetPage
124155
*

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"php": ">7.0.1"
77
},
88
"type": "magento2-module",
9-
"version": "2.0.14",
9+
"version": "2.0.15",
1010
"autoload": {
1111
"files": [
1212
"registration.php"

dev/testv2/.npmrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
always-auth=true
2-
@itg-commerce:registry=https://gitlab.itg.cloud/api/v4/projects/295/packages/npm/
3-
//gitlab.itg.cloud/api/v4/projects/295/packages/npm/:_authToken=${NPM_TOKEN}
2+
@itg-commerce:registry=https://gitlab.itg.cloud/api/v4/projects/227/packages/npm/
3+
//gitlab.itg.cloud/api/v4/projects/227/packages/npm/:_authToken=${NPM_TOKEN}

0 commit comments

Comments
 (0)