Skip to content

Commit

Permalink
Merge pull request #4 from Yproximite/fix/YP-5651
Browse files Browse the repository at this point in the history
ekomi api limit result to 200
  • Loading branch information
RomulusED69 authored Dec 17, 2019
2 parents 9776733 + 8077af5 commit 6c0be44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion spec/Service/OrderServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ function it_should_get_orders(
'customDataFilter' => json_encode(['vendor_id' => 123]),
];

$message->getOffset()->willReturn(5);
$message->build()->willReturn($query);

$method = 'GET';
$path = 'orders';

$client->sendRequest($method, $path, $query)->willReturn(['data' => []]);
$client->sendRequest($method, $path, $query)->willReturn(['data' => [], 'limit' => 15, 'total' => 0]);
$client->sendRequest($method, $path, $query)->shouldBeCalled();

$factory->createMany(Order::class, [])->willReturn([]);
Expand Down
7 changes: 7 additions & 0 deletions src/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public function getOrders(OrderListMessage $message): array
$path = 'orders';

$response = $this->getClient()->sendRequest('GET', $path, $message->build());
$data = $response['data'];

while ($response['limit'] > $response['total'] && $response['total'] > $message->getOffset() + 200) {
$message->setOffset($message->getOffset() + 200);
$response = $this->getClient()->sendRequest('GET', $path, $message->build());
$data = array_merge($data, $response['data']);
}

/** @var Order[] $models */
$models = $this->getModelFactory()->createMany(Order::class, $response['data']);
Expand Down

0 comments on commit 6c0be44

Please sign in to comment.