Skip to content

Commit

Permalink
Merge pull request #82 from aligent/feature/fetch-all-customer-pages
Browse files Browse the repository at this point in the history
Ability to fetch all customers at once
  • Loading branch information
jswift authored Jul 14, 2021
2 parents 070a79c + 5572a06 commit f1503eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/BigCommerce/Api/Customers/CustomersApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public function getAll(array $filters = [], int $page = 1, int $limit = 250): Cu
return new CustomersResponse($this->getAllResources($filters, $page, $limit));
}

public function getAllPages(array $filter = []): CustomersResponse
{
return CustomersResponse::buildFromAllPages(function ($page) use ($filter) {
return $this->getAllResources($filter, $page, 200);
});
}

public function getByEmail(string $email): ?Customer
{
$customers = $this->getAll([self::FILTER__EMAIL_IN => $email])->getCustomers();
Expand Down
5 changes: 2 additions & 3 deletions src/BigCommerce/ResponseModels/Customer/CustomersResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace BigCommerce\ApiV3\ResponseModels\Customer;

use BigCommerce\ApiV3\ResourceModels\Customer\Customer;
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse;
use stdClass;
use BigCommerce\ApiV3\ResponseModels\PaginatedBatchableResponse;

class CustomersResponse extends PaginatedResponse
class CustomersResponse extends PaginatedBatchableResponse
{
/**
* @return Customer[]
Expand Down
9 changes: 9 additions & 0 deletions tests/BigCommerce/Api/Customers/CustomersApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public function testCanGetCustomers()
$this->assertEquals('California', $customers[0]->addresses[0]->state_or_province);
}

public function testCanGetAllPagesOfCustomers()
{
$this->setReturnData('customers__get_all.json');

$customersResponse = $this->getApi()->customers()->getAll();

$this->assertEquals(1, $customersResponse->getPagination()->total);
}

public function testCanGetCustomerByEmail()
{
$this->setReturnData('customers__get_all.json');
Expand Down

0 comments on commit f1503eb

Please sign in to comment.